Web/scripts/main.js
Ell ee5c7b64f0
All checks were successful
Web/pipeline/head This commit looks good
overhauled most of the script code
2021-03-19 07:55:18 +01:00

42 lines
No EOL
1.2 KiB
JavaScript

const dark = getCookie("dark") === "true";
const pride = new Date().getMonth() === 5;
const loc = $("script").last().attr("src").split("/")[0];
if (dark) {
document.write( /*html*/ `<link rel="stylesheet" href="${loc}/style/dark.css">`);
document.write( /*html*/ `<link rel="stylesheet" href="${loc}/style/prettify-dark.css">`);
}
if (pride)
document.write( /*html*/ `<link rel="stylesheet" href="${loc}/style/pride.css">`);
$(function () {
let openModals = function (hash) {
if (hash && hash.startsWith("#")) {
let modal = $(`${hash}-modal`);
if (modal.length)
modal.modal('show');
}
}
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();
});