faster theme load
This commit is contained in:
parent
68ebf556c4
commit
162158340b
17
src/app.html
17
src/app.html
|
@ -11,6 +11,23 @@
|
||||||
<link rel="stylesheet" href="/stylesheets/global.css" />
|
<link rel="stylesheet" href="/stylesheets/global.css" />
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
|
|
||||||
|
<script>
|
||||||
|
if (typeof localStorage !== 'undefined') {
|
||||||
|
theme = localStorage.getItem('theme');
|
||||||
|
}
|
||||||
|
const themesArr = ["green", "netherrack", "dark", "pink"];
|
||||||
|
|
||||||
|
if (!theme) {
|
||||||
|
const randomNumber = Math.floor(Math.random() * 4);
|
||||||
|
console.log("Slecting: " + themesArr[randomNumber]);
|
||||||
|
document.documentElement.setAttribute('data-theme', themesArr[randomNumber]);
|
||||||
|
localStorage.setItem('theme', themesArr[randomNumber]);
|
||||||
|
} else {
|
||||||
|
console.log("Slecting: " + theme);
|
||||||
|
document.documentElement.setAttribute('data-theme', theme);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body style="display: contents">
|
<body style="display: contents">
|
||||||
|
|
|
@ -31,29 +31,11 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
const themesArr = ["green", "netherrack", "dark", "pink"];
|
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const lock = document.createElement('meta');
|
const lock = document.createElement('meta');
|
||||||
lock.name = 'darkreader-lock';
|
lock.name = 'darkreader-lock';
|
||||||
document.head.appendChild(lock);
|
document.head.appendChild(lock);
|
||||||
|
|
||||||
let theme: string | null = null;
|
|
||||||
|
|
||||||
if (typeof localStorage !== 'undefined') {
|
|
||||||
theme = localStorage.getItem('theme');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!theme) {
|
|
||||||
const randomNumber = Math.floor(Math.random() * 4);
|
|
||||||
console.log("Slecting: " + themesArr[randomNumber]);
|
|
||||||
document.documentElement.setAttribute('data-theme', themesArr[randomNumber]);
|
|
||||||
localStorage.setItem('theme', themesArr[randomNumber]);
|
|
||||||
} else {
|
|
||||||
console.log("Slecting: " + theme);
|
|
||||||
document.documentElement.setAttribute('data-theme', theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue