From 912ce41497f0be4dce0ec7874e7a42dfe1dffdf0 Mon Sep 17 00:00:00 2001 From: Gildas Date: Tue, 22 Nov 2022 01:43:03 +0100 Subject: [PATCH] make sure init script is appended after the notes see https://github.com/gildas-lormeau/SingleFile/discussions/1057 --- lib/single-file-extension-editor.js | 14 ++++---------- src/ui/content/content-ui-editor-web.js | 14 ++++---------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/lib/single-file-extension-editor.js b/lib/single-file-extension-editor.js index bfe43f441..428e3468b 100644 --- a/lib/single-file-extension-editor.js +++ b/lib/single-file-extension-editor.js @@ -1893,17 +1893,13 @@ pre code { element.style.removeProperty("-sf-" + pointerEvents); }); doc.body.removeAttribute("contentEditable"); - const scriptElement = doc.createElement("script"); - scriptElement.setAttribute(SCRIPT_TEMPLATE_SHADOW_ROOT, ""); - scriptElement.textContent = getEmbedScript(); - doc.body.appendChild(scriptElement); const newResources = Object.keys(updatedResources).filter(url => updatedResources[url].type == "stylesheet").map(url => updatedResources[url]); newResources.forEach(resource => { const element = doc.createElement("style"); doc.body.appendChild(element); element.textContent = resource.content; }); - return singlefile.helper.serialize(doc, compressHTML); + return singlefile.helper.serialize(doc, compressHTML) + ""; } function onUpdate(saved) { @@ -2060,11 +2056,9 @@ pre code { window.onresize = reflowNotes; window.onUpdate = () => {}; document.documentElement.onmouseup = document.documentElement.ontouchend = onMouseUp; - window.addEventListener("DOMContentLoaded", () => { - processNode(document); - reflowNotes(); - document.querySelectorAll(${JSON.stringify(NOTE_TAGNAME)}).forEach(noteElement => attachNoteListeners(noteElement)); - }); + processNode(document); + reflowNotes(); + document.querySelectorAll(${JSON.stringify(NOTE_TAGNAME)}).forEach(noteElement => attachNoteListeners(noteElement)); })()`); } diff --git a/src/ui/content/content-ui-editor-web.js b/src/ui/content/content-ui-editor-web.js index 21f341284..958414cab 100644 --- a/src/ui/content/content-ui-editor-web.js +++ b/src/ui/content/content-ui-editor-web.js @@ -1890,17 +1890,13 @@ pre code { element.style.removeProperty("-sf-" + pointerEvents); }); doc.body.removeAttribute("contentEditable"); - const scriptElement = doc.createElement("script"); - scriptElement.setAttribute(SCRIPT_TEMPLATE_SHADOW_ROOT, ""); - scriptElement.textContent = getEmbedScript(); - doc.body.appendChild(scriptElement); const newResources = Object.keys(updatedResources).filter(url => updatedResources[url].type == "stylesheet").map(url => updatedResources[url]); newResources.forEach(resource => { const element = doc.createElement("style"); doc.body.appendChild(element); element.textContent = resource.content; }); - return singlefile.helper.serialize(doc, compressHTML); + return singlefile.helper.serialize(doc, compressHTML) + ""; } function onUpdate(saved) { @@ -2057,11 +2053,9 @@ pre code { window.onresize = reflowNotes; window.onUpdate = () => {}; document.documentElement.onmouseup = document.documentElement.ontouchend = onMouseUp; - window.addEventListener("DOMContentLoaded", () => { - processNode(document); - reflowNotes(); - document.querySelectorAll(${JSON.stringify(NOTE_TAGNAME)}).forEach(noteElement => attachNoteListeners(noteElement)); - }); + processNode(document); + reflowNotes(); + document.querySelectorAll(${JSON.stringify(NOTE_TAGNAME)}).forEach(noteElement => attachNoteListeners(noteElement)); })()`); }