Skip to content

Commit c3f4bb7

Browse files
committed
Update theme selection JS
1 parent c577c0d commit c3f4bb7

1 file changed

Lines changed: 37 additions & 25 deletions

File tree

_layouts/main.html

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
<div class="window-body">
4646
{% include nav.html %}
4747
<div style="margin-top: .5em;">
48-
<select>
49-
<option id="stylesheet1">XP Theme</option>
50-
<option id="stylesheet2">98 Theme</option>
51-
<option id="stylesheet3">7 Theme</option>
48+
<select id="theme-selector">
49+
<option id="xp-style" value="0">XP Theme</option>
50+
<option id="98-style" value="1">98 Theme</option>
51+
<option id="7-style" value="2">7 Theme</option>
5252
</select>
5353
</div>
5454
</div>
@@ -76,37 +76,49 @@
7676
</body>
7777

7878
<script>
79+
window.addEventListener('load', initialize, false);
80+
window.addEventListener('load', loadTheme, false);
81+
7982
function swapStyleSheet(sheet) {
8083
document.getElementById("pagestyle").setAttribute("href", sheet);
8184
}
8285

83-
function initate() {
84-
var style1 = document.getElementById("stylesheet1");
85-
var style2 = document.getElementById("stylesheet2");
86-
var style3 = document.getElementById("stylesheet3");
86+
function initialize() {
87+
let XPStyle = document.getElementById("xp-style");
88+
let ninetyEightStyle = document.getElementById("98-style");
89+
let sevenStyle = document.getElementById("7-style");
8790

88-
style1.onclick = function () {
91+
XPStyle.onclick = function () {
8992
swapStyleSheet("https://unpkg.com/xp.css");
90-
localStorage.setItem("theme", "https://unpkg.com/xp.css");
91-
};
92-
style2.onclick = function () {
93+
localStorage.setItem("theme", "XP");
94+
}
95+
ninetyEightStyle.onclick = function () {
9396
swapStyleSheet("https://unpkg.com/xp.css@0.2.3/dist/98.css");
94-
localStorage.setItem("theme", "https://unpkg.com/xp.css@0.2.3/dist/98.css");
95-
};
96-
style3.onclick = function () {
97+
localStorage.setItem("theme", "98");
98+
}
99+
sevenStyle.onclick = function () {
97100
swapStyleSheet("https://unpkg.com/7.css")
98-
localStorage.setItem("theme", "https://unpkg.com/7.css");
99-
};
101+
localStorage.setItem("theme", "7");
102+
}
100103
}
101104

102-
window.onload = function () {
103-
if (localStorage.getItem("theme") == "https://unpkg.com/xp.css") {
104-
swapStyleSheet("https://unpkg.com/xp.css");
105-
} else if (localStorage.getItem("theme") == "https://unpkg.com/xp.css@0.2.3/dist/98.css") {
106-
swapStyleSheet("https://unpkg.com/xp.css@0.2.3/dist/98.css");
107-
} else if (localStorage.getItem("theme") == "https://unpkg.com/7.css") {
108-
swapStyleSheet("https://unpkg.com/7.css");
105+
function loadTheme() {
106+
let currentTheme = localStorage.getItem("theme");
107+
let themeSelect = document.getElementById("theme-selector");
108+
109+
switch (currentTheme) {
110+
case "XP":
111+
swapStyleSheet("https://unpkg.com/xp.css");
112+
themeSelect.value = "0";
113+
break
114+
case "98":
115+
swapStyleSheet("https://unpkg.com/98.css");
116+
themeSelect.value = "1";
117+
break
118+
case "7":
119+
swapStyleSheet("https://unpkg.com/7.css");
120+
themeSelect.value = "2";
121+
break
109122
}
110-
initate();
111123
}
112124
</script>

0 commit comments

Comments
 (0)