mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
Mind other old constructs for scriptlets
Related feedback: https://old.reddit.com/r/uBlockOrigin/comments/1jmcqhn/ Related commit: https://github.com/gorhill/uBlock/commit/44c038b9a1
This commit is contained in:
parent
44c038b9a1
commit
b381ceda72
1 changed files with 7 additions and 6 deletions
|
|
@ -67,8 +67,10 @@ const lookupScriptlet = (rawToken, mainMap, isolatedMap, debug = false) => {
|
||||||
const details = reng.contentFromName(token, 'text/javascript');
|
const details = reng.contentFromName(token, 'text/javascript');
|
||||||
if ( details === undefined ) { return; }
|
if ( details === undefined ) { return; }
|
||||||
const targetWorldMap = details.world !== 'ISOLATED' ? mainMap : isolatedMap;
|
const targetWorldMap = details.world !== 'ISOLATED' ? mainMap : isolatedMap;
|
||||||
const content = patchScriptlet(details.js, args.slice(1));
|
const match = /^function\s+([^(\s]+)\s*\(/.exec(details.js);
|
||||||
if ( content.startsWith('(function(') === false ) {
|
const fname = match && match[1];
|
||||||
|
const content = patchScriptlet(fname, details.js, args.slice(1));
|
||||||
|
if ( fname ) {
|
||||||
targetWorldMap.set(token, details.js);
|
targetWorldMap.set(token, details.js);
|
||||||
}
|
}
|
||||||
const dependencies = details.dependencies || [];
|
const dependencies = details.dependencies || [];
|
||||||
|
|
@ -92,10 +94,9 @@ const lookupScriptlet = (rawToken, mainMap, isolatedMap, debug = false) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fill-in scriptlet argument placeholders.
|
// Fill-in scriptlet argument placeholders.
|
||||||
const patchScriptlet = (content, arglist) => {
|
const patchScriptlet = (fname, content, arglist) => {
|
||||||
const match = /^function\s+([^(\s]+)\s*\(/.exec(content);
|
if ( fname ) {
|
||||||
if ( match ) {
|
content = `${fname}({{args}});`;
|
||||||
content = `${match[1]}({{args}});`;
|
|
||||||
} else {
|
} else {
|
||||||
for ( let i = 0; i < arglist.length; i++ ) {
|
for ( let i = 0; i < arglist.length; i++ ) {
|
||||||
content = content.replace(`{{${i+1}}}`, arglist[i]);
|
content = content.replace(`{{${i+1}}}`, arglist[i]);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue