Web/main/scripts/main.js
Ell 11c00e85b3
All checks were successful
Jenkins
Ellpeck/Web/pipeline/head This commit looks good
switch to local storage
2023-06-13 17:29:52 +02:00

31 lines
929 B
JavaScript

const darkCookie = localStorage.getItem("dark");
const dark = darkCookie === null ? window.matchMedia("(prefers-color-scheme: dark)").matches : darkCookie === "true";
if (dark)
$('head').append($("<link/>", {
rel: "stylesheet",
href: "/style/dark.css"
}));
// redirect legacy anchors
if (/^#privacy\/?$/.test(location.hash))
location.href = "/privacy";
if (/^#impressum\/?$/.test(location.hash))
location.href = "/impressum";
$(function () {
$('.navbar-collapse a').on('click', function () {
$('.navbar-collapse').collapse('hide');
});
$('#blobheart').on('click', function () {
$('#navbar-image').attr('src', 'res/heart.jpeg');
});
let mode = $('#dark-mode');
mode.prop('checked', dark);
mode.on('click', function () {
localStorage.setItem("dark", $(this).prop('checked'));
location.hash = "";
location.reload();
});
});