30 lines
No EOL
825 B
JavaScript
30 lines
No EOL
825 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 || 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
|
|
}));
|
|
} |