mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-08-14.git
synced 2024-08-15 00:53:20 +00:00
fix: null ptr while loading/switching theme
This commit is contained in:
parent
0453d08eed
commit
73a142fd9b
1 changed files with 14 additions and 7 deletions
|
@ -11,7 +11,9 @@ toggle_theme.addEventListener('click', function () {
|
||||||
xhr.open('GET', url, true);
|
xhr.open('GET', url, true);
|
||||||
|
|
||||||
set_mode(dark_mode);
|
set_mode(dark_mode);
|
||||||
|
try {
|
||||||
window.localStorage.setItem('dark_mode', dark_mode ? 'dark' : 'light');
|
window.localStorage.setItem('dark_mode', dark_mode ? 'dark' : 'light');
|
||||||
|
} catch {}
|
||||||
|
|
||||||
xhr.send();
|
xhr.send();
|
||||||
});
|
});
|
||||||
|
@ -23,9 +25,12 @@ window.addEventListener('storage', function (e) {
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', function () {
|
window.addEventListener('DOMContentLoaded', function () {
|
||||||
window.localStorage.setItem('dark_mode', document.getElementById('dark_mode_pref').textContent);
|
const dark_mode = document.getElementById('dark_mode_pref').textContent;
|
||||||
|
try {
|
||||||
// Update localStorage if dark mode preference changed on preferences page
|
// Update localStorage if dark mode preference changed on preferences page
|
||||||
update_mode(window.localStorage.dark_mode);
|
window.localStorage.setItem('dark_mode', dark_mode);
|
||||||
|
} catch {}
|
||||||
|
update_mode(dark_mode);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,9 +42,11 @@ lightScheme.addListener(scheme_switch);
|
||||||
|
|
||||||
function scheme_switch (e) {
|
function scheme_switch (e) {
|
||||||
// ignore this method if we have a preference set
|
// ignore this method if we have a preference set
|
||||||
|
try {
|
||||||
if (localStorage.getItem('dark_mode')) {
|
if (localStorage.getItem('dark_mode')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} catch {}
|
||||||
if (e.matches) {
|
if (e.matches) {
|
||||||
if (e.media.includes("dark")) {
|
if (e.media.includes("dark")) {
|
||||||
set_mode(true);
|
set_mode(true);
|
||||||
|
|
Loading…
Reference in a new issue