gear_menu: Allow user to configure preferred theme.

We save the preferred theme in localstorage so that user doesn't
have to re-select the theme on every reload. Users on slow
computers might see flash of a theme change, if it happens.
This commit is contained in:
Aman Agrawal
2022-02-10 15:06:55 +00:00
committed by Tim Abbott
parent 8e7e8c7179
commit 9b622b7d25
8 changed files with 79 additions and 15 deletions

26
static/js/dark_theme.js Normal file
View File

@@ -0,0 +1,26 @@
import $ from "jquery";
import {localstorage} from "./localstorage";
import {page_params} from "./page_params";
export function enable() {
$("body").removeClass("color-scheme-automatic").addClass("dark-theme");
if (page_params.is_spectator) {
const ls = localstorage();
ls.set("spectator-theme-preference", "dark");
}
}
export function disable() {
$("body").removeClass("color-scheme-automatic").removeClass("dark-theme");
if (page_params.is_spectator) {
const ls = localstorage();
ls.set("spectator-theme-preference", "light");
}
}
export function default_preference_checker() {
$("body").removeClass("dark-theme").addClass("color-scheme-automatic");
}