The JS frontend now reads from the preference stored in the Crystal
backend to update the localStorage on page load, and checks the
preference stored in the backend when updating the mode. This should
fix the issues noted in PR #601 regarding the frontend and backend
prefs not being synchronized properly.
Changed the default value for the preference `dark-mode` from
"light" to "", to reflect the fact that `dark-mode` is tri-state
and that the default (no preference set) may be the dark theme
(depending on `prefers-color-scheme`).
This should fix <https://github.com/omarroth/invidious/issues/559>.
The cookie storage format has been changed from boolean
("true"/"false") to tri-state ("dark"/"light"/""), so that users
without a cookie set will get dark mode if they have enabled the dark
theme in their operating system. The code for handling the cookie
state, along with the user's operating system theme, has been factored
out into a new function `update_mode`, which is called both at window
load and at the "storage" event listener, because the "storage" event
listener is only trigerred when a change is made to the localStorage
from another tab/window (for more info - see
<https://stackoverflow.com/a/4679754>).