diff --git a/static/sort_filter.ts b/static/sort_filter.ts index 0183a0c..03f777d 100644 --- a/static/sort_filter.ts +++ b/static/sort_filter.ts @@ -1,3 +1,5 @@ +import { onReady } from "./utils"; + const initSortFilter = (): void => { const sortSelect = document.getElementById("sort-select") as HTMLSelectElement | null; const orderSelect = document.getElementById("order-select") as HTMLSelectElement | null; @@ -21,4 +23,4 @@ const initSortFilter = (): void => { }); }; -document.addEventListener("DOMContentLoaded", initSortFilter); +onReady(initSortFilter); diff --git a/static/theme.ts b/static/theme.ts index 104937c..e654f74 100644 --- a/static/theme.ts +++ b/static/theme.ts @@ -1,3 +1,5 @@ +import { onReady } from "./utils"; + type Theme = "light" | "dark"; const colorSchemeQuery = window.matchMedia?.("(prefers-color-scheme: dark)") ?? null; @@ -17,8 +19,4 @@ const initTheme = (): void => { colorSchemeQuery?.addEventListener("change", () => applyTheme(getPreferredTheme())); }; -if (document.readyState === "loading") { - document.addEventListener("DOMContentLoaded", initTheme); -} else { - initTheme(); -} +onReady(initTheme);