diff options
| author | Samantaz Fox <coding@samantaz.fr> | 2022-04-27 18:32:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-27 18:32:40 +0200 |
| commit | 3bbd709bd6ef812d8c4458c192e166c53b76ab1d (patch) | |
| tree | 6d81622d1d091ae37e13b5de38a319f956f88d61 /assets/js/themes.js | |
| parent | a0f566fef34ec3ee2a1badc7ac6e78099ad24892 (diff) | |
| parent | dbb1e3f5d8aae3d732bbf3ccf82baec0739d9445 (diff) | |
| download | invidious-3bbd709bd6ef812d8c4458c192e166c53b76ab1d.tar.gz invidious-3bbd709bd6ef812d8c4458c192e166c53b76ab1d.tar.bz2 invidious-3bbd709bd6ef812d8c4458c192e166c53b76ab1d.zip | |
Merge pull request #3045 from AHOHNMYC/js-lint
Js lint
Diffstat (limited to 'assets/js/themes.js')
| -rw-r--r-- | assets/js/themes.js | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/assets/js/themes.js b/assets/js/themes.js index 0214a7f0..3f503b38 100644 --- a/assets/js/themes.js +++ b/assets/js/themes.js @@ -1,8 +1,9 @@ +'use strict'; var toggle_theme = document.getElementById('toggle_theme'); toggle_theme.href = 'javascript:void(0);'; toggle_theme.addEventListener('click', function () { - var dark_mode = document.body.classList.contains("light-theme"); + var dark_mode = document.body.classList.contains('light-theme'); var url = '/toggle_theme?redirect=false'; var xhr = new XMLHttpRequest(); @@ -13,7 +14,7 @@ toggle_theme.addEventListener('click', function () { set_mode(dark_mode); try { window.localStorage.setItem('dark_mode', dark_mode ? 'dark' : 'light'); - } catch {} + } catch (e) {} xhr.send(); }); @@ -29,7 +30,7 @@ window.addEventListener('DOMContentLoaded', function () { try { // Update localStorage if dark mode preference changed on preferences page window.localStorage.setItem('dark_mode', dark_mode); - } catch {} + } catch (e) {} update_mode(dark_mode); }); @@ -46,11 +47,11 @@ function scheme_switch (e) { if (localStorage.getItem('dark_mode')) { return; } - } catch {} + } catch (exception) {} if (e.matches) { - if (e.media.includes("dark")) { + if (e.media.includes('dark')) { set_mode(true); - } else if (e.media.includes("light")) { + } else if (e.media.includes('light')) { set_mode(false); } } @@ -77,15 +78,13 @@ function update_mode (mode) { // If preference for dark mode indicated set_mode(true); } - else if (mode === 'false' /* for backwards compatibility */ || mode === 'light') { - // If preference for light mode indicated - set_mode(false); - } + else if (mode === 'false' /* for backwards compatibility */ || mode === 'light') { + // If preference for light mode indicated + set_mode(false); + } else if (document.getElementById('dark_mode_pref').textContent === '' && window.matchMedia('(prefers-color-scheme: dark)').matches) { // If no preference indicated here and no preference indicated on the preferences page (backend), but the browser tells us that the operating system has a dark theme set_mode(true); } // else do nothing, falling back to the mode defined by the `dark_mode` preference on the preferences page (backend) } - - |
