39 lines
896 B
JavaScript
39 lines
896 B
JavaScript
|
|
||
|
const SYMBOL_LIGHT = "🌞";
|
||
|
const SYMBOL_DARK = "🌙";
|
||
|
|
||
|
const set_theme_cookie = (value) =>
|
||
|
{
|
||
|
const d = new Date();
|
||
|
d.setTime(d.getTime() + (365 * 24 * 60 * 60 * 1000));
|
||
|
const cookie_str = `theme=${value}; path=/; expires=${d.toUTCString()}; samesite=strict`;
|
||
|
document.cookie = cookie_str;
|
||
|
};
|
||
|
|
||
|
$(document).ready(() =>
|
||
|
{
|
||
|
let e_button = $("#theme-button");
|
||
|
let e_target = $("#theme-target");
|
||
|
|
||
|
let css_src = e_target.attr("href");
|
||
|
e_button.html(css_src == "/static/css/light.css" ? SYMBOL_LIGHT : SYMBOL_DARK);
|
||
|
|
||
|
e_button.on("click", () =>
|
||
|
{
|
||
|
let css_src = e_target.attr("href");
|
||
|
if (css_src == "/static/css/light.css")
|
||
|
{
|
||
|
e_target.attr("href", "/static/css/dark.css");
|
||
|
e_button.html(SYMBOL_DARK);
|
||
|
set_theme_cookie("dark");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
e_target.attr("href", "/static/css/light.css");
|
||
|
e_button.html(SYMBOL_LIGHT);
|
||
|
set_theme_cookie("light");
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
|