Web/scripts/util.js
Ell 5de5fba62a
All checks were successful
Web/pipeline/head This commit looks good
added a featured category to the blog
2021-03-31 02:48:13 +02:00

29 lines
No EOL
790 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() {
// this is probably a terrible hack
if (window.location.hash.startsWith("#")) {
let anchor = $(window.location.hash);
if (anchor.length) {
$('html, body').animate({
scrollTop: anchor.offset().top
}, 0);
}
}
}
function addStyle(path) {
$('head').append($("<link/>", {
rel: "stylesheet",
href: path
}));
}