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); })();