diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-08-18 01:49:17 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-08-18 01:49:17 +0200 |
| commit | edf0d64aa2c837b4bb28787483f98cb4815601c2 (patch) | |
| tree | f8d2984b46cc3a62dbae4498aaf5b214d8228b14 | |
| parent | 0e15d4461cc9b8e8baeeab2288ef8bbc2d30c3e6 (diff) | |
Wrap localStorage access in try/catch
| -rw-r--r-- | app/views/layouts/application.html.erb | 6 | ||||
| -rw-r--r-- | public/javascripts/public.js | 10 |
2 files changed, 10 insertions, 6 deletions
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4a71011b..756b4bdd 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb | |||
| @@ -22,8 +22,10 @@ | |||
| 22 | 22 | ||
| 23 | <%= javascript_tag nonce: true do %> | 23 | <%= javascript_tag nonce: true do %> |
| 24 | document.addEventListener("DOMContentLoaded", function() { | 24 | document.addEventListener("DOMContentLoaded", function() { |
| 25 | if (localStorage.getItem('override-prefers-color-scheme')) | 25 | try { |
| 26 | document.getElementById("light-mode").checked = true; | 26 | if (localStorage.getItem('override-prefers-color-scheme')) |
| 27 | document.getElementById("light-mode").checked = true; | ||
| 28 | } catch (e) {} | ||
| 27 | }); | 29 | }); |
| 28 | <% end %> | 30 | <% end %> |
| 29 | 31 | ||
diff --git a/public/javascripts/public.js b/public/javascripts/public.js index 7f38f66a..3943e1ce 100644 --- a/public/javascripts/public.js +++ b/public/javascripts/public.js | |||
| @@ -22,9 +22,11 @@ document.addEventListener('DOMContentLoaded', function(){ | |||
| 22 | }); | 22 | }); |
| 23 | 23 | ||
| 24 | document.getElementById("light-mode").addEventListener("change", () => { | 24 | document.getElementById("light-mode").addEventListener("change", () => { |
| 25 | if (document.getElementById("light-mode").checked) | 25 | try { |
| 26 | localStorage.setItem("override-prefers-color-scheme", 1); | 26 | if (document.getElementById("light-mode").checked) |
| 27 | else | 27 | localStorage.setItem("override-prefers-color-scheme", 1); |
| 28 | localStorage.removeItem("override-prefers-color-scheme"); | 28 | else |
| 29 | localStorage.removeItem("override-prefers-color-scheme"); | ||
| 30 | } catch (e) {} | ||
| 29 | }); | 31 | }); |
| 30 | }); | 32 | }); |
