const fs = require('fs'); const js = fs.readFileSync('c:/dev/git/python/ObsiGate/frontend/app.js', 'utf8'); const extractManager = (name) => { const regex = new RegExp('const ' + name + ' = \\{[\\s\\S]*?\\n \\};'); const match = regex.exec(js); return match ? match[0] : ''; }; // Also we need variables const vars = 'let rightSidebarVisible = false;\nlet rightSidebarWidth = 280;\nlet headingsCache = [];\nlet activeHeadingId = null;'; const utils = 'function el(tag, attrs, children) {\n const e = document.createElement(tag);\n if (attrs) { for (let k in attrs) { if (k === "class") e.className = attrs[k]; else e.setAttribute(k, attrs[k]); } }\n if (children) { children.forEach(c => { if (typeof c === "string") e.appendChild(document.createTextNode(c)); else e.appendChild(c); }); }\n return e;\n}'; const safeCreateIcons = 'function safeCreateIcons() { if (window.lucide) window.lucide.createIcons(); }'; const code = [ vars, utils, safeCreateIcons, extractManager('OutlineManager'), extractManager('ScrollSpyManager'), extractManager('ReadingProgressManager'), extractManager('RightSidebarManager') ].join('\n\n'); let html = fs.readFileSync('c:/dev/git/python/ObsiGate/frontend/popout.html', 'utf8'); // replace body layout html = html.replace('
\n
', `
`); html = html.replace('
\n
', `
`); // Inject TOC button html = html.replace('actionsDiv.appendChild(dlBtn);', `actionsDiv.appendChild(dlBtn); const tocBtn = document.createElement("button"); tocBtn.className = "btn-action"; tocBtn.id = "toc-toggle-btn"; tocBtn.title = "Afficher/Masquer le sommaire"; tocBtn.innerHTML = ' TOC'; tocBtn.addEventListener("click", () => { RightSidebarManager.toggle(); }); actionsDiv.appendChild(tocBtn);`); // init TOC manager html = html.replace('// Highlight code blocks', `OutlineManager.init(); RightSidebarManager.init(); // Highlight code blocks`); // insert the managers code before initPopout(); html = html.replace('async function initPopout()', code + '\n\n async function initPopout()'); fs.writeFileSync('c:/dev/git/python/ObsiGate/frontend/popout.html', html); console.log('Script ran successfully');