{"id":996,"date":"2026-08-13T16:57:31","date_gmt":"2026-08-13T16:57:31","guid":{"rendered":"https:\/\/freewebtools.co.in\/?page_id=996"},"modified":"2026-08-13T17:18:49","modified_gmt":"2026-08-13T17:18:49","slug":"smart-copy-paste","status":"publish","type":"page","link":"https:\/\/freewebtools.co.in\/index.php\/smart-copy-paste\/","title":{"rendered":"Smart Copy Paste"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Smart Copy Paste Application<\/title>\n    <!-- Scoped Stylesheet Safe for WordPress & Standalone -->\n    <style>\n    #smart-copy-paste-tool {\n        display: block;\n        font-family: system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif;\n        color: #1e293b;\n        background-color: #f8fafc;\n        border: 1px solid #cbd5e1;\n        border-radius: 12px;\n        padding: 24px;\n        margin: 20px 0;\n        box-sizing: border-box;\n        width: 100%;\n        max-width: 100%;\n        overflow: hidden;\n    }\n\n    #smart-copy-paste-tool *, \n    #smart-copy-paste-tool *::before, \n    #smart-copy-paste-tool *::after {\n        box-sizing: border-box;\n    }\n\n    #smart-copy-paste-tool .scpt-header-title {\n        font-size: 28px;\n        font-weight: 700;\n        text-align: center;\n        margin-bottom: 20px;\n        color: #0f172a;\n    }\n\n    #smart-copy-paste-tool .scpt-main-toolbar,\n    #smart-copy-paste-tool .scpt-sub-toolbar,\n    #smart-copy-paste-tool .scpt-format-strip {\n        display: flex;\n        flex-wrap: wrap;\n        gap: 10px;\n        margin-bottom: 12px;\n        align-items: center;\n        background: #ffffff;\n        padding: 10px;\n        border: 1px solid #e2e8f0;\n        border-radius: 8px;\n    }\n\n    #smart-copy-paste-tool .scpt-sub-toolbar { margin-bottom: 12px; }\n    #smart-copy-paste-tool .scpt-format-strip { margin-bottom: 16px; padding: 6px 10px; }\n\n    #smart-copy-paste-tool .toolbar-section {\n        display: flex;\n        flex-wrap: wrap;\n        gap: 6px;\n        align-items: center;\n        margin-right: 15px;\n    }\n\n    #smart-copy-paste-tool .toolbar-section-title {\n        font-size: 12px;\n        font-weight: 700;\n        color: #64748b;\n        text-transform: uppercase;\n        margin-right: 4px;\n    }\n\n    #smart-copy-paste-tool .scpt-btn {\n        background-color: #f8fafc;\n        color: #334155;\n        border: 1px solid #cbd5e1;\n        padding: 6px 12px;\n        font-size: 13px;\n        font-weight: 500;\n        border-radius: 6px;\n        cursor: pointer;\n        transition: all 0.15s ease;\n    }\n\n    #smart-copy-paste-tool .scpt-btn:hover:not(:disabled) {\n        background-color: #f1f5f9;\n        border-color: #94a3b8;\n    }\n\n    #smart-copy-paste-tool .scpt-btn:disabled {\n        opacity: 0.5;\n        cursor: not-allowed;\n    }\n\n    #smart-copy-paste-tool .scpt-btn-primary { background-color: #2563eb; color: #ffffff; border-color: #2563eb; }\n    #smart-copy-paste-tool .scpt-btn-primary:hover { background-color: #1d4ed8; }\n    #smart-copy-paste-tool .scpt-btn-accent { background-color: #0d9488; color: #ffffff; border-color: #0d9488; }\n    #smart-copy-paste-tool .scpt-btn-accent:hover { background-color: #0f766e; }\n    #smart-copy-paste-tool .scpt-btn-danger { background-color: #ef4444; color: #ffffff; border-color: #ef4444; }\n\n    #smart-copy-paste-tool .scpt-view-toggle {\n        display: inline-flex;\n        background: #f1f5f9;\n        border-radius: 6px;\n        padding: 2px;\n        border: 1px solid #cbd5e1;\n    }\n\n    #smart-copy-paste-tool .scpt-view-btn {\n        background: transparent;\n        border: none;\n        padding: 4px 10px;\n        font-size: 12px;\n        font-weight: 600;\n        color: #64748b;\n        cursor: pointer;\n        border-radius: 4px;\n    }\n\n    #smart-copy-paste-tool .scpt-view-btn.active {\n        background: #ffffff;\n        color: #1e293b;\n        box-shadow: 0 1px 3px rgba(0,0,0,0.1);\n    }\n\n    #smart-copy-paste-tool .scpt-fmt-btn {\n        background: #f8fafc;\n        border: 1px solid #cbd5e1;\n        color: #334155;\n        padding: 4px 8px;\n        font-size: 12px;\n        border-radius: 4px;\n        cursor: pointer;\n    }\n\n    #smart-copy-paste-tool .scpt-fmt-btn:hover { background: #e2e8f0; }\n\n    #smart-copy-paste-tool .scpt-separator {\n        width: 1px;\n        height: 18px;\n        background: #cbd5e1;\n        margin: 0 4px;\n    }\n\n    #smart-copy-paste-tool .scpt-diagram-toolbar {\n        display: flex;\n        gap: 6px;\n        align-items: center;\n        background: #1e293b;\n        color: #ffffff;\n        padding: 6px 12px;\n        border-radius: 6px;\n        margin-bottom: 12px;\n        font-size: 12px;\n    }\n\n    #smart-copy-paste-tool .scpt-diag-title { font-weight: 600; margin-right: 6px; color: #94a3b8; }\n    #smart-copy-paste-tool .scpt-diag-action { background: #334155; color: #ffffff; border: 1px solid #475569; padding: 4px 8px; font-size: 11px; }\n    #smart-copy-paste-tool .scpt-diag-action:hover { background: #475569; }\n\n    #smart-copy-paste-tool .scpt-editor-viewport {\n        background: #ffffff;\n        border: 1px solid #cbd5e1;\n        border-radius: 8px;\n        box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);\n        position: relative;\n    }\n\n    #smart-copy-paste-tool .scpt-editor-canvas {\n        padding: 30px;\n        min-height: 350px;\n        outline: none;\n        line-height: 1.6;\n        font-size: 15px;\n        overflow-x: auto;\n        word-break: break-word;\n    }\n\n    #smart-copy-paste-tool .scpt-editor-canvas h1 { font-size: 24px; margin-top: 0; margin-bottom: 12px; font-weight: 700; }\n    #smart-copy-paste-tool .scpt-editor-canvas h2 { font-size: 18px; margin-top: 24px; margin-bottom: 10px; font-weight: 600; }\n    #smart-copy-paste-tool .scpt-editor-canvas p { margin: 0 0 12px 0; }\n\n    #smart-copy-paste-tool .scpt-table-wrap { width: 100%; overflow-x: auto; margin: 16px 0; }\n    #smart-copy-paste-tool table { width: 100%; border-collapse: collapse; min-width: 400px; }\n    #smart-copy-paste-tool th, #smart-copy-paste-tool td { border: 1px solid #cbd5e1; padding: 8px 12px; text-align: left; }\n    #smart-copy-paste-tool th { background-color: #f8fafc; font-weight: 600; }\n\n    #smart-copy-paste-tool blockquote {\n        border-left: 4px solid #2563eb;\n        margin: 16px 0;\n        padding: 4px 0 4px 16px;\n        color: #475569;\n        font-style: italic;\n    }\n\n    #smart-copy-paste-tool ul, #smart-copy-paste-tool ol { margin: 0 0 16px 0; padding-left: 24px; }\n    #smart-copy-paste-tool li { margin-bottom: 4px; }\n\n    #smart-copy-paste-tool svg,\n    #smart-copy-paste-tool img,\n    #smart-copy-paste-tool canvas {\n        max-width: 100% !important;\n        height: auto !important;\n        display: block;\n        margin: 16px auto;\n    }\n\n    #smart-copy-paste-tool .scpt-diagram-node {\n        border: 2px dashed transparent;\n        padding: 4px;\n        border-radius: 6px;\n        cursor: pointer;\n        transition: border-color 0.15s ease;\n    }\n\n    #smart-copy-paste-tool .scpt-diagram-node.selected { border-color: #2563eb; }\n\n    #smart-copy-paste-tool .scpt-modal-overlay {\n        position: fixed;\n        top: 0; left: 0; width: 100%; height: 100%;\n        background: rgba(0,0,0,0.5);\n        z-index: 99999;\n        display: flex;\n        align-items: center;\n        justify-content: center;\n    }\n\n    #smart-copy-paste-tool .scpt-modal-dialog {\n        background: #ffffff;\n        width: 90%;\n        max-width: 500px;\n        border-radius: 8px;\n        box-shadow: 0 10px 25px rgba(0,0,0,0.2);\n        overflow: hidden;\n        display: flex;\n        flex-direction: column;\n    }\n\n    #smart-copy-paste-tool .scpt-modal-header {\n        padding: 16px 20px;\n        background: #f8fafc;\n        border-bottom: 1px solid #e2e8f0;\n        display: flex;\n        justify-content: space-between;\n        align-items: center;\n    }\n\n    #smart-copy-paste-tool .scpt-modal-header h3 { margin: 0; font-size: 16px; font-weight: 700; }\n    #smart-copy-paste-tool .scpt-modal-close-btn { background: transparent; border: none; font-size: 20px; cursor: pointer; color: #64748b; }\n    #smart-copy-paste-tool .scpt-modal-body { padding: 20px; font-size: 14px; color: #334155; max-height: 300px; overflow-y: auto; }\n    #smart-copy-paste-tool .scpt-modal-footer { padding: 12px 20px; background: #f8fafc; border-top: 1px solid #e2e8f0; display: flex; justify-content: flex-end; gap: 8px; }\n\n    @media (max-width: 768px) {\n        #smart-copy-paste-tool { padding: 10px; }\n        #smart-copy-paste-tool .scpt-main-toolbar,\n        #smart-copy-paste-tool .scpt-sub-toolbar { flex-direction: column; align-items: stretch; }\n        #smart-copy-paste-tool .toolbar-section { width: 100%; }\n    }\n    <\/style>\n<\/head>\n<body style=\"background: #e2e8f0; padding: 20px;\">\n\n<div id=\"smart-copy-paste-tool\" class=\"scpt-container\">\n    <div class=\"scpt-header-title\">Smart Copy Paste<\/div>\n\n    <!-- Top Action Toolbar -->\n    <div class=\"scpt-main-toolbar\">\n        <div class=\"toolbar-section\">\n            <span class=\"toolbar-section-title\">Workflow:<\/span>\n            <button type=\"button\" id=\"scpt-smart-paste-btn\" class=\"scpt-btn scpt-btn-accent\">Paste AI Notes<\/button>\n            <button type=\"button\" id=\"scpt-fix-symbols-btn\" class=\"scpt-btn\">Fix Symbols<\/button>\n            <button type=\"button\" id=\"scpt-doc-check-btn\" class=\"scpt-btn\">Document Check<\/button>\n            <button type=\"button\" id=\"scpt-undo-btn\" class=\"scpt-btn\" disabled>Undo<\/button>\n            <button type=\"button\" id=\"scpt-redo-btn\" class=\"scpt-btn\" disabled>Redo<\/button>\n        <\/div>\n        <div class=\"toolbar-section\">\n            <span class=\"toolbar-section-title\">View Mode:<\/span>\n            <div class=\"scpt-view-toggle\">\n                <button type=\"button\" data-view=\"editor\" class=\"scpt-view-btn active\">Editor<\/button>\n                <button type=\"button\" data-view=\"preview\" class=\"scpt-view-btn\">Preview<\/button>\n                <button type=\"button\" data-view=\"print\" class=\"scpt-view-btn\">Print Preview<\/button>\n            <\/div>\n        <\/div>\n    <\/div>\n\n    <!-- Secondary Export & Copy Toolbar -->\n    <div class=\"scpt-sub-toolbar\">\n        <div class=\"toolbar-section\">\n            <span class=\"toolbar-section-title\">Copy:<\/span>\n            <button type=\"button\" id=\"scpt-copy-full-btn\" class=\"scpt-btn scpt-btn-primary\">Copy Full Notes<\/button>\n            <button type=\"button\" id=\"scpt-copy-word-btn\" class=\"scpt-btn\">Copy for Word<\/button>\n            <button type=\"button\" id=\"scpt-copy-html-btn\" class=\"scpt-btn\">Copy HTML<\/button>\n            <button type=\"button\" id=\"scpt-copy-plain-btn\" class=\"scpt-btn\">Copy Plain Text<\/button>\n        <\/div>\n        <div class=\"toolbar-section\">\n            <span class=\"toolbar-section-title\">Export \/ Print:<\/span>\n            <button type=\"button\" id=\"scpt-export-word-btn\" class=\"scpt-btn\">Export Word<\/button>\n            <button type=\"button\" id=\"scpt-print-pdf-btn\" class=\"scpt-btn\">Print \/ PDF<\/button>\n        <\/div>\n    <\/div>\n\n    <!-- Formatting Tool Strip -->\n    <div class=\"scpt-format-strip\">\n        <button type=\"button\" data-cmd=\"bold\" class=\"scpt-fmt-btn\" title=\"Bold\"><b>B<\/b><\/button>\n        <button type=\"button\" data-cmd=\"italic\" class=\"scpt-fmt-btn\" title=\"Italic\"><i>I<\/i><\/button>\n        <button type=\"button\" data-cmd=\"underline\" class=\"scpt-fmt-btn\" title=\"Underline\"><u>U<\/u><\/button>\n        <button type=\"button\" data-cmd=\"strikeThrough\" class=\"scpt-fmt-btn\" title=\"Strikethrough\"><s>S<\/s><\/button>\n        <span class=\"scpt-separator\"><\/span>\n        <button type=\"button\" data-cmd=\"formatBlock\" data-value=\"H1\" class=\"scpt-fmt-btn\">H1<\/button>\n        <button type=\"button\" data-cmd=\"formatBlock\" data-value=\"H2\" class=\"scpt-fmt-btn\">H2<\/button>\n        <button type=\"button\" data-cmd=\"formatBlock\" data-value=\"P\" class=\"scpt-fmt-btn\">P<\/button>\n        <span class=\"scpt-separator\"><\/span>\n        <button type=\"button\" data-cmd=\"insertUnorderedList\" class=\"scpt-fmt-btn\" title=\"Bullet List\">\u2022 List<\/button>\n        <button type=\"button\" data-cmd=\"insertOrderedList\" class=\"scpt-fmt-btn\" title=\"Numbered List\">1. List<\/button>\n        <button type=\"button\" data-cmd=\"indent\" class=\"scpt-fmt-btn\" title=\"Indent\">\u2794 Indent<\/button>\n        <button type=\"button\" data-cmd=\"outdent\" class=\"scpt-fmt-btn\" title=\"Outdent\">\u2b05 Outdent<\/button>\n        <span class=\"scpt-separator\"><\/span>\n        <button type=\"button\" data-cmd=\"superscript\" class=\"scpt-fmt-btn\" title=\"Superscript\">X\u00b2<\/button>\n        <button type=\"button\" data-cmd=\"subscript\" class=\"scpt-fmt-btn\" title=\"Subscript\">X\u2082<\/button>\n        <span class=\"scpt-separator\"><\/span>\n        <button type=\"button\" id=\"scpt-insert-table-btn\" class=\"scpt-fmt-btn\">Insert Table<\/button>\n        <button type=\"button\" id=\"scpt-insert-svg-btn\" class=\"scpt-fmt-btn\">Insert Diagram<\/button>\n    <\/div>\n\n    <!-- Contextual Diagram Floating Toolbar -->\n    <div id=\"scpt-diagram-toolbar\" class=\"scpt-diagram-toolbar\" style=\"display: none;\">\n        <span class=\"scpt-diag-title\">Diagram Tools:<\/span>\n        <button type=\"button\" data-action=\"view\" class=\"scpt-btn scpt-diag-action\">View<\/button>\n        <button type=\"button\" data-action=\"center\" class=\"scpt-btn scpt-diag-action\">Center<\/button>\n        <button type=\"button\" data-action=\"copy\" class=\"scpt-btn scpt-diag-action\">Copy Diagram<\/button>\n        <button type=\"button\" data-action=\"svg\" class=\"scpt-btn scpt-diag-action\">Download SVG<\/button>\n        <button type=\"button\" data-action=\"delete\" class=\"scpt-btn scpt-diag-action scpt-btn-danger\">Delete<\/button>\n    <\/div>\n\n    <!-- Main Document Editor Canvas -->\n    <div class=\"scpt-editor-viewport\">\n        <div id=\"scpt-editor-content\" class=\"scpt-editor-canvas\" contenteditable=\"true\" spellcheck=\"false\">\n            <h1>Advanced AI Research Notes &amp; Equations<\/h1>\n            <p>Welcome to Smart Copy Paste. Paste messy AI notes, repair mathematical symbols, and manage structured documents seamlessly.<\/p>\n            \n            <h2>1. Mathematical Symbols &amp; Equations<\/h2>\n            <p>Expressions like x * y, a &lt;= b, a &gt;= b, -&gt;, and +- are automatically normalized. Greek letters and formulas ($x^2 + y^2 = z^2$, $E = mc^2$, $H_2O$, $\\pi$, $\\sum$) render cleanly.<\/p>\n\n            <h2>2. Structured Data Table<\/h2>\n            <div class=\"scpt-table-wrap\">\n                <table>\n                    <thead>\n                        <tr>\n                            <th>Constant<\/th>\n                            <th>Symbol<\/th>\n                            <th>Approximation<\/th>\n                        <\/tr>\n                    <\/thead>\n                    <tbody>\n                        <tr>\n                            <td>Pi Ratio<\/td>\n                            <td>$\\pi$<\/td>\n                            <td>$3.14159$<\/td>\n                        <\/tr>\n                        <tr>\n                            <td>Golden Ratio<\/td>\n                            <td>$\\phi$<\/td>\n                            <td>$1.61803$<\/td>\n                        <\/tr>\n                    <\/tbody>\n                <\/table>\n            <\/div>\n\n            <h2>3. Embedded Diagram Architecture<\/h2>\n            <p>Vector graphics remain fully interactive and scalable:<\/p>\n            <div class=\"scpt-diagram-node\" contenteditable=\"false\">\n                <svg viewBox=\"0 0 400 100\" width=\"100%\" height=\"auto\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <rect width=\"400\" height=\"100\" rx=\"6\" fill=\"#f8fafc\" stroke=\"#cbd5e1\" stroke-width=\"1\"><\/rect>\n                    <rect x=\"30\" y=\"30\" width=\"100\" height=\"40\" rx=\"4\" fill=\"#2563eb\"><\/rect>\n                    <text x=\"80\" y=\"55\" fill=\"#ffffff\" font-size=\"12\" font-weight=\"bold\" text-anchor=\"middle\">Smart Parser<\/text>\n                    <line x1=\"130\" y1=\"50\" x2=\"270\" y2=\"50\" stroke=\"#64748b\" stroke-width=\"2\"><\/line>\n                    <rect x=\"270\" y=\"30\" width=\"100\" height=\"40\" rx=\"4\" fill=\"#059669\"><\/rect>\n                    <text x=\"320\" y=\"55\" fill=\"#ffffff\" font-size=\"12\" font-weight=\"bold\" text-anchor=\"middle\">Clean Document<\/text>\n                <\/svg>\n            <\/div>\n        <\/div>\n    <\/div>\n\n    <!-- Document Check Modal \/ Overlay -->\n    <div id=\"scpt-modal-overlay\" class=\"scpt-modal-overlay\" style=\"display: none;\">\n        <div class=\"scpt-modal-dialog\">\n            <div class=\"scpt-modal-header\">\n                <h3 id=\"scpt-modal-title\">Document Quality Check<\/h3>\n                <button type=\"button\" id=\"scpt-modal-close\" class=\"scpt-modal-close-btn\">&times;<\/button>\n            <\/div>\n            <div id=\"scpt-modal-body\" class=\"scpt-modal-body\"><\/div>\n            <div class=\"scpt-modal-footer\">\n                <button type=\"button\" id=\"scpt-modal-action-btn\" class=\"scpt-btn scpt-btn-primary\">Apply Automatic Fixes<\/button>\n                <button type=\"button\" id=\"scpt-modal-dismiss-btn\" class=\"scpt-btn\">Close<\/button>\n            <\/div>\n        <\/div>\n    <\/div>\n\n    <!-- Table Insert Modal \/ Overlay -->\n    <div id=\"scpt-table-modal-overlay\" class=\"scpt-modal-overlay\" style=\"display: none;\">\n        <div class=\"scpt-modal-dialog\">\n            <div class=\"scpt-modal-header\">\n                <h3>Insert Table<\/h3>\n                <button type=\"button\" id=\"scpt-table-modal-close\" class=\"scpt-modal-close-btn\">&times;<\/button>\n            <\/div>\n            <div class=\"scpt-modal-body\">\n                <div style=\"margin-bottom: 12px;\">\n                    <label style=\"display:block; font-weight:600; margin-bottom:4px;\">Rows:<\/label>\n                    <input type=\"number\" id=\"scpt-table-rows\" value=\"3\" min=\"1\" max=\"20\" style=\"width:100%; padding:6px; border:1px solid #cbd5e1; border-radius:4px;\">\n                <\/div>\n                <div>\n                    <label style=\"display:block; font-weight:600; margin-bottom:4px;\">Columns:<\/label>\n                    <input type=\"number\" id=\"scpt-table-cols\" value=\"3\" min=\"1\" max=\"10\" style=\"width:100%; padding:6px; border:1px solid #cbd5e1; border-radius:4px;\">\n                <\/div>\n            <\/div>\n            <div class=\"scpt-modal-footer\">\n                <button type=\"button\" id=\"scpt-table-insert-confirm\" class=\"scpt-btn scpt-btn-primary\">Insert Table<\/button>\n                <button type=\"button\" id=\"scpt-table-modal-dismiss\" class=\"scpt-btn\">Cancel<\/button>\n            <\/div>\n        <\/div>\n    <\/div>\n\n    <!-- Paste AI Notes Modal \/ Overlay -->\n    <div id=\"scpt-paste-modal-overlay\" class=\"scpt-modal-overlay\" style=\"display: none;\">\n        <div class=\"scpt-modal-dialog\" style=\"max-width: 600px;\">\n            <div class=\"scpt-modal-header\">\n                <h3>Paste AI Notes \/ Content<\/h3>\n                <button type=\"button\" id=\"scpt-paste-modal-close\" class=\"scpt-modal-close-btn\">&times;<\/button>\n            <\/div>\n            <div class=\"scpt-modal-body\">\n                <p style=\"margin-top:0; font-size:13px; color:#64748b;\">Paste raw text, AI output, or HTML below. It will be sanitized and structured automatically.<\/p>\n                <textarea id=\"scpt-paste-textarea\" placeholder=\"Paste content here...\" style=\"width:100%; height:180px; padding:10px; border:1px solid #cbd5e1; border-radius:6px; font-family:inherit; font-size:14px; resize:vertical; outline:none;\"><\/textarea>\n            <\/div>\n            <div class=\"scpt-modal-footer\">\n                <button type=\"button\" id=\"scpt-paste-insert-confirm\" class=\"scpt-btn scpt-btn-primary\">Process &amp; Insert<\/button>\n                <button type=\"button\" id=\"scpt-paste-modal-dismiss\" class=\"scpt-btn\">Cancel<\/button>\n            <\/div>\n        <\/div>\n    <\/div>\n<\/div>\n\n<!-- Robust Production-Ready Application JavaScript -->\n<script>\n(function () {\n    'use strict';\n\n    if (window.SmartCopyPasteInitialized) return;\n    window.SmartCopyPasteInitialized = true;\n\n    function initApp() {\n        const root = document.getElementById('smart-copy-paste-tool');\n        const editor = root.querySelector('#scpt-editor-content');\n        if (!root || !editor) return;\n\n        \/\/ Application State\n        const state = {\n            history: [],\n            redoStack: [],\n            selectedDiagram: null,\n            savedRange: null,\n            isViewMode: false,\n            lastRecordedHtml: ''\n        };\n\n        const MOJIBAKE_MAP = {\n            '\u00e2\u02c6\u2018': '\u2211', '\u00e2\u02c6\u0161': '\u221a', '\u00e2\u02c6\u017e': '\u221e', '\u00cf\u20ac': '\u03c0',\n            '\u00ce\u00b1': '\u03b1', '\u00ce\u00b2': '\u03b2', '\u00ce\u00b3': '\u03b3', '\u00e2\u2030\u00a4': '\u2264',\n            '\u00e2\u2030\u00a5': '\u2265', '\u00e2\u2030 ': '\u2260', '\u00c3\u2014': '\u00d7', '\u00c3\u00b7': '\u00f7'\n        };\n\n        const MATH_SYMBOLS_MAP = {\n            '\\\\sum': '\u2211', '\\\\sqrt': '\u221a', '\\\\infty': '\u221e', '\\\\pi': '\u03c0',\n            '\\\\theta': '\u03b8', '\\\\alpha': '\u03b1', '\\\\beta': '\u03b2', '\\\\gamma': '\u03b3',\n            '\\\\Delta': '\u0394', '\\\\Sigma': '\u03a3', '\\\\\u03a9': '\u03a9', '\\\\mu': '\u03bc',\n            '\\\\lambda': '\u03bb', '\\\\leq': '\u2264', '\\\\geq': '\u2265', '\\\\neq': '\u2260',\n            '\\\\approx': '\u2248', '\\\\pm': '\u00b1', '\\\\times': '\u00d7', '\\\\div': '\u00f7',\n            '\\\\int': '\u222b', '\\\\partial': '\u2202', '\\\\nabla': '\u2207'\n        };\n\n        \/\/ Notification \/ Toast System\n        function showToast(message, isError = false) {\n            const existing = root.querySelector('#scpt-toast');\n            if (existing) existing.remove();\n\n            const toast = document.createElement('div');\n            toast.id = 'scpt-toast';\n            toast.textContent = message;\n            Object.assign(toast.style, {\n                position: 'fixed',\n                bottom: '24px',\n                right: '24px',\n                backgroundColor: isError ? '#ef4444' : '#059669',\n                color: '#ffffff',\n                padding: '10px 18px',\n                borderRadius: '6px',\n                boxShadow: '0 4px 12px rgba(0,0,0,0.15)',\n                fontFamily: 'system-ui, sans-serif',\n                fontSize: '14px',\n                fontWeight: '500',\n                zIndex: '99999',\n                opacity: '0',\n                transition: 'opacity 0.2s ease'\n            });\n            root.appendChild(toast);\n            requestAnimationFrame(() => { toast.style.opacity = '1'; });\n            setTimeout(() => {\n                toast.style.opacity = '0';\n                setTimeout(() => toast.remove(), 300);\n            }, 2500);\n        }\n\n        \/\/ History Management\n        function saveStateToHistory(force = false) {\n            const currentHtml = editor.innerHTML;\n            if (!force && currentHtml === state.lastRecordedHtml) return;\n            state.history.push(currentHtml);\n            if (state.history.length > 50) state.history.shift();\n            state.redoStack = [];\n            state.lastRecordedHtml = currentHtml;\n            updateUndoRedoButtons();\n        }\n\n        function updateUndoRedoButtons() {\n            const undoBtn = root.querySelector('#scpt-undo-btn');\n            const redoBtn = root.querySelector('#scpt-redo-btn');\n            if (undoBtn) undoBtn.disabled = state.history.length <= 1;\n            if (redoBtn) redoBtn.disabled = state.redoStack.length === 0;\n        }\n\n        function executeUndo() {\n            if (state.history.length <= 1) return;\n            state.redoStack.push(state.history.pop());\n            const previousHtml = state.history[state.history.length - 1];\n            editor.innerHTML = previousHtml;\n            state.lastRecordedHtml = previousHtml;\n            updateUndoRedoButtons();\n            showToast('Undo executed');\n        }\n\n        function executeRedo() {\n            if (state.redoStack.length === 0) return;\n            const nextHtml = state.redoStack.pop();\n            state.history.push(nextHtml);\n            editor.innerHTML = nextHtml;\n            state.lastRecordedHtml = nextHtml;\n            updateUndoRedoButtons();\n            showToast('Redo executed');\n        }\n\n        \/\/ Selection &#038; Range Helpers\n        function saveSelection() {\n            const sel = window.getSelection();\n            if (sel &#038;&#038; sel.rangeCount > 0) {\n                const range = sel.getRangeAt(0);\n                if (editor.contains(range.commonAncestorContainer) || editor === range.commonAncestorContainer) {\n                    state.savedRange = range.cloneRange();\n                }\n            }\n        }\n\n        function restoreSelection() {\n            editor.focus();\n            if (state.savedRange) {\n                try {\n                    const sel = window.getSelection();\n                    sel.removeAllRanges();\n                    sel.addRange(state.savedRange);\n                } catch (e) {\n                    \/\/ Fallback if range became detached\n                }\n            }\n        }\n\n        \/\/ Safe Symbol Repair on Text Nodes & Content\n        function repairTextContent(text) {\n            let res = text;\n            for (const [bad, good] of Object.entries(MOJIBAKE_MAP)) {\n                res = res.split(bad).join(good);\n            }\n            for (const [latex, unicode] of Object.entries(MATH_SYMBOLS_MAP)) {\n                const regex = new RegExp(latex.replace(\/\\\\\/g, '\\\\\\\\') + '(?![a-zA-Z])', 'g');\n                res = res.replace(regex, unicode);\n            }\n            res = res.replace(\/\\s\\*\\s\/g, ' \u00d7 ');\n            res = res.replace(\/\\s<=\\s\/g, ' \u2264 ');\n            res = res.replace(\/\\s>=\\s\/g, ' \u2265 ');\n            res = res.replace(\/\\s!=\\s\/g, ' \u2260 ');\n            res = res.replace(\/\\s->\\s\/g, ' \u2192 ');\n            res = res.replace(\/\\s<-\\s\/g, ' \u2190 ');\n            res = res.replace(\/\\s\\+-\\s\/g, ' \u00b1 ');\n            res = res.replace(\/\\.\\.\\.\/g, '\u2026');\n            res = res.replace(\/--\/g, '\u2013');\n            res = res.replace(\/---\/g, '\u2014');\n\n            \/\/ Handle inline math expressions like $x^2 + y^2 = z^2$\n            res = res.replace(\/\\$([^$]+)\\$\/g, (match, inner) => {\n                let processed = inner.replace(\/\\^([0-9a-zA-Z\\+\\-]+)\/g, '<sup>$1<\/sup>');\n                processed = processed.replace(\/_([0-9a-zA-Z]+)\/g, '<sub>$1<\/sub>');\n                return `<span style=\"font-family:serif;\">${processed}<\/span>`;\n            });\n            return res;\n        }\n\n        function repairHtmlSubtree(node) {\n            let changed = false;\n            if (node.nodeType === Node.TEXT_NODE) {\n                const repaired = repairTextContent(node.nodeValue);\n                if (repaired !== node.nodeValue) {\n                    node.nodeValue = repaired;\n                    changed = true;\n                }\n            } else if (node.nodeType === Node.ELEMENT_NODE) {\n                if (node.tagName === 'SCRIPT' || node.tagName === 'STYLE' || node.classList.contains('scpt-diagram-node')) {\n                    return false;\n                }\n                for (let child of Array.from(node.childNodes)) {\n                    if (repairHtmlSubtree(child)) {\n                        changed = true;\n                    }\n                }\n            }\n            return changed;\n        }\n\n        function repairSymbolsInEditor() {\n            saveStateToHistory();\n            const beforeHtml = editor.innerHTML;\n            repairHtmlSubtree(editor);\n            const afterHtml = editor.innerHTML;\n            if (beforeHtml !== afterHtml) {\n                state.lastRecordedHtml = afterHtml;\n                updateUndoRedoButtons();\n                showToast('Symbols repaired successfully');\n            } else {\n                showToast('No broken symbols found to repair');\n            }\n        }\n\n        \/\/ Robust HTML Sanitizer & Paste Parser\n        function sanitizeAndParseHtml(inputHtmlOrText) {\n            const parser = new DOMParser();\n            const doc = parser.parseFromString(inputHtmlOrText, 'text\/html');\n\n            doc.querySelectorAll('script, style, iframe, object, embed, link, meta, form, input, button').forEach(el => el.remove());\n\n            doc.querySelectorAll('*').forEach(el => {\n                Array.from(el.attributes).forEach(attr => {\n                    const name = attr.name.toLowerCase();\n                    if (name.startsWith('on') || name.startsWith('java') || (name === 'href' && attr.value.trim().toLowerCase().startsWith('javascript:'))) {\n                        el.removeAttribute(attr.name);\n                    }\n                });\n                if (el.hasAttribute('style')) {\n                    el.removeAttribute('style');\n                }\n            });\n\n            if (!inputHtmlOrText.includes('<') || doc.body.textContent === inputHtmlOrText) {\n                const lines = inputHtmlOrText.split(\/\\r?\\n\\r?\\n\/);\n                doc.body.innerHTML = lines.map(line => line.trim() ? `<p>${escapeHtml(line)}<\/p>` : '').join('');\n            }\n\n            doc.querySelectorAll('table').forEach(tbl => {\n                if (!tbl.parentElement.classList.contains('scpt-table-wrap')) {\n                    const wrapper = doc.createElement('div');\n                    wrapper.className = 'scpt-table-wrap';\n                    tbl.parentNode.insertBefore(wrapper, tbl);\n                    wrapper.appendChild(tbl);\n                }\n            });\n\n            repairHtmlSubtree(doc.body);\n            return doc.body.innerHTML;\n        }\n\n        function escapeHtml(str) {\n            return str.replace(\/&\/g, '&amp;').replace(\/<\/g, '&lt;').replace(\/>\/g, '&gt;').replace(\/\"\/g, '&quot;');\n        }\n\n        \/\/ Document Quality Checker\n        function runDocumentCheck() {\n            const html = editor.innerHTML;\n            const paragraphs = editor.querySelectorAll('p').length;\n            const headings = editor.querySelectorAll('h1, h2, h3, h4, h5, h6').length;\n            const lists = editor.querySelectorAll('ul, ol').length;\n            const tables = editor.querySelectorAll('table').length;\n            \n            const emptyParas = Array.from(editor.querySelectorAll('p')).filter(p => !p.textContent.trim() && !p.querySelector('svg')).length;\n            \n            let suspiciousSymbols = 0;\n            ['\u00e2\u02c6', '\u00c3\u2014', '\u00c2'].forEach(char => {\n                if (html.includes(char)) suspiciousSymbols++;\n            });\n\n            const modalOverlay = root.querySelector('#scpt-modal-overlay');\n            const modalBody = root.querySelector('#scpt-modal-body');\n            const actionBtn = root.querySelector('#scpt-modal-action-btn');\n\n            if (modalOverlay && modalBody) {\n                let report = '<ul>';\n                report += `<li>\u2713 <strong>Paragraphs:<\/strong> ${paragraphs}<\/li>`;\n                report += `<li>\u2713 <strong>Headings:<\/strong> ${headings}<\/li>`;\n                report += `<li>\u2713 <strong>Lists:<\/strong> ${lists}<\/li>`;\n                report += `<li>\u2713 <strong>Tables:<\/strong> ${tables}<\/li>`;\n                report += emptyParas > 0 ? `<li>\u26a0 <strong>Empty paragraphs:<\/strong> ${emptyParas} detected.<\/li>` : '<li>\u2713 No empty paragraphs found.<\/li>';\n                report += suspiciousSymbols > 0 ? `<li>\u26a0 <strong>Suspicious \/ Mojibake symbols:<\/strong> ${suspiciousSymbols} detected.<\/li>` : '<li>\u2713 Symbol encoding is clean.<\/li>';\n                report += '<\/ul>';\n\n                modalBody.innerHTML = report;\n                modalOverlay.style.display = 'flex';\n\n                if (actionBtn) {\n                    actionBtn.onclick = (e) => {\n                        e.preventDefault();\n                        saveStateToHistory();\n                        editor.querySelectorAll('p').forEach(p => {\n                            if (!p.textContent.trim() && !p.querySelector('svg')) p.remove();\n                        });\n                        repairHtmlSubtree(editor);\n                        modalOverlay.style.display = 'none';\n                        state.lastRecordedHtml = editor.innerHTML;\n                        updateUndoRedoButtons();\n                        showToast('Automatic fixes applied successfully');\n                    };\n                }\n            }\n        }\n\n        \/\/ Clipboard Manager\n        const ClipboardManager = {\n            async copyFull() {\n                const html = editor.innerHTML;\n                const plain = editor.textContent || '';\n                try {\n                    if (navigator.clipboard && window.ClipboardItem) {\n                        await navigator.clipboard.write([\n                            new ClipboardItem({\n                                'text\/html': new Blob([html], { type: 'text\/html;charset=utf-8' }),\n                                'text\/plain': new Blob([plain], { type: 'text\/plain;charset=utf-8' })\n                            })\n                        ]);\n                        showToast('Copied Full Notes successfully');\n                    } else {\n                        await navigator.clipboard.writeText(plain);\n                        showToast('Copied as Plain Text');\n                    }\n                } catch (err) {\n                    showToast('Clipboard copy failed', true);\n                }\n            },\n            async copyForWord() {\n                const clone = editor.cloneNode(true);\n                clone.querySelectorAll('.scpt-diagram-node').forEach(node => {\n                    node.removeAttribute('contenteditable');\n                    node.style.border = 'none';\n                });\n                const html = clone.innerHTML;\n                const plain = clone.textContent || '';\n                try {\n                    if (navigator.clipboard && window.ClipboardItem) {\n                        await navigator.clipboard.write([\n                            new ClipboardItem({\n                                'text\/html': new Blob([html], { type: 'text\/html;charset=utf-8' }),\n                                'text\/plain': new Blob([plain], { type: 'text\/plain;charset=utf-8' })\n                            })\n                        ]);\n                        showToast('Copied for Microsoft Word successfully');\n                    } else {\n                        await navigator.clipboard.writeText(plain);\n                        showToast('Copied as Plain Text (Fallback)');\n                    }\n                } catch (err) {\n                    showToast('Word copy failed', true);\n                }\n            },\n            async copyHtml() {\n                try {\n                    await navigator.clipboard.writeText(editor.innerHTML);\n                    showToast('Copied Clean HTML source');\n                } catch (err) {\n                    showToast('Copy HTML failed', true);\n                }\n            },\n            async copyPlainText() {\n                try {\n                    await navigator.clipboard.writeText(editor.textContent || '');\n                    showToast('Copied Plain Text');\n                } catch (err) {\n                    showToast('Copy plain text failed', true);\n                }\n            }\n        };\n\n        \/\/ Export & Print\n        function exportWordDoc() {\n            const html = editor.innerHTML;\n            const docxHeader = '<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:w=\"urn:schemas-microsoft-com:office:word\" xmlns=\"http:\/\/www.w3.org\/TR\/REC-html40\"><head><meta charset=\"utf-8\"><title>Export<\/title><\/head><body>';\n            const docxFooter = '<\/body><\/html>';\n            const blob = new Blob([docxHeader + html + docxFooter], { type: 'application\/msword;charset=utf-8' });\n            const url = URL.createObjectURL(blob);\n            const a = document.createElement('a');\n            a.href = url;\n            a.download = `smart-notes-${Date.now()}.doc`;\n            document.body.appendChild(a);\n            a.click();\n            document.body.removeChild(a);\n            URL.revokeObjectURL(url);\n            showToast('Word-compatible document exported');\n        }\n\n        function printDocument() {\n            const win = window.open('', '_blank');\n            if (!win) {\n                showToast('Popup blocked. Allow popups to print.', true);\n                return;\n            }\n            win.document.write(`<!DOCTYPE html><html><head><title>Print Notes<\/title><style>body{font-family:sans-serif;line-height:1.6;padding:40px;color:#000;}table{border-collapse:collapse;width:100%;margin-bottom:16px;}th,td{border:1px solid #333;padding:8px;text-align:left;}svg{max-width:100%;height:auto;display:block;margin:16px auto;}<\/style><\/head><body>${editor.innerHTML}<\/body><\/html>`);\n            win.document.close();\n            win.focus();\n            setTimeout(() => { win.print(); win.close(); }, 300);\n        }\n\n        \/\/ Formatting Helper using Saved Range\n        function applyFormat(command, value = null) {\n            saveStateToHistory();\n            restoreSelection();\n            if (command === 'formatBlock') {\n                document.execCommand('formatBlock', false, `<${value}>`);\n            } else {\n                document.execCommand(command, false, value);\n            }\n            state.lastRecordedHtml = editor.innerHTML;\n            updateUndoRedoButtons();\n            editor.focus();\n        }\n\n        \/\/ Insert Table at Cursor\n        const tableModal = root.querySelector('#scpt-table-modal-overlay');\n        function openTableModal() {\n            saveSelection();\n            if (tableModal) tableModal.style.display = 'flex';\n        }\n\n        function closeTableModal() {\n            if (tableModal) tableModal.style.display = 'none';\n        }\n\n        function insertTableAtSelection() {\n            saveStateToHistory();\n            restoreSelection();\n            const rows = parseInt(root.querySelector('#scpt-table-rows').value) || 3;\n            const cols = parseInt(root.querySelector('#scpt-table-cols').value) || 3;\n\n            let tableHtml = '<div class=\"scpt-table-wrap\"><table><thead><tr>';\n            for (let c = 0; c < cols; c++) tableHtml += `<th>Header ${c + 1}<\/th>`;\n            tableHtml += '<\/tr><\/thead><tbody>';\n            for (let r = 0; r < rows - 1; r++) {\n                tableHtml += '<tr>';\n                for (let c = 0; c < cols; c++) tableHtml += `<td>Data ${r + 1},${c + 1}<\/td>`;\n                tableHtml += '<\/tr>';\n            }\n            tableHtml += '<\/tbody><\/table><\/div><p><br><\/p>';\n\n            const sel = window.getSelection();\n            if (sel && sel.rangeCount > 0 && editor.contains(sel.getRangeAt(0).commonAncestorContainer)) {\n                const range = sel.getRangeAt(0);\n                range.deleteContents();\n                const el = document.createElement('div');\n                el.innerHTML = tableHtml;\n                const frag = document.createDocumentFragment();\n                let lastNode;\n                while (el.firstChild) {\n                    lastNode = frag.appendChild(el.firstChild);\n                }\n                range.insertNode(frag);\n                if (lastNode) {\n                    range.setStartAfter(lastNode);\n                    range.collapse(true);\n                    sel.removeAllRanges();\n                    sel.addRange(range);\n                }\n            } else {\n                editor.insertAdjacentHTML('beforeend', tableHtml);\n            }\n\n            closeTableModal();\n            state.lastRecordedHtml = editor.innerHTML;\n            updateUndoRedoButtons();\n            showToast('Table inserted successfully');\n        }\n\n        \/\/ Insert Diagram at Cursor\n        function insertDiagramAtSelection() {\n            saveStateToHistory();\n            restoreSelection();\n            const svgHtml = '<div class=\"scpt-diagram-node\" contenteditable=\"false\"><svg viewBox=\"0 0 350 90\" width=\"100%\" height=\"auto\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><rect width=\"350\" height=\"90\" rx=\"6\" fill=\"#f8fafc\" stroke=\"#cbd5e1\" stroke-width=\"1\"\/><rect x=\"20\" y=\"25\" width=\"90\" height=\"40\" rx=\"4\" fill=\"#2563eb\"\/><text x=\"65\" y=\"50\" fill=\"#ffffff\" font-size=\"11\" font-weight=\"bold\" text-anchor=\"middle\">Input Source<\/text><line x1=\"110\" y1=\"45\" x2=\"240\" y2=\"45\" stroke=\"#64748b\" stroke-width=\"2\"\/><polygon points=\"240,42 248,45 240,48\" fill=\"#64748b\"\/><rect x=\"248\" y=\"25\" width=\"90\" height=\"40\" rx=\"4\" fill=\"#059669\"\/><text x=\"293\" y=\"50\" fill=\"#ffffff\" font-size=\"11\" font-weight=\"bold\" text-anchor=\"middle\">Output Node<\/text><\/svg><\/div><p><br><\/p>';\n            \n            const sel = window.getSelection();\n            if (sel && sel.rangeCount > 0 && editor.contains(sel.getRangeAt(0).commonAncestorContainer)) {\n                const range = sel.getRangeAt(0);\n                range.deleteContents();\n                const el = document.createElement('div');\n                el.innerHTML = svgHtml;\n                const frag = document.createDocumentFragment();\n                let lastNode;\n                while (el.firstChild) {\n                    lastNode = frag.appendChild(el.firstChild);\n                }\n                range.insertNode(frag);\n                if (lastNode) {\n                    range.setStartAfter(lastNode);\n                    range.collapse(true);\n                    sel.removeAllRanges();\n                    sel.addRange(range);\n                }\n            } else {\n                editor.insertAdjacentHTML('beforeend', svgHtml);\n            }\n\n            state.lastRecordedHtml = editor.innerHTML;\n            updateUndoRedoButtons();\n            showToast('Diagram inserted successfully');\n        }\n\n        \/\/ Paste AI Notes Modal workflow\n        const pasteModal = root.querySelector('#scpt-paste-modal-overlay');\n        const pasteTextarea = root.querySelector('#scpt-paste-textarea');\n\n        async function openPasteModal() {\n            saveSelection();\n            if (pasteTextarea) pasteTextarea.value = '';\n            try {\n                if (navigator.clipboard && navigator.clipboard.readText) {\n                    const text = await navigator.clipboard.readText();\n                    if (text && pasteTextarea) {\n                        pasteTextarea.value = text;\n                    }\n                }\n            } catch (err) {\n                \/\/ Clipboard read permission denied or not supported; allow manual paste in textarea\n            }\n            if (pasteModal) pasteModal.style.display = 'flex';\n            if (pasteTextarea) pasteTextarea.focus();\n        }\n\n        function closePasteModal() {\n            if (pasteModal) pasteModal.style.display = 'none';\n        }\n\n        function confirmPasteModal() {\n            if (!pasteTextarea) return;\n            const content = pasteTextarea.value;\n            if (!content.trim()) {\n                showToast('Paste content is empty', true);\n                return;\n            }\n            saveStateToHistory();\n            restoreSelection();\n            const parsed = sanitizeAndParseHtml(content);\n\n            const sel = window.getSelection();\n            if (sel && sel.rangeCount > 0 && editor.contains(sel.getRangeAt(0).commonAncestorContainer)) {\n                const range = sel.getRangeAt(0);\n                range.deleteContents();\n                const el = document.createElement('div');\n                el.innerHTML = parsed;\n                const frag = document.createDocumentFragment();\n                let lastNode;\n                while (el.firstChild) {\n                    lastNode = frag.appendChild(el.firstChild);\n                }\n                range.insertNode(frag);\n                if (lastNode) {\n                    range.setStartAfter(lastNode);\n                    range.collapse(true);\n                    sel.removeAllRanges();\n                    sel.addRange(range);\n                }\n            } else {\n                editor.insertAdjacentHTML('beforeend', parsed);\n            }\n\n            closePasteModal();\n            state.lastRecordedHtml = editor.innerHTML;\n            updateUndoRedoButtons();\n            showToast('AI notes parsed and inserted successfully');\n        }\n\n        \/\/ Event Listeners Initialization\n        root.addEventListener('click', (e) => {\n            const diagNode = e.target.closest('.scpt-diagram-node');\n            const diagToolbar = root.querySelector('#scpt-diagram-toolbar');\n            \n            root.querySelectorAll('.scpt-diagram-node').forEach(n => n.classList.remove('selected'));\n            if (diagNode) {\n                diagNode.classList.add('selected');\n                state.selectedDiagram = diagNode;\n                if (diagToolbar) diagToolbar.style.display = 'flex';\n            } else if (!e.target.closest('#scpt-diagram-toolbar')) {\n                state.selectedDiagram = null;\n                if (diagToolbar) diagToolbar.style.display = 'none';\n            }\n        });\n\n        \/\/ Toolbar Buttons binding\n        root.querySelector('#scpt-smart-paste-btn').onclick = (e) => { e.preventDefault(); openPasteModal(); };\n        root.querySelector('#scpt-fix-symbols-btn').onclick = (e) => { e.preventDefault(); repairSymbolsInEditor(); };\n        root.querySelector('#scpt-doc-check-btn').onclick = (e) => { e.preventDefault(); runDocumentCheck(); };\n        root.querySelector('#scpt-undo-btn').onclick = (e) => { e.preventDefault(); executeUndo(); };\n        root.querySelector('#scpt-redo-btn').onclick = (e) => { e.preventDefault(); executeRedo(); };\n\n        root.querySelector('#scpt-copy-full-btn').onclick = (e) => { e.preventDefault(); ClipboardManager.copyFull(); };\n        root.querySelector('#scpt-copy-word-btn').onclick = (e) => { e.preventDefault(); ClipboardManager.copyForWord(); };\n        root.querySelector('#scpt-copy-html-btn').onclick = (e) => { e.preventDefault(); ClipboardManager.copyHtml(); };\n        root.querySelector('#scpt-copy-plain-btn').onclick = (e) => { e.preventDefault(); ClipboardManager.copyPlainText(); };\n\n        root.querySelector('#scpt-export-word-btn').onclick = (e) => { e.preventDefault(); exportWordDoc(); };\n        root.querySelector('#scpt-print-pdf-btn').onclick = (e) => { e.preventDefault(); printDocument(); };\n\n        \/\/ Formatting buttons\n        root.querySelectorAll('.scpt-fmt-btn[data-cmd]').forEach(btn => {\n            btn.onclick = (e) => {\n                e.preventDefault();\n                applyFormat(btn.dataset.cmd, btn.dataset.value || null);\n            };\n        });\n\n        root.querySelector('#scpt-insert-table-btn').onclick = (e) => { e.preventDefault(); openTableModal(); };\n        root.querySelector('#scpt-insert-svg-btn').onclick = (e) => { e.preventDefault(); insertDiagramAtSelection(); };\n\n        \/\/ View mode toggles\n        root.querySelectorAll('.scpt-view-btn').forEach(btn => {\n            btn.onclick = (e) => {\n                e.preventDefault();\n                root.querySelectorAll('.scpt-view-btn').forEach(b => b.classList.remove('active'));\n                btn.classList.add('active');\n                const view = btn.dataset.view;\n                if (view === 'editor') {\n                    state.isViewMode = false;\n                    editor.setAttribute('contenteditable', 'true');\n                    showToast('Switched to Editor Mode');\n                } else if (view === 'preview') {\n                    state.isViewMode = true;\n                    editor.setAttribute('contenteditable', 'false');\n                    showToast('Switched to Preview Mode');\n                } else if (view === 'print') {\n                    printDocument();\n                }\n            };\n        });\n\n        \/\/ Modals closing events\n        root.querySelector('#scpt-modal-close').onclick = (e) => { e.preventDefault(); root.querySelector('#scpt-modal-overlay').style.display = 'none'; };\n        root.querySelector('#scpt-modal-dismiss-btn').onclick = (e) => { e.preventDefault(); root.querySelector('#scpt-modal-overlay').style.display = 'none'; };\n\n        root.querySelector('#scpt-table-modal-close').onclick = (e) => { e.preventDefault(); closeTableModal(); };\n        root.querySelector('#scpt-table-modal-dismiss').onclick = (e) => { e.preventDefault(); closeTableModal(); };\n        root.querySelector('#scpt-table-insert-confirm').onclick = (e) => { e.preventDefault(); insertTableAtSelection(); };\n\n        root.querySelector('#scpt-paste-modal-close').onclick = (e) => { e.preventDefault(); closePasteModal(); };\n        root.querySelector('#scpt-paste-modal-dismiss').onclick = (e) => { e.preventDefault(); closePasteModal(); };\n        root.querySelector('#scpt-paste-insert-confirm').onclick = (e) => { e.preventDefault(); confirmPasteModal(); };\n\n        \/\/ Diagram Actions\n        root.querySelectorAll('.scpt-diag-action').forEach(btn => {\n            btn.onclick = (e) => {\n                e.preventDefault();\n                if (!state.selectedDiagram) {\n                    showToast('No diagram selected', true);\n                    return;\n                }\n                const action = btn.dataset.action;\n                const svgEl = state.selectedDiagram.querySelector('svg');\n\n                if (action === 'view' || action === 'center') {\n                    state.selectedDiagram.scrollIntoView({ behavior: 'smooth', block: 'center' });\n                    showToast(action === 'center' ? 'Diagram centered' : 'Viewing diagram');\n                } else if (action === 'copy') {\n                    if (svgEl) {\n                        navigator.clipboard.writeText(svgEl.outerHTML);\n                        showToast('Diagram SVG copied to clipboard');\n                    }\n                } else if (action === 'svg') {\n                    if (svgEl) {\n                        const blob = new Blob([svgEl.outerHTML], { type: 'image\/svg+xml;charset=utf-8' });\n                        const url = URL.createObjectURL(blob);\n                        const a = document.createElement('a');\n                        a.href = url;\n                        a.download = `diagram-${Date.now()}.svg`;\n                        document.body.appendChild(a);\n                        a.click();\n                        document.body.removeChild(a);\n                        URL.revokeObjectURL(url);\n                        showToast('SVG downloaded successfully');\n                    }\n                } else if (action === 'delete') {\n                    saveStateToHistory();\n                    state.selectedDiagram.remove();\n                    state.selectedDiagram = null;\n                    root.querySelector('#scpt-diagram-toolbar').style.display = 'none';\n                    state.lastRecordedHtml = editor.innerHTML;\n                    updateUndoRedoButtons();\n                    showToast('Diagram deleted');\n                }\n            };\n        });\n\n        \/\/ Editor input & mutation handling\n        let debounceTimer;\n        editor.addEventListener('input', () => {\n            if (state.isViewMode) return;\n            clearTimeout(debounceTimer);\n            debounceTimer = setTimeout(() => {\n                saveStateToHistory();\n            }, 500);\n        });\n\n        editor.addEventListener('mouseup', saveSelection);\n        editor.addEventListener('keyup', saveSelection);\n\n        \/\/ Keyboard shortcuts\n        editor.addEventListener('keydown', (e) => {\n            if ((e.ctrlKey || e.metaKey) && !e.shiftKey && e.key.toLowerCase() === 'z') {\n                e.preventDefault();\n                executeUndo();\n            } else if ((e.ctrlKey || e.metaKey) && (e.key.toLowerCase() === 'y' || (e.shiftKey && e.key.toLowerCase() === 'z'))) {\n                e.preventDefault();\n                executeRedo();\n            }\n        });\n\n        \/\/ Initialize first history entry\n        state.history.push(editor.innerHTML);\n        state.lastRecordedHtml = editor.innerHTML;\n        updateUndoRedoButtons();\n    }\n\n    if (document.readyState === 'loading') {\n        document.addEventListener('DOMContentLoaded', initApp);\n    } else {\n        initApp();\n    }\n})();\n<\/script>\n\n<\/body>\n<\/html>\n","protected":false},"excerpt":{"rendered":"<p>Smart Copy Paste Application Smart Copy Paste Workflow: Paste AI Notes Fix Symbols Document Check Undo Redo View Mode: Editor Preview Print Preview Copy: Copy Full Notes Copy for Word Copy HTML Copy Plain Text Export \/ Print: Export Word Print \/ PDF B I U S H1 H2 P \u2022 List 1. List \u2794 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-996","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/freewebtools.co.in\/index.php\/wp-json\/wp\/v2\/pages\/996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freewebtools.co.in\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/freewebtools.co.in\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/freewebtools.co.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freewebtools.co.in\/index.php\/wp-json\/wp\/v2\/comments?post=996"}],"version-history":[{"count":8,"href":"https:\/\/freewebtools.co.in\/index.php\/wp-json\/wp\/v2\/pages\/996\/revisions"}],"predecessor-version":[{"id":1004,"href":"https:\/\/freewebtools.co.in\/index.php\/wp-json\/wp\/v2\/pages\/996\/revisions\/1004"}],"wp:attachment":[{"href":"https:\/\/freewebtools.co.in\/index.php\/wp-json\/wp\/v2\/media?parent=996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}