function setCookie(name, value) {
	let end = new Date();
	end.setTime( end.getTime() + 3600 * 1000 );
	let str=name+"="+escape(value)+"; expires="+end.toGMTString()+"; path=/; Secure; SameSite=lax";
	document.cookie = str;
}
function getCookie(name) {
	let debut = document.cookie.indexOf(name);
	if( debut == -1 )	return null;
	let 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);
})();
