From c597bb5d5b6d08c8839750444f6d7f0f9953cb5e Mon Sep 17 00:00:00 2001 From: Sulthan Zaki Date: Fri, 24 Jul 2026 18:46:10 +0700 Subject: [PATCH] fix(userscript): move boot after TEMPLATE/CSS consts to avoid TDZ crash init() ran at line 514 (document.body exists at @run-at document-idle), but buildUI() reads the TEMPLATE/CSS consts declared lower in the IIFE. Accessing them before initialization threw ReferenceError: Cannot access 'CSS' before initialization, so the script died before mounting the FAB and no UI appeared in Cromite. Move the boot invocation to the end of the IIFE, after both consts are initialized. Co-Authored-By: Claude Opus 4.8 --- userscript/manga-bookmark.user.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/userscript/manga-bookmark.user.js b/userscript/manga-bookmark.user.js index fc46fec..7255d1c 100644 --- a/userscript/manga-bookmark.user.js +++ b/userscript/manga-bookmark.user.js @@ -511,9 +511,6 @@ refresh().then(() => maybeAutoUpdate()); // sync, then auto-record this page } - if (document.body) init(); - else document.addEventListener("DOMContentLoaded", init); - // ============================================================ // Markup + styles (kept at bottom for readability) // ============================================================ @@ -598,4 +595,13 @@ .toast.show { opacity: 1; transform: translateY(0); } .toast.err { background: #7f1d1d; } `; + + // ============================================================ + // Boot — MUST run last: init() -> buildUI() reads TEMPLATE/CSS, + // which are const (TDZ) and only initialized above. At + // @run-at document-idle document.body already exists, so init() + // fires synchronously here, after the consts are set. + // ============================================================ + if (document.body) init(); + else document.addEventListener("DOMContentLoaded", init); })();