mirror of
https://github.com/ThePhaseless/Byparr.git
synced 2025-03-16 10:10:20 +08:00
450 lines
77 KiB
JavaScript
450 lines
77 KiB
JavaScript
![]() |
/*******************************************************************************
|
||
|
|
||
|
uBlock Origin Lite - a comprehensive, MV3-compliant content blocker
|
||
|
Copyright (C) 2014-present Raymond Hill
|
||
|
|
||
|
This program is free software: you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation, either version 3 of the License, or
|
||
|
(at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||
|
|
||
|
Home: https://github.com/gorhill/uBlock
|
||
|
|
||
|
*/
|
||
|
|
||
|
/* jshint esversion:11 */
|
||
|
/* global cloneInto */
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
// ruleset: annoyances-cookies
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
// Important!
|
||
|
// Isolate from global scope
|
||
|
|
||
|
// Start of local scope
|
||
|
(( ) => {
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
// Start of code to inject
|
||
|
const uBOL_trustedSetCookie = function() {
|
||
|
|
||
|
const scriptletGlobals = {}; // jshint ignore: line
|
||
|
|
||
|
const argsList = [["datr","__GMZCgwVF5BbyvAtfJojQwg","1year","","reload","1"],["ig_did","0C826C21-17C3-444A-ABB7-EBABD37214D7","1year","","reload","1"],["euconsent-v2","CPt3fQAPt3fQACNAFAENDLCgAAAAAAAAACiQAAAOCgDAB-AIsAZ8A6QDBAHBAAAA.YAAAAAAAAAAA","1year"],["tracking-opt-in-status","rejected","1year"],["addtl_consent","1~","1year"],["dm-euconsent-v2","CPt6yMAPt6yMABpAGAENDECgAAAAAH_AAAqIAAAS3AJMNW4gC7MocGbQMIoEQIwrCQigUAEFAMLRAQAODgp2VgE-sIkAKAUARgRAhwBRkQCAAASAJCIAJAiwQAAAiAQAAgAQCIQAMDAIKACwEAgABAdAxRCgAECQgSIiIhTAgKgSCAlsqEEoLpDTCAKssAKARGwUACIJARWAAICwcAwRICViwQJMQbRAAMAKAUSoVqKT00BCxmQAAAAA","1year"],["fig_save_consent","iTTPgpSWqAGGcd3vV88zNDbHsABxE1hB","1year"],["euconsent-v2","CPubvkAPubvkAAHABBENDMCgAAAAAAAAAB5YAAAAAAAA.YAAAAAAAAAAA","1year"],["OptanonConsent","groups=C0001%3A1%2CC0002%3A0%2CC0008%3A0","1year"],["_scw_rgpd_hash","408362395"],["PUR_SUBSCRIPTION","PREMIUM"],["CookieConsent","{necessary:true%2Cpreferences:false%2Cstatistics:false%2Cmarketing:false}","1year"],["cb","1_1970_01_01_2-3","1year","","reload","1"],["datr","mWTaZBxAoW8lFl0v3EpECGYi","1year","","reload","1"],["COOKIES_CONSENT","essential"],["myscript","{%22acceptance%22:true%2C%22analytics%22:false}"],["tm_cookie_setting","Analytics","","","reload","1"],["BCP","AD=0&AL=0&SM=0"],["cookies","{\"system\":1,\"target\":0}"],["CookieControl","{\"interactedWith\":true,\"acceptedCategories\":[\"essentials\"]}"],["cookie_preference","functional"],["trackingPermissionConsentsValue","%7B%22cookies_analytics%22%3Afalse%2C%22cookies_personalization%22%3Afalse%2C%22cookies_advertisement%22%3Afalse%7D"],["euconsent-v2","CPzEX8APzEX8ADtACBESAUEgAAAAAAAAAAiQAAAAAAAA"],["euconsent-v2-addtl","%20"],["pfUserCookPolicy","12562660:1"],["viucom-cookie-accept","[\"technical_necessary\"]"],["BN.User.CookieConsent","CAE%3D"],["CookieConsent","{stamp:%27BvqlZ34xqOpzSOaxY1VgwOy5CZ1lfC4Xs2JNiDqz9M4rNuyyAY56Jg==%27%2Cnecessary:true%2Cpreferences:false%2Cstatistics:false%2Cmarketing:false%2Cmethod:%27explicit%27%2Cver:1%2Cutc:1697932000537}","1year"],["CookieConsent","{stamp:%27Uv9YOAVP5djCBw71lxhE4rNAfTObaGck2Sn3rKWf9dPCYpqcWvAlpA==%27%2Cnecessary:true%2Cpreferences:false%2Cstatistics:false%2Cmarketing:false%2Cmethod:%27explicit%27%2Cver:2}","1year"],["CookieConsent","{stamp:%27Uv9YOAVP5djCBw71lxhE4rNAfTObaGck2Sn3rKWf9dPCYpqcWvAlpA==%27%2Cnecessary:true%2Cpreferences:false%2Cstatistics:false%2Cmarketing:false%2Cmethod:%27explicit%27%2Cver:3}","1year"],["CookieConsent","{stamp:%27fbbiPQWa8SRQm47Ge8hRVOAPAgw2jXlG8o/+hp1euVVi1qtFQj1O3w==%27%2Cnecessary:true%2Cpreferences:true%2Cstatistics:true%2Cmarketing:true%2Cmethod:%27explicit%27%2Cver:4}","1year"],["CookieConsent","{stamp:%27Uv9YOAVP5djCBw71lxhE4rNAfTObaGck2Sn3rKWf9dPCYpqcWvAlpA==%27%2Cnecessary:true%2Cpreferences:false%2Cstatistics:false%2Cmarketing:false%2Cmethod:%27explicit%27%2Cver:5}","1year"],["CookieConsent","{stamp:%27Uv9YOAVP5djCBw71lxhE4rNAfTObaGck2Sn3rKWf9dPCYpqcWvAlpA==%27%2Cnecessary:true%2Cpreferences:false%2Cstatistics:false%2Cmarketing:false%2Cmethod:%27explicit%27%2Cver:6}","1year"],["SK.Website.ConsentManager","W1siYmFzZSIsdHJ1ZV0sWyJnb29nbGVhbmFseXRpY3MiLGZhbHNlXSxbIm1ldGFwaXhlbCIsZmFsc2VdXQ=="],["consent","%7B%22level%22%3A%5B%22necessary%22%5D%2C%22revision%22%3A0%2C%22data%22%3A%7B%22id%22%3A%22DarYF7gx7v%22%7D%2C%22rfc_cookie%22%3Atrue%7D"],["CookieConsents","{\"StrictlyNecessary\":true,\"Analytical\":false,\"Performance\":false,\"AdvertisingAndTargeting\":false,\"timestamp\":\"\"}"],["cookie-consent-1","{\"optedIn\":true,\"functionality\":false,\"statistics\":false}"],["kmt_rd","no-consent","","","reload","1"],["cr_consent","2|tracking=false+analytics=false+marketing=false","","","reload","1"],["hbl_cookie_prefs_v1","[%22Essential%22]"],["mmc-cookie-consent","{\"Id\":\"c2457eddbecc20cbab3869374900e864\",\"CategoryID\":4}","1year"],["fixami.app_state","eyJzdGF0ZSI6eyJpc1RheEluY2x1ZGVkIjp0cnVlLCJpc0ZpcnN0VmlzaXQiOnRydWUsImlzQ3VzdG9tZXJTZXJ2aWNlTW9kYWxPcGVuIjpmYWxzZSwiYWNjZXB0ZWRDb29raWVzIjoiMCIsImhhc0FjY2VwdGVkQ29va2llcyI6dHJ1ZSwiaGFzQWNjZXB0ZWRNYXJrZXRpbmdDb29raWVzIjp0cnVlLCJoYXNBY2NlcHRlZFN0YX
|
||
|
|
||
|
const hostnamesMap = new Map([["facebook.com",0],["instagram.com",1],["fandom.com",[2,3,4]],["dailymotion.com",5],["lefigaro.fr",6],["filmweb.pl",7],["thetrainline.com",[8,55]],["scaleway.com",9],["all3dp.com",10],["threads.net",12],["messenger.com",13],["trading212.com",14],["myscript.com",15],["odido.nl",16],["bing.com",17],["procvetok.ua",18],["stwater.co.uk",19],["boogschietshop.nl",20],["hashop.nl",20],["x-kom.pl",21],["tiempo.com",[22,23]],["pizzafan.gr",24],["windhager.eu",25],["banknorwegian.no",26],["biomarkt.de",27],["plaion.com",27],["apetro.pt",28],["apoteket.se",28],["bergbauernmilch.de",28],["berlingske.dk",28],["cineplex.de",28],["danbolig.dk",28],["egmont.com",28],["euroatla.pt",28],["finanzmarktwelt.de",28],["harzwasserwerke.de",28],["hoyavision.com",28],["nos.pt",28],["neue.at",28],["nngroup.com",28],["nordiskfilm.com",28],["storyhouseegmont.dk",28],["storyhouseegmont.no",28],["storyhouseegmont.se",28],["toyota-forklifts.se",28],["vn.at",28],["werder.de",28],["werkenbijlidl.nl",28],["wwf.fi",28],["refinery29.com",29],["dasinvestment.com",29],["fof.se",29],["mein-grundeinkommen.de",29],["ekstrabladet.dk",30],["kino.dk",31],["dr.dk",32],["schauspiel.koeln",33],["onlinestempel.ch",34],["chase.co.uk",35],["svt.se",36],["komoot.com",37],["komoot.de",37],["chatreplay.stream",38],["hubblehq.com",39],["hwebber.co.uk",40],["gereedschapcentrum.nl",41],["ontinet.com",42],["fplstatistics.co.uk",43],["kirjasto.vaasa.fi",44],["softonic.com",45],["informatech.com",46],["aonsolutions.es",47],["launer.com",48],["bever.nl",49],["sixt-neuwagen.de",50],["oem.no",51],["forums.tomsguide.com",52],["tomsguide.com",53],["walmart.ca",54],["cc.com",55],["1001games.com",[55,166,167]],["1001hry.cz",[55,166,167]],["1001jeux.fr",[55,166,167]],["1001jocuri.ro",[55,166,167]],["1001jogos.com.br",[55,166,167]],["1001jogos.pt",[55,166,167]],["1001pelit.com",[55,166,167]],["1001spiele.de",[55,166,167]],["elkspel.nl",[55,166,167]],["gamespot.com",[55,94]],["giochixl.it",[55,166,167]],["glamour.com",[55,185]],["grajteraz.pl",[55,166,167]],["isladejuegos.com",[55,166,167]],["jatekokxl.hu",[55,166,167]],["mtvuutiset.fi",[55,92]],["paixnidiaxl.gr",[55,166,167]],["pushsquare.com",[55,122,123]],["spelo.se",[55,166,167]],["spillespill.no",[55,166,167]],["spilxl.dk",[55,166,167]],["thejournal.ie",[55,109]],["vkmag.com",[55,90,91]],["zdnet.com",[55,102]],["zoom.us",[55,192,193]],["mesta.net",[55,196]],["tredz.co.uk",[55,207]],["uphold.com",[55,217,218]],["webuyanycar.com",55],["resursbank.fi",56],["ft.com",57],["what3words.com",58],["aufstiegs-bafoeg.de",59],["bafa.de",59],["ble.de",59],["bmbf.de",59],["bne-portal.de",59],["bundespolizei.de",59],["schleswig-holstein.de",59],["verfassungsschutz.de",59],["delfi.ee",[60,61,62]],["flynorse.com",63],["fruugonorge.com",64],["fruugo.de",64],["hyperoptic.com",65],["education.lego.com",66],["lego.com",[67,68]],["planningportal.co.uk",69],["veriff.com",70],["programme.conventus.de",71],["arena.pl",72],["govirtuo.com",[73,74]],["deal.by",75],["zwenkwielen.net",76],["lastmile.lt",77],["biomedcentral.com",78],["bol.com",79],["fotografiska.com",80],["osmanlicakelam.net",81],["mic.eucast.org",82],["open.online",[83,84]],["ilovefreegle.org",[85,86]],["evaair.com",[88,89]],["ampparit.com",93],["arvopaperi.fi",93],["iltalehti.fi",93],["kauppalehti.fi",93],["mediuutiset.fi",93],["mikrobitti.fi",93],["talouselama.fi",93],["tekniikkatalous.fi",93],["tivi.fi",93],["uusisuomi.fi",93],["asialadies.de",95],["avladies.de",95],["badeladies.de",95],["behaarteladies.de",95],["bizarrladies.de",95],["busenladies.de",95],["deutscheladies.de",95],["devoteladies.de",95],["dominanteladies.de",95],["erfahreneladies.de",95],["escorts24.de",95],["exklusivladies.de",95],["fkk24.de",95],["grosseladies.de",95],["hobbyladies.de",95],["jungeladies.de",95],["kollegin.de",95],["kussladies.de",95],["ladies.de",95],["latinaladies.de",95],["massierendeladies.de",95],["mollyladies.de",95],["nsladies.de",95],["nymphomaneladies.de",95],["orientladies.de",95],["osteuropaladies.de",95],["piercingladies.de",95],["rasierteladies.de",95],["schokoladies.
|
||
|
|
||
|
const entitiesMap = new Map([["lidl",11],["www.google",87],["just-eat",[115,116,117]],["lieferando",[115,116,117]],["coolstuff",182],["wolfswinkel",233],["esprit",244]]);
|
||
|
|
||
|
const exceptionsMap = new Map([]);
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
function trustedSetCookie(
|
||
|
name = '',
|
||
|
value = '',
|
||
|
offsetExpiresSec = '',
|
||
|
path = ''
|
||
|
) {
|
||
|
if ( name === '' ) { return; }
|
||
|
|
||
|
const safe = safeSelf();
|
||
|
const logPrefix = safe.makeLogPrefix('set-cookie', name, value, path);
|
||
|
const time = new Date();
|
||
|
|
||
|
if ( value.includes('$now$') ) {
|
||
|
value = value.replaceAll('$now$', time.getTime());
|
||
|
}
|
||
|
if ( value.includes('$currentDate$') ) {
|
||
|
value = value.replaceAll('$currentDate$', time.toUTCString());
|
||
|
}
|
||
|
if ( value.includes('$currentISODate$') ) {
|
||
|
value = value.replaceAll('$currentISODate$', time.toISOString());
|
||
|
}
|
||
|
|
||
|
let expires = '';
|
||
|
if ( offsetExpiresSec !== '' ) {
|
||
|
if ( offsetExpiresSec === '1day' ) {
|
||
|
time.setDate(time.getDate() + 1);
|
||
|
} else if ( offsetExpiresSec === '1year' ) {
|
||
|
time.setFullYear(time.getFullYear() + 1);
|
||
|
} else {
|
||
|
if ( /^\d+$/.test(offsetExpiresSec) === false ) { return; }
|
||
|
time.setSeconds(time.getSeconds() + parseInt(offsetExpiresSec, 10));
|
||
|
}
|
||
|
expires = time.toUTCString();
|
||
|
}
|
||
|
|
||
|
const done = setCookieFn(
|
||
|
true,
|
||
|
name,
|
||
|
value,
|
||
|
expires,
|
||
|
path,
|
||
|
safeSelf().getExtraArgs(Array.from(arguments), 4)
|
||
|
);
|
||
|
|
||
|
if ( done ) {
|
||
|
safe.uboLog(logPrefix, 'Done');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function safeSelf() {
|
||
|
if ( scriptletGlobals.safeSelf ) {
|
||
|
return scriptletGlobals.safeSelf;
|
||
|
}
|
||
|
const self = globalThis;
|
||
|
const safe = {
|
||
|
'Array_from': Array.from,
|
||
|
'Error': self.Error,
|
||
|
'Function_toStringFn': self.Function.prototype.toString,
|
||
|
'Function_toString': thisArg => safe.Function_toStringFn.call(thisArg),
|
||
|
'Math_floor': Math.floor,
|
||
|
'Math_max': Math.max,
|
||
|
'Math_min': Math.min,
|
||
|
'Math_random': Math.random,
|
||
|
'Object': Object,
|
||
|
'Object_defineProperty': Object.defineProperty.bind(Object),
|
||
|
'Object_defineProperties': Object.defineProperties.bind(Object),
|
||
|
'Object_fromEntries': Object.fromEntries.bind(Object),
|
||
|
'Object_getOwnPropertyDescriptor': Object.getOwnPropertyDescriptor.bind(Object),
|
||
|
'RegExp': self.RegExp,
|
||
|
'RegExp_test': self.RegExp.prototype.test,
|
||
|
'RegExp_exec': self.RegExp.prototype.exec,
|
||
|
'Request_clone': self.Request.prototype.clone,
|
||
|
'XMLHttpRequest': self.XMLHttpRequest,
|
||
|
'addEventListener': self.EventTarget.prototype.addEventListener,
|
||
|
'removeEventListener': self.EventTarget.prototype.removeEventListener,
|
||
|
'fetch': self.fetch,
|
||
|
'JSON': self.JSON,
|
||
|
'JSON_parseFn': self.JSON.parse,
|
||
|
'JSON_stringifyFn': self.JSON.stringify,
|
||
|
'JSON_parse': (...args) => safe.JSON_parseFn.call(safe.JSON, ...args),
|
||
|
'JSON_stringify': (...args) => safe.JSON_stringifyFn.call(safe.JSON, ...args),
|
||
|
'log': console.log.bind(console),
|
||
|
// Properties
|
||
|
logLevel: 0,
|
||
|
// Methods
|
||
|
makeLogPrefix(...args) {
|
||
|
return this.sendToLogger && `[${args.join(' \u205D ')}]` || '';
|
||
|
},
|
||
|
uboLog(...args) {
|
||
|
if ( this.sendToLogger === undefined ) { return; }
|
||
|
if ( args === undefined || args[0] === '' ) { return; }
|
||
|
return this.sendToLogger('info', ...args);
|
||
|
|
||
|
},
|
||
|
uboErr(...args) {
|
||
|
if ( this.sendToLogger === undefined ) { return; }
|
||
|
if ( args === undefined || args[0] === '' ) { return; }
|
||
|
return this.sendToLogger('error', ...args);
|
||
|
},
|
||
|
escapeRegexChars(s) {
|
||
|
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||
|
},
|
||
|
initPattern(pattern, options = {}) {
|
||
|
if ( pattern === '' ) {
|
||
|
return { matchAll: true };
|
||
|
}
|
||
|
const expect = (options.canNegate !== true || pattern.startsWith('!') === false);
|
||
|
if ( expect === false ) {
|
||
|
pattern = pattern.slice(1);
|
||
|
}
|
||
|
const match = /^\/(.+)\/([gimsu]*)$/.exec(pattern);
|
||
|
if ( match !== null ) {
|
||
|
return {
|
||
|
re: new this.RegExp(
|
||
|
match[1],
|
||
|
match[2] || options.flags
|
||
|
),
|
||
|
expect,
|
||
|
};
|
||
|
}
|
||
|
if ( options.flags !== undefined ) {
|
||
|
return {
|
||
|
re: new this.RegExp(this.escapeRegexChars(pattern),
|
||
|
options.flags
|
||
|
),
|
||
|
expect,
|
||
|
};
|
||
|
}
|
||
|
return { pattern, expect };
|
||
|
},
|
||
|
testPattern(details, haystack) {
|
||
|
if ( details.matchAll ) { return true; }
|
||
|
if ( details.re ) {
|
||
|
return this.RegExp_test.call(details.re, haystack) === details.expect;
|
||
|
}
|
||
|
return haystack.includes(details.pattern) === details.expect;
|
||
|
},
|
||
|
patternToRegex(pattern, flags = undefined, verbatim = false) {
|
||
|
if ( pattern === '' ) { return /^/; }
|
||
|
const match = /^\/(.+)\/([gimsu]*)$/.exec(pattern);
|
||
|
if ( match === null ) {
|
||
|
const reStr = this.escapeRegexChars(pattern);
|
||
|
return new RegExp(verbatim ? `^${reStr}$` : reStr, flags);
|
||
|
}
|
||
|
try {
|
||
|
return new RegExp(match[1], match[2] || undefined);
|
||
|
}
|
||
|
catch(ex) {
|
||
|
}
|
||
|
return /^/;
|
||
|
},
|
||
|
getExtraArgs(args, offset = 0) {
|
||
|
const entries = args.slice(offset).reduce((out, v, i, a) => {
|
||
|
if ( (i & 1) === 0 ) {
|
||
|
const rawValue = a[i+1];
|
||
|
const value = /^\d+$/.test(rawValue)
|
||
|
? parseInt(rawValue, 10)
|
||
|
: rawValue;
|
||
|
out.push([ a[i], value ]);
|
||
|
}
|
||
|
return out;
|
||
|
}, []);
|
||
|
return this.Object_fromEntries(entries);
|
||
|
},
|
||
|
onIdle(fn, options) {
|
||
|
if ( self.requestIdleCallback ) {
|
||
|
return self.requestIdleCallback(fn, options);
|
||
|
}
|
||
|
return self.requestAnimationFrame(fn);
|
||
|
},
|
||
|
};
|
||
|
scriptletGlobals.safeSelf = safe;
|
||
|
if ( scriptletGlobals.bcSecret === undefined ) { return safe; }
|
||
|
// This is executed only when the logger is opened
|
||
|
const bc = new self.BroadcastChannel(scriptletGlobals.bcSecret);
|
||
|
let bcBuffer = [];
|
||
|
safe.logLevel = scriptletGlobals.logLevel || 1;
|
||
|
safe.sendToLogger = (type, ...args) => {
|
||
|
if ( args.length === 0 ) { return; }
|
||
|
const text = `[${document.location.hostname || document.location.href}]${args.join(' ')}`;
|
||
|
if ( bcBuffer === undefined ) {
|
||
|
return bc.postMessage({ what: 'messageToLogger', type, text });
|
||
|
}
|
||
|
bcBuffer.push({ type, text });
|
||
|
};
|
||
|
bc.onmessage = ev => {
|
||
|
const msg = ev.data;
|
||
|
switch ( msg ) {
|
||
|
case 'iamready!':
|
||
|
if ( bcBuffer === undefined ) { break; }
|
||
|
bcBuffer.forEach(({ type, text }) =>
|
||
|
bc.postMessage({ what: 'messageToLogger', type, text })
|
||
|
);
|
||
|
bcBuffer = undefined;
|
||
|
break;
|
||
|
case 'setScriptletLogLevelToOne':
|
||
|
safe.logLevel = 1;
|
||
|
break;
|
||
|
case 'setScriptletLogLevelToTwo':
|
||
|
safe.logLevel = 2;
|
||
|
break;
|
||
|
}
|
||
|
};
|
||
|
bc.postMessage('areyouready?');
|
||
|
return safe;
|
||
|
}
|
||
|
|
||
|
function setCookieFn(
|
||
|
trusted = false,
|
||
|
name = '',
|
||
|
value = '',
|
||
|
expires = '',
|
||
|
path = '',
|
||
|
options = {},
|
||
|
) {
|
||
|
// https://datatracker.ietf.org/doc/html/rfc2616#section-2.2
|
||
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/2777
|
||
|
if ( trusted === false && /[^!#$%&'*+\-.0-9A-Z[\]^_`a-z|~]/.test(name) ) {
|
||
|
name = encodeURIComponent(name);
|
||
|
}
|
||
|
// https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1
|
||
|
// The characters [",] are given a pass from the RFC requirements because
|
||
|
// apparently browsers do not follow the RFC to the letter.
|
||
|
if ( /[^ -:<-[\]-~]/.test(value) ) {
|
||
|
value = encodeURIComponent(value);
|
||
|
}
|
||
|
|
||
|
const cookieBefore = getCookieFn(name);
|
||
|
if ( cookieBefore !== undefined && options.dontOverwrite ) { return; }
|
||
|
if ( cookieBefore === value && options.reload ) { return; }
|
||
|
|
||
|
const cookieParts = [ name, '=', value ];
|
||
|
if ( expires !== '' ) {
|
||
|
cookieParts.push('; expires=', expires);
|
||
|
}
|
||
|
|
||
|
if ( path === '' ) { path = '/'; }
|
||
|
else if ( path === 'none' ) { path = ''; }
|
||
|
if ( path !== '' && path !== '/' ) { return; }
|
||
|
if ( path === '/' ) {
|
||
|
cookieParts.push('; path=/');
|
||
|
}
|
||
|
|
||
|
if ( trusted ) {
|
||
|
if ( options.domain ) {
|
||
|
cookieParts.push(`; domain=${options.domain}`);
|
||
|
}
|
||
|
cookieParts.push('; Secure');
|
||
|
} else if ( /^__(Host|Secure)-/.test(name) ) {
|
||
|
cookieParts.push('; Secure');
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
document.cookie = cookieParts.join('');
|
||
|
} catch(_) {
|
||
|
}
|
||
|
|
||
|
const done = getCookieFn(name) === value;
|
||
|
if ( done && options.reload ) {
|
||
|
window.location.reload();
|
||
|
}
|
||
|
|
||
|
return done;
|
||
|
}
|
||
|
|
||
|
function getCookieFn(
|
||
|
name = ''
|
||
|
) {
|
||
|
for ( const s of document.cookie.split(/\s*;\s*/) ) {
|
||
|
const pos = s.indexOf('=');
|
||
|
if ( pos === -1 ) { continue; }
|
||
|
if ( s.slice(0, pos) !== name ) { continue; }
|
||
|
return s.slice(pos+1).trim();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
const hnParts = [];
|
||
|
try { hnParts.push(...document.location.hostname.split('.')); }
|
||
|
catch(ex) { }
|
||
|
const hnpartslen = hnParts.length;
|
||
|
if ( hnpartslen === 0 ) { return; }
|
||
|
|
||
|
const todoIndices = new Set();
|
||
|
const tonotdoIndices = [];
|
||
|
|
||
|
// Exceptions
|
||
|
if ( exceptionsMap.size !== 0 ) {
|
||
|
for ( let i = 0; i < hnpartslen; i++ ) {
|
||
|
const hn = hnParts.slice(i).join('.');
|
||
|
const excepted = exceptionsMap.get(hn);
|
||
|
if ( excepted ) { tonotdoIndices.push(...excepted); }
|
||
|
}
|
||
|
exceptionsMap.clear();
|
||
|
}
|
||
|
|
||
|
// Hostname-based
|
||
|
if ( hostnamesMap.size !== 0 ) {
|
||
|
const collectArgIndices = hn => {
|
||
|
let argsIndices = hostnamesMap.get(hn);
|
||
|
if ( argsIndices === undefined ) { return; }
|
||
|
if ( typeof argsIndices === 'number' ) { argsIndices = [ argsIndices ]; }
|
||
|
for ( const argsIndex of argsIndices ) {
|
||
|
if ( tonotdoIndices.includes(argsIndex) ) { continue; }
|
||
|
todoIndices.add(argsIndex);
|
||
|
}
|
||
|
};
|
||
|
for ( let i = 0; i < hnpartslen; i++ ) {
|
||
|
const hn = hnParts.slice(i).join('.');
|
||
|
collectArgIndices(hn);
|
||
|
}
|
||
|
collectArgIndices('*');
|
||
|
hostnamesMap.clear();
|
||
|
}
|
||
|
|
||
|
// Entity-based
|
||
|
if ( entitiesMap.size !== 0 ) {
|
||
|
const n = hnpartslen - 1;
|
||
|
for ( let i = 0; i < n; i++ ) {
|
||
|
for ( let j = n; j > i; j-- ) {
|
||
|
const en = hnParts.slice(i,j).join('.');
|
||
|
let argsIndices = entitiesMap.get(en);
|
||
|
if ( argsIndices === undefined ) { continue; }
|
||
|
if ( typeof argsIndices === 'number' ) { argsIndices = [ argsIndices ]; }
|
||
|
for ( const argsIndex of argsIndices ) {
|
||
|
if ( tonotdoIndices.includes(argsIndex) ) { continue; }
|
||
|
todoIndices.add(argsIndex);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
entitiesMap.clear();
|
||
|
}
|
||
|
|
||
|
// Apply scriplets
|
||
|
for ( const i of todoIndices ) {
|
||
|
try { trustedSetCookie(...argsList[i]); }
|
||
|
catch(ex) {}
|
||
|
}
|
||
|
argsList.length = 0;
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
};
|
||
|
// End of code to inject
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
// Inject code
|
||
|
|
||
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1736575
|
||
|
// 'MAIN' world not yet supported in Firefox, so we inject the code into
|
||
|
// 'MAIN' ourself when environment in Firefox.
|
||
|
|
||
|
const targetWorld = 'ISOLATED';
|
||
|
|
||
|
// Not Firefox
|
||
|
if ( typeof wrappedJSObject !== 'object' || targetWorld === 'ISOLATED' ) {
|
||
|
return uBOL_trustedSetCookie();
|
||
|
}
|
||
|
|
||
|
// Firefox
|
||
|
{
|
||
|
const page = self.wrappedJSObject;
|
||
|
let script, url;
|
||
|
try {
|
||
|
page.uBOL_trustedSetCookie = cloneInto([
|
||
|
[ '(', uBOL_trustedSetCookie.toString(), ')();' ],
|
||
|
{ type: 'text/javascript; charset=utf-8' },
|
||
|
], self);
|
||
|
const blob = new page.Blob(...page.uBOL_trustedSetCookie);
|
||
|
url = page.URL.createObjectURL(blob);
|
||
|
const doc = page.document;
|
||
|
script = doc.createElement('script');
|
||
|
script.async = false;
|
||
|
script.src = url;
|
||
|
(doc.head || doc.documentElement || doc).append(script);
|
||
|
} catch (ex) {
|
||
|
console.error(ex);
|
||
|
}
|
||
|
if ( url ) {
|
||
|
if ( script ) { script.remove(); }
|
||
|
page.URL.revokeObjectURL(url);
|
||
|
}
|
||
|
delete page.uBOL_trustedSetCookie;
|
||
|
}
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
// End of local scope
|
||
|
})();
|
||
|
|
||
|
/******************************************************************************/
|
||
|
|
||
|
void 0;
|