Byparr/extentions/uBOL-home/rulesets/scripting/scriptlet/default.trusted-replace-node-text.js

447 lines
32 KiB
JavaScript
Raw Normal View History

2024-07-24 13:57:40 +00:00
/*******************************************************************************
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: default
/******************************************************************************/
// Important!
// Isolate from global scope
// Start of local scope
(( ) => {
/******************************************************************************/
// Start of code to inject
const uBOL_replaceNodeText = function() {
const scriptletGlobals = {}; // jshint ignore: line
const argsList = [["script","\"adBlockWallEnabled\":true","\"adBlockWallEnabled\":false"],["script","popunder","p"],["script","/\\$.*embed.*.appendTo.*;/","","condition","appendTo"],["script","setInterval"],["script","/\\\"homad\\\",/"],["script","/\\\"homad\\\":\\{\\\"state\\\":\\\"enabled\\\"\\}/","\"homad\":{\"state\":\"disabled\"}"],["script","\"isAdBlockerEnabled\":true","\"isAdBlockerEnabled\":false"],["script","popunder","","condition","popunder","stay","1"],["script","/\\(function\\(.*?\\)\\(\\)\\}\\)\\(\\)/","","condition","throw"],["script","\"}};","\"}}; jQuery(document).ready(function(t){let e=document.createElement(\"link\");e.setAttribute(\"rel\",\"stylesheet\"),e.setAttribute(\"media\",\"all\"),e.setAttribute(\"href\",\"https://dragontea.ink/wp-content/cache/autoptimize/css/autoptimize_325679dd9090b57747bdd165077b8cc2.css\"),document.head.appendChild(e),t(\".dmpvazRKNzBib1IxNjh0T0cwUUUxekEyY3F6Wm5QYzJDWGZqdXFnRzZ0TT0nuobc\").parent().prev().prev().prev();var a=1,n=16,r=11,i=\"08\",g=\"\",c=\"\",d=0,o=2,p=3,s=0,h=100;s++,s*=2,h/=2,h/=2;var $=3,u=20;function b(){let e=t(\".entry-header.header\"),a=parseInt(e.attr(\"data-id\"));return a}function m(t,e,a,n,r){return CryptoJSAesJson.decrypt(t,e+a+n+r)}function f(t,e){return CryptoJSAesJson.decrypt(t,e)}function l(t,e){return parseInt(t.toString()+e.toString())}function k(t,e,a){return t.toString()+e.toString()+a.toString()}$*=2,u=u-2-2,i=\"03\",o++,r++,n=n/4-2,a++,a*=4,n++,n++,n++,a-=5,r++,i=\"07\",t(\".reading-content .page-break img\").each(function(){var e,g=t(this),c=f(g.attr(\"id\").toString(),(e=parseInt((b()+l(r,i))*a-t(\".reading-content .page-break img\").length),e=l(2*n+1,e)).toString());g.attr(\"id\",c)}),r=0,n=0,a=0,i=0,t(\".reading-content .page-break img\").each(function(){var e=t(this),a=parseInt(e.attr(\"id\").replace(/image-(\\d+)[a-z]+/i,\"$1\"));t(\".reading-content .page-break\").eq(a).append(e)}),t(\".reading-content .page-break img\").each(function(){var e=t(this).attr(\"id\");g+=e.substr(-1),t(this).attr(\"id\",e.slice(0,-1))}),d++,$++,$++,u/=4,u*=2,o*=2,p-=3,p++,t(\".reading-content .page-break img\").each(function(){var e,a=t(this),n=f(a.attr(\"dta\").toString(),(e=parseInt((b()+l($,u))*(2*d)-t(\".reading-content .page-break img\").length-(4*d+1)),e=k(2*o+p+p+1,g,e)).toString());a.attr(\"dta\",n)}),d=0,$=0,u=0,o=0,p=0,t(\".reading-content .page-break img\").each(function(){var e=t(this).attr(\"dta\").substr(-2);c+=e,t(this).removeAttr(\"dta\")}),s*=s,s++,h-=25,h++,h++,t(\".reading-content .page-break img\").each(function(){var e=t(this),a=f(e.attr(\"data-src\").toString(),(b(),k(b()+4*s,c,t(\".reading-content .page-break img\").length*(2*h))).toString());e.attr(\"data-src\",a)}),s=0,h=0,t(\".reading-content .page-break img\").each(function(){t(this).addClass(\"wp-manga-chapter-img img-responsive lazyload effect-fade\")}),_0xabe6x4d=!0});"],["script","scri12pts && ifra2mes && coo1kies","true"],["script","/catch[\\s\\S]*?}/","","condition","fetch"],["script","/(function playVideo\\(\\) \\{[\\s\\S]*?\\.remove\\(\\);[\\s\\S]*?\\})/","$1 playVideo();"],["script","video_urls.length != activeItem","!1"],["script","\"adblock-detection\",\"enabled\":true","\"adblock-detection\",\"enabled\":false"],["script","/if.*includes.*;/"],["script","/^([^{])/","document.addEventListener('DOMContentLoaded',()=>{const i=document.createElement('iframe');i.style='height:0;width:0;border:0';i.id='aswift_0';document.body.appendChild(i);i.focus();const f=document.createElement('div');f.id='9JJFp';document.body.appendChild(f);});$1","sedCount","2"],["script","true","false","condition","antiads"],["script","/^window\\.location\\.href.*\\'$/gms"],["script","= false;","= true;","condition","innerHTML"],["script","'IFRAME'","'BODY'"],["script","typeof cdo == 'undefined' || document.querySelector('div.textads.banner-ads.banner_ads.ad-unit.ad-zone.ad-space.adsbox') == undefined","false"],["script","/window\\.location\\.href='.*';/","","condition","openLink"],["script","});","});var iframe = document.createElement('iframe');iframe.style.height = '0';iframe.style.width =
const hostnamesMap = new Map([["bild.de",0],["nhentai.net",1],["jizzbunker.com",2],["multiup.io",3],["giga.de",4],["kino.de",4],["spieletipps.de",4],["t-online.de",5],["games.metro.us",6],["arcade.dailygazette.com",6],["games.dailymail.co.uk",6],["buktube.com",7],["fullxh.com",7],["galleryxh.site",7],["megaxh.com",7],["movingxh.world",7],["seexh.com",7],["taoxh.life",7],["unlockxh4.com",7],["xhaccess.com",7],["xhadult2.com",7],["xhadult3.com",7],["xhadult4.com",7],["xhadult5.com",7],["xhamster46.com",7],["xhbig.com",7],["xhbranch5.com",7],["xhday.com",7],["xhday1.com",7],["xhmoon5.com",7],["xhplanet1.com",7],["xhplanet2.com",7],["xhreal2.com",7],["xhreal3.com",7],["xhtab2.com",7],["xhtab4.com",7],["xhtree.com",7],["xhvictory.com",7],["xhwebsite.com",7],["xhwebsite2.com",7],["xhwide1.com",7],["infinityscans.xyz",8],["infinityscans.net",8],["dragontea.ink",9],["perchance.org",10],["cheater.ninja",11],["dizikral.com",[12,13]],["vandaaginside.nl",14],["authenticateme.xyz",15],["sinonimos.de",16],["antonimos.de",16],["quesignifi.ca",16],["tiktokrealtime.com",16],["tiktokcounter.net",16],["tpayr.xyz",16],["poqzn.xyz",16],["ashrfd.xyz",16],["rezsx.xyz",16],["tryzt.xyz",16],["ashrff.xyz",16],["rezst.xyz",16],["dawenet.com",16],["erzar.xyz",16],["waezm.xyz",16],["waezg.xyz",16],["blackwoodacademy.org",16],["cryptednews.space",16],["vivuq.com",16],["swgop.com",16],["vbnmll.com",16],["telcoinfo.online",16],["dshytb.com",16],["moonplusnews.com",17],["loanoffering.in",17],["hipsonyc.com",18],["theforyou.in",18],["gyanitheme.com",18],["hostadviser.net",18],["blog.cryptowidgets.net",[19,20]],["blog.insurancegold.in",[19,20]],["blog.wiki-topia.com",[19,20]],["blog.coinsvalue.net",[19,20]],["blog.cookinguide.net",[19,20]],["blog.freeoseocheck.com",[19,20]],["blog.makeupguide.net",20],["blog.carstopia.net",20],["blog.carsmania.net",20],["bitzite.com",20],["appsbull.com",20],["diudemy.com",20],["maqal360.com",20],["advertisingexcel.com",20],["allcryptoz.net",20],["batmanfactor.com",20],["beautifulfashionnailart.com",20],["crewbase.net",20],["crewus.net",20],["phineypet.com",20],["shinbhu.net",20],["shinchu.net",20],["talkforfitness.com",20],["thumb8.net",20],["thumb9.net",20],["topcryptoz.net",20],["uniqueten.net",20],["ultraten.net",20],["suaurl.com",21],["mamahawa.com",22],["laweducationinfo.com",23],["savemoneyinfo.com",23],["worldaffairinfo.com",23],["godstoryinfo.com",23],["successstoryinfo.com",23],["cxissuegk.com",23],["learnmarketinfo.com",23],["bhugolinfo.com",23],["armypowerinfo.com",23],["rsadnetworkinfo.com",23],["rsinsuranceinfo.com",23],["rsfinanceinfo.com",23],["rsgamer.app",23],["rssoftwareinfo.com",23],["rshostinginfo.com",23],["rseducationinfo.com",23],["dlink2.net",24],["viralsbaba1.blogspot.com",25],["dl.apkmoddone.com",26],["eroasmr.com",27],["bussyhunter.com",28],["kusonime.com",30],["mcrypto.club",31],["codingnepalweb.com",32],["demonoid.is",33],["jpvhub.com",34],["derstandard.at",35],["derstandard.de",35],["www.chip.de",36],["zefoy.com",37],["idoitmyself.xyz",38],["uploadboy.com",[39,40]],["reymit.ir",41],["foodxor.com",43],["drawer-opportunity-i-243.site",44],["adultdeepfakes.com",45],["linkshortify.com",46],["nexusmods.com",47],["comidacaseira.me",48],["tvbanywherena.com",49],["haveibeenpwned.com",50],["trainerscity.com",51],["tikmate.app",52],["paste-drop.com",53],["dizipal730.com",54],["filext.com",55],["kiddyearner.com",56],["www.reddit.com",57],["9to5google.com",58],["9to5mac.com",58],["api.dock.agacad.com",59],["jprime.jp",60],["financemonk.net",61],["www.youtube.com",62],["download.megaup.net",63],["jytechs.in",64],["dev.miuiflash.com",64],["djxmaza.in",64],["thecubexguide.com",64],["client.falixnodes.net",[65,66]]]);
const entitiesMap = new Map([["hamsterix",7],["xhamster",7],["xhamster1",7],["xhamster10",7],["xhamster11",7],["xhamster12",7],["xhamster13",7],["xhamster14",7],["xhamster15",7],["xhamster16",7],["xhamster17",7],["xhamster18",7],["xhamster19",7],["xhamster20",7],["xhamster2",7],["xhamster3",7],["xhamster4",7],["xhamster42",7],["xhamster5",7],["xhamster7",7],["xhamster8",7],["aagmaal",29],["empire-stream",42],["empire-streaming",42],["empire-streamz",42],["dropgalaxy",61]]);
const exceptionsMap = new Map([]);
/******************************************************************************/
function replaceNodeText(
nodeName,
pattern,
replacement,
...extraArgs
) {
replaceNodeTextFn(nodeName, pattern, replacement, ...extraArgs);
}
function replaceNodeTextFn(
nodeName = '',
pattern = '',
replacement = ''
) {
const safe = safeSelf();
const logPrefix = safe.makeLogPrefix('replace-node-text.fn', ...Array.from(arguments));
const reNodeName = safe.patternToRegex(nodeName, 'i', true);
const rePattern = safe.patternToRegex(pattern, 'gms');
const extraArgs = safe.getExtraArgs(Array.from(arguments), 3);
const reCondition = safe.patternToRegex(extraArgs.condition || '', 'ms');
const stop = (takeRecord = true) => {
if ( takeRecord ) {
handleMutations(observer.takeRecords());
}
observer.disconnect();
if ( safe.logLevel > 1 ) {
safe.uboLog(logPrefix, 'Quitting');
}
};
let sedCount = extraArgs.sedCount || 0;
const handleNode = node => {
const before = node.textContent;
reCondition.lastIndex = 0;
if ( safe.RegExp_test.call(reCondition, before) === false ) { return true; }
rePattern.lastIndex = 0;
if ( safe.RegExp_test.call(rePattern, before) === false ) { return true; }
rePattern.lastIndex = 0;
const after = pattern !== ''
? before.replace(rePattern, replacement)
: replacement;
node.textContent = after;
if ( safe.logLevel > 1 ) {
safe.uboLog(logPrefix, `Text before:\n${before.trim()}`);
}
safe.uboLog(logPrefix, `Text after:\n${after.trim()}`);
return sedCount === 0 || (sedCount -= 1) !== 0;
};
const handleMutations = mutations => {
for ( const mutation of mutations ) {
for ( const node of mutation.addedNodes ) {
if ( reNodeName.test(node.nodeName) === false ) { continue; }
if ( handleNode(node) ) { continue; }
stop(false); return;
}
}
};
const observer = new MutationObserver(handleMutations);
observer.observe(document, { childList: true, subtree: true });
if ( document.documentElement ) {
const treeWalker = document.createTreeWalker(
document.documentElement,
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT
);
let count = 0;
for (;;) {
const node = treeWalker.nextNode();
count += 1;
if ( node === null ) { break; }
if ( reNodeName.test(node.nodeName) === false ) { continue; }
if ( node === document.currentScript ) { continue; }
if ( handleNode(node) ) { continue; }
stop(); break;
}
safe.uboLog(logPrefix, `${count} nodes present before installing mutation observer`);
}
if ( extraArgs.stay ) { return; }
runAt(( ) => {
const quitAfter = extraArgs.quitAfter || 0;
if ( quitAfter !== 0 ) {
setTimeout(( ) => { stop(); }, quitAfter);
} else {
stop();
}
}, 'interactive');
}
function runAt(fn, when) {
const intFromReadyState = state => {
const targets = {
'loading': 1,
'interactive': 2, 'end': 2, '2': 2,
'complete': 3, 'idle': 3, '3': 3,
};
const tokens = Array.isArray(state) ? state : [ state ];
for ( const token of tokens ) {
const prop = `${token}`;
if ( targets.hasOwnProperty(prop) === false ) { continue; }
return targets[prop];
}
return 0;
};
const runAt = intFromReadyState(when);
if ( intFromReadyState(document.readyState) >= runAt ) {
fn(); return;
}
const onStateChange = ( ) => {
if ( intFromReadyState(document.readyState) < runAt ) { return; }
fn();
safe.removeEventListener.apply(document, args);
};
const safe = safeSelf();
const args = [ 'readystatechange', onStateChange, { capture: true } ];
safe.addEventListener.apply(document, args);
}
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;
}
/******************************************************************************/
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 { replaceNodeText(...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_replaceNodeText();
}
// Firefox
{
const page = self.wrappedJSObject;
let script, url;
try {
page.uBOL_replaceNodeText = cloneInto([
[ '(', uBOL_replaceNodeText.toString(), ')();' ],
{ type: 'text/javascript; charset=utf-8' },
], self);
const blob = new page.Blob(...page.uBOL_replaceNodeText);
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_replaceNodeText;
}
/******************************************************************************/
// End of local scope
})();
/******************************************************************************/
void 0;