15 lines
871 B
JavaScript
15 lines
871 B
JavaScript
// This document exists only under the private cookie path.
|
|
addEventListener("message", event => {
|
|
if (event.origin !== location.origin || event.source !== parent || !event.ports[0]) return;
|
|
const name="vzlet_demo_v1", next=event.data, port=event.ports[0];
|
|
try {
|
|
if(next!==null){
|
|
if(typeof next!=="string" || !/^[a-zA-Z0-9_=-]{1,3500}$/.test(next)) throw Error("Некорректная позиция");
|
|
document.cookie=name+"="+next+"; Path="+location.pathname+"; SameSite=Strict; Max-Age=2592000"+(location.protocol==="https:"?"; Secure":"");
|
|
}
|
|
const value=document.cookie.split("; ").find(item=>item.startsWith(name+"="))?.slice(name.length+1)||"";
|
|
if(next!==null && value!==next)throw Error("Браузер заблокировал cookie");
|
|
port.postMessage({value});
|
|
} catch(err){port.postMessage({error:err.message});}
|
|
});
|