diff --git a/moonbit-tour/src/main.ts b/moonbit-tour/src/main.ts index 0a76d67a..ab0f8efb 100644 --- a/moonbit-tour/src/main.ts +++ b/moonbit-tour/src/main.ts @@ -29,23 +29,32 @@ const moonSvg = `("#theme")!; +setTheme(theme); -function toggleTheme() { +function setTheme(theme: Theme) { if (theme === "light") { - theme = "dark"; - document.querySelector("html")?.classList.add("dark"); - monaco.editor.setTheme("dark-plus"); - themeButton.innerHTML = moonSvg; - } else { - theme = "light"; document.querySelector("html")?.classList.remove("dark"); monaco.editor.setTheme("light-plus"); themeButton.innerHTML = sunSvg; + } else { + document.querySelector("html")?.classList.add("dark"); + monaco.editor.setTheme("dark-plus"); + themeButton.innerHTML = moonSvg; } + localStorage.setItem("theme", theme); +} + +function toggleTheme() { + theme = theme === "light" ? "dark" : "light"; + setTheme(theme); } themeButton.addEventListener("click", toggleTheme); @@ -116,7 +125,6 @@ monaco.editor.create(editor, { alwaysConsumeMouseWheel: false, }, fontFamily: "monospace", - theme: "light-plus", }); run();