PCv5/app/static/scripts/pc-utils.js

28 lines
872 B
JavaScript

function setCookie(name, value) {
var end = new Date();
end.setTime( end.getTime() + 3600 * 1000 );
var str=name+"="+escape(value)+"; expires="+end.toGMTString()+"; path=/; Secure; SameSite=lax";
document.cookie = str;
}
function getCookie(name) {
var debut = document.cookie.indexOf(name);
if( debut == -1 ) return null;
var end = document.cookie.indexOf( ";", debut+name.length+1 );
if( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( debut+name.length+1, end ) );
}
/* Automatically close context menus when clicking out of them */
function closeContextMenus(e) {
document.querySelectorAll('details[open]>.context-menu').forEach(menu => {
if(!menu.contains(event.target)) {
menu.parentElement.open = false;
e.preventDefault();
}
});
}
(function(){
window.addEventListener("click", closeContextMenus);
})();