summaryrefslogtreecommitdiffstats
path: root/assets/js/themes.js
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2022-01-05 03:23:22 +0100
committerGitHub <noreply@github.com>2022-01-05 03:23:22 +0100
commitedcc1554827aa3d0f22c39765ec03d5b5cd01421 (patch)
tree048e2910bde8319a262fb4e1aea208500b6836c1 /assets/js/themes.js
parent823121637146c4b5b13ab4f4326cb73ff16828d6 (diff)
parent73a142fd9b778162c129af2da1c6bdbe9b8ed69b (diff)
downloadinvidious-edcc1554827aa3d0f22c39765ec03d5b5cd01421.tar.gz
invidious-edcc1554827aa3d0f22c39765ec03d5b5cd01421.tar.bz2
invidious-edcc1554827aa3d0f22c39765ec03d5b5cd01421.zip
Merge pull request #2744 from tirz/feature-fix_null_ptr_for_localStorage
fix: null ptr while retaining video time
Diffstat (limited to 'assets/js/themes.js')
-rw-r--r--assets/js/themes.js21
1 files changed, 14 insertions, 7 deletions
diff --git a/assets/js/themes.js b/assets/js/themes.js
index 543b849e..470f10bf 100644
--- a/assets/js/themes.js
+++ b/assets/js/themes.js
@@ -11,7 +11,9 @@ toggle_theme.addEventListener('click', function () {
xhr.open('GET', url, true);
set_mode(dark_mode);
- window.localStorage.setItem('dark_mode', dark_mode ? 'dark' : 'light');
+ try {
+ window.localStorage.setItem('dark_mode', dark_mode ? 'dark' : 'light');
+ } catch {}
xhr.send();
});
@@ -23,9 +25,12 @@ window.addEventListener('storage', function (e) {
});
window.addEventListener('DOMContentLoaded', function () {
- window.localStorage.setItem('dark_mode', document.getElementById('dark_mode_pref').textContent);
- // Update localStorage if dark mode preference changed on preferences page
- update_mode(window.localStorage.dark_mode);
+ const dark_mode = document.getElementById('dark_mode_pref').textContent;
+ try {
+ // Update localStorage if dark mode preference changed on preferences page
+ window.localStorage.setItem('dark_mode', dark_mode);
+ } catch {}
+ update_mode(dark_mode);
});
@@ -37,9 +42,11 @@ lightScheme.addListener(scheme_switch);
function scheme_switch (e) {
// ignore this method if we have a preference set
- if (localStorage.getItem('dark_mode')) {
- return;
- }
+ try {
+ if (localStorage.getItem('dark_mode')) {
+ return;
+ }
+ } catch {}
if (e.matches) {
if (e.media.includes("dark")) {
set_mode(true);