Web/scripts/util.js

33 lines
890 B
JavaScript
Raw Normal View History

2020-04-02 22:14:53 +02:00
function getCookie(key) {
let c = document.cookie;
if (!c)
return undefined;
2021-03-19 07:55:18 +01:00
let start = c.indexOf(`${key}=`) + key.length + 1;
2020-04-02 22:14:53 +02:00
let end = c.indexOf(";", start);
return c.substring(start, end < 0 ? c.length : end);
}
2020-04-02 22:14:53 +02:00
function setCookie(key, value, days) {
2021-03-19 07:55:18 +01:00
let date = new Date();
2020-04-02 22:14:53 +02:00
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
2021-03-19 07:59:36 +01:00
document.cookie = `${key}=${value}; expires=${date.toUTCString()}; path=/`;
}
function forceToAnchor() {
// this is probably a terrible hack
if (window.location.hash.startsWith("#")) {
2021-03-19 07:55:18 +01:00
let anchor = $(window.location.hash);
if (anchor.length) {
$('html, body').animate({
scrollTop: anchor.offset().top
}, 0);
}
}
2021-03-19 11:42:35 +01:00
}
function addStyle(path) {
$('head').append($("<link/>", {
rel: "stylesheet",
href: path
}));
}