8 lines
1.4 KiB
JavaScript
8 lines
1.4 KiB
JavaScript
'use strict';var getData=getData||function(id,clear=true){let data={};const element=document.getElementById(`${id}-data`);if(element){try{data=JSON.parse(element.textContent);if(clear){element.innerHTML='';}}catch(e){}}
|
|
return data;};var isObject=isObject||function isObject(item){return(item&&typeof item==='object'&&!Array.isArray(item));};var mergeDeep=mergeDeep||function mergeDeep(target,...sources){if(!sources.length)return target;const source=sources.shift();if(isObject(target)&&isObject(source)){for(const key in source){if(isObject(source[key])){if(!target[key])Object.assign(target,{[key]:{}});mergeDeep(target[key],source[key]);}else{Object.assign(target,{[key]:source[key]});}}}
|
|
return mergeDeep(target,...sources);};function getCookie(name){let matches=document.cookie.match(new RegExp("(?:^|; )"+name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,'\\$1')+"=([^;]*)"));return matches?decodeURIComponent(matches[1]):false;}
|
|
function setCookie(name,value,options={}){if(typeof options.expires==='number'){options.expires=new Date(Date.now()+options.expires*864e5);}
|
|
if(options.expires instanceof Date){options.expires=options.expires.toUTCString();}
|
|
let updatedCookie=encodeURIComponent(name)+"="+encodeURIComponent(value);for(let optionKey in options){updatedCookie+="; "+optionKey;let optionValue=options[optionKey];if(optionValue!==true){updatedCookie+="="+optionValue;}}
|
|
document.cookie=updatedCookie;}
|
|
function deleteCookie(name){setCookie(name,"",{'expires':-1});} |