mirror of
https://github.com/tomfran/typo.git
synced 2025-04-25 21:19:55 +03:00
move inline JS to its own file
This commit is contained in:
parent
86e224dde6
commit
31ba2ee311
2 changed files with 30 additions and 34 deletions
|
@ -34,38 +34,6 @@
|
|||
|
||||
</body>
|
||||
|
||||
<script>
|
||||
|
||||
function isAuto() {
|
||||
return document.body.classList.contains("auto");
|
||||
}
|
||||
|
||||
function setTheme() {
|
||||
if (!isAuto()) {
|
||||
return
|
||||
}
|
||||
|
||||
document.body.classList.remove("auto");
|
||||
let cls = "light";
|
||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
cls = "dark";
|
||||
}
|
||||
|
||||
document.body.classList.add(cls);
|
||||
}
|
||||
|
||||
function invertBody() {
|
||||
document.body.classList.toggle("dark");
|
||||
document.body.classList.toggle("light");
|
||||
}
|
||||
|
||||
if (isAuto()) {
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addListener(invertBody);
|
||||
}
|
||||
|
||||
setTheme();
|
||||
|
||||
</script>
|
||||
|
||||
<script src="{{ "js/theme-switch.js" | relURL }}"></script>
|
||||
<script defer src="{{ "js/copy-code.js" | relURL }}"></script>
|
||||
</html>
|
||||
</html>
|
||||
|
|
28
static/js/theme-switch.js
Normal file
28
static/js/theme-switch.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
function isAuto() {
|
||||
return document.body.classList.contains("auto");
|
||||
}
|
||||
|
||||
function setTheme() {
|
||||
if (!isAuto()) {
|
||||
return
|
||||
}
|
||||
|
||||
document.body.classList.remove("auto");
|
||||
let cls = "light";
|
||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
cls = "dark";
|
||||
}
|
||||
|
||||
document.body.classList.add(cls);
|
||||
}
|
||||
|
||||
function invertBody() {
|
||||
document.body.classList.toggle("dark");
|
||||
document.body.classList.toggle("light");
|
||||
}
|
||||
|
||||
if (isAuto()) {
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addListener(invertBody);
|
||||
}
|
||||
|
||||
setTheme();
|
Loading…
Add table
Add a link
Reference in a new issue