Loading last theme selected
This commit is contained in:
parent
4b933b7b0e
commit
68ebf556c4
|
@ -38,9 +38,22 @@
|
||||||
lock.name = 'darkreader-lock';
|
lock.name = 'darkreader-lock';
|
||||||
document.head.appendChild(lock);
|
document.head.appendChild(lock);
|
||||||
|
|
||||||
const randomNumber = Math.floor(Math.random() * 4);
|
let theme: string | null = null;
|
||||||
console.log("Slecting: " + themesArr[randomNumber]);
|
|
||||||
document.documentElement.setAttribute('data-theme', themesArr[randomNumber]);
|
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