Web/main/scripts/util.js
Ell 6bde3c4ff8
Some checks failed
Web/pipeline/head There was a failure building this commit
silently convert the entire website to jekyll
2021-07-09 01:59:28 +02:00

30 lines
No EOL
832 B
JavaScript

function getCookie(key) {
let match = new RegExp(`${key}=([^;]+);?`, "g").exec(document.cookie);
return match ? match[1] : undefined;
}
function setCookie(key, value, days) {
let date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
document.cookie = `${key}=${value}; expires=${date.toUTCString()}; path=/`;
}
function forceToAnchor(customAnchor) {
let anchor = customAnchor || window.location.hash;
// this is probably a terrible hack
if (anchor.startsWith("#")) {
let element = $(anchor);
if (element.length) {
$('html, body').animate({
scrollTop: element.offset().top
}, 0);
}
}
}
function addStyle(path) {
$('head').append($("<link/>", {
rel: "stylesheet",
href: path
}));
}