Web/scripts/main.js

40 lines
998 B
JavaScript

const dark = getCookie("dark") === "true";
const loc = $("script").last().attr("src").split("/")[0];
if (dark) {
addStyle(`${loc}/style/dark.css`);
addStyle(`${loc}/style/prettify-dark.css`);
}
$(function () {
openModals(window.location.hash);
$('a').on('click', function () {
openModals($(this).attr('href'));
});
$('.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 () {
setCookie("dark", $(this).prop('checked'), 365);
window.location.hash = "";
location.reload();
});
PR.prettyPrint();
});
function openModals(hash) {
if (hash && hash.startsWith("#")) {
let modal = $(`${hash}-modal`);
if (modal.length)
modal.modal('show');
}
}