Web/scripts/main.js

59 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-12-30 02:26:56 +01:00
let dark = getCookie("dark") === "true";
2018-12-30 16:38:14 +01:00
let cookieNotification = getCookie("notification") !== "true";
2019-06-01 22:26:20 +02:00
let pride = new Date().getMonth() == 5;
2018-12-30 16:38:14 +01:00
2019-10-03 15:15:25 +02:00
if (dark) {
2019-10-03 23:32:49 +02:00
document.write('<link rel="stylesheet" href="style/dark.css">')
document.write('<link rel="stylesheet" href="style/prettify-dark.css">')
2019-10-03 15:15:25 +02:00
}
2019-06-01 22:26:20 +02:00
if (pride)
2019-10-03 23:32:49 +02:00
document.write('<link rel="stylesheet" href="style/pride.css">')
2018-12-30 02:26:56 +01:00
2018-12-16 23:39:35 +01:00
$(function () {
let openModals = function (hash) {
2018-12-30 16:38:14 +01:00
if (hash && hash.length > 1) {
2018-07-28 11:22:20 +02:00
if (hash === '#impressum') {
$('#impressum-modal').modal('show');
2019-03-28 22:01:47 +01:00
} else if (hash === "#commissions") {
$('#commissions-modal').modal('show');
2018-07-28 11:22:20 +02:00
}
}
}
openModals(window.location.hash);
2018-12-16 23:39:35 +01:00
$('a').on('click', function () {
2018-07-28 11:22:20 +02:00
openModals($(this).attr('href'));
});;
2018-12-16 23:39:35 +01:00
$('.navbar-collapse a').on('click', function () {
2018-07-25 12:50:47 +02:00
$('.navbar-collapse').collapse('hide');
2018-07-24 22:45:53 +02:00
});
2018-12-16 23:39:35 +01:00
$('#blobheart').on('click', function () {
$('#navbar-image').attr('src', 'res/heart.png');
});
2018-12-30 02:26:56 +01:00
let mode = $('#dark-mode');
mode.prop('checked', dark);
mode.on('click', function () {
2018-12-30 16:38:14 +01:00
setCookie("dark", $(this).prop('checked'), 365);
window.location.hash = "";
2018-12-30 02:26:56 +01:00
location.reload();
});
2019-10-03 15:15:25 +02:00
PR.prettyPrint();
2018-12-30 02:26:56 +01:00
});
function getCookie(key) {
let c = document.cookie;
if (!c)
return undefined;
let start = c.indexOf(key + "=") + key.length + 1;
let end = c.indexOf(";", start);
return c.substring(start, end < 0 ? c.length : end);
2018-12-30 16:38:14 +01:00
}
function setCookie(key, value, days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
document.cookie = key + "=" + value + "; expires=" + date.toUTCString();
2018-12-30 02:26:56 +01:00
}