Fix theme saving

This commit is contained in:
Someone-dQw4w9WgXcQ 2023-07-27 22:04:10 +01:00
parent e3ec320949
commit e101e90054
2 changed files with 8 additions and 8 deletions

View file

@ -43,16 +43,16 @@
<link rel="stylesheet alternate" href="{{ '/assets/css/theme2.css' | relative_url }}" id="theme_source_2"> <link rel="stylesheet alternate" href="{{ '/assets/css/theme2.css' | relative_url }}" id="theme_source_2">
<script> <script>
let theme = sessionStorage.getItem('theme'); let theme = localStorage.getItem('theme');
if (theme === "dark") { if (theme === "dark") {
sessionStorage.setItem('theme', 'dark'); localStorage.setItem('theme', 'dark');
node1 = document.getElementById('theme_source'); node1 = document.getElementById('theme_source');
node2 = document.getElementById('theme_source_2'); node2 = document.getElementById('theme_source_2');
node1.setAttribute('rel', 'stylesheet alternate'); node1.setAttribute('rel', 'stylesheet alternate');
node2.setAttribute('rel', 'stylesheet'); node2.setAttribute('rel', 'stylesheet');
} }
else { else {
sessionStorage.setItem('theme', 'light'); localStorage.setItem('theme', 'light');
} }
function toggleTheme() { function toggleTheme() {
@ -61,13 +61,13 @@
if (node1.getAttribute("rel") == "stylesheet") { if (node1.getAttribute("rel") == "stylesheet") {
node1.setAttribute("rel", "stylesheet alternate"); node1.setAttribute("rel", "stylesheet alternate");
node2.setAttribute("rel", "stylesheet"); node2.setAttribute("rel", "stylesheet");
editor.setOption("theme", "dark"); try {editor?.setOption("theme", "dark")} catch {};
sessionStorage.setItem("theme", "dark"); localStorage.setItem("theme", "dark");
} else { } else {
node2.setAttribute("rel", "stylesheet alternate"); node2.setAttribute("rel", "stylesheet alternate");
node1.setAttribute("rel", "stylesheet"); node1.setAttribute("rel", "stylesheet");
editor.setOption("theme", "light"); try {editor.setOption("theme", "light")} catch {};
sessionStorage.setItem("theme", "light"); localStorage.setItem("theme", "light");
} }
return false; return false;
} }

View file

@ -89,7 +89,7 @@
<!-- CodeMirror Luau Editor (MUST BE LOADED AFTER CODEMIRROR!) --> <!-- CodeMirror Luau Editor (MUST BE LOADED AFTER CODEMIRROR!) -->
<script> <script>
var editor = CodeMirror.fromTextArea(document.getElementById("script"), { var editor = CodeMirror.fromTextArea(document.getElementById("script"), {
theme: sessionStorage.getItem('theme'), theme: localStorage.getItem('theme'),
mode: "luau", mode: "luau",
matchBrackets: true, matchBrackets: true,
lineNumbers: true, lineNumbers: true,