Web/scripts/util.js
Ell 052ef46de5
All checks were successful
Web/pipeline/head This commit looks good
don't add unnecessary anchors if we force to the anchor anyway
2021-06-24 00:21:16 +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
}));
}