✦ 代码工坊 HTML
14px
📝 编辑器 行数: 0
👁️ 预览 实时渲染
就绪 字符: 0
\n\n' + code + '\n\n'; } const blob = new Blob([fullHtml], { type: 'text/html;charset=utf-8' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; const now = new Date(); const dateStr = now.getFullYear() + '-' + String(now.getMonth()+1).padStart(2,'0') + '-' + String(now.getDate()).padStart(2,'0'); a.download = 'page-' + dateStr + '.html'; document.body.appendChild(a); a.click(); document.body.removeChild(a); setTimeout(function() { URL.revokeObjectURL(url); }, 1000); statusMsg.textContent = '⬇ 导出成功'; } // 快捷键 editor.commands.addCommand({ name: 'manualRefresh', bindKey: { win: 'Ctrl-Enter', mac: 'Cmd-Enter' }, exec: function() { updatePreview(); statusMsg.textContent = '🔄 手动刷新 (' + new Date().toLocaleTimeString() + ')'; } }); editor.commands.addCommand({ name: 'formatShortcut', bindKey: { win: 'Ctrl-Shift-F', mac: 'Cmd-Shift-F' }, exec: formatCode }); // 绑定按钮 btnFormat.addEventListener('click', formatCode); btnClear.addEventListener('click', clearCode); btnReset.addEventListener('click', resetCode); btnExport.addEventListener('click', exportHTML); // 初始渲染 setTimeout(updatePreview, 500); // Resize 自适应 const ro = new ResizeObserver(function() { clearTimeout(window._resizeTimer); window._resizeTimer = setTimeout(function() { editor.resize(); }, 200); }); ro.observe(container); console.log('✨ 智能编辑器已启动'); })();