mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-20 04:53:50 +02:00
Fix assembling of scriptlets for isolated world
This commit is contained in:
parent
9b682dff03
commit
40141e2dfc
1 changed files with 9 additions and 1 deletions
|
@ -143,7 +143,15 @@ const isolatedWorldInjector = (( ) => {
|
||||||
scriptletSlot: parts.indexOf('scriptlet-slot'),
|
scriptletSlot: parts.indexOf('scriptlet-slot'),
|
||||||
assemble: function(hostname, scriptlets) {
|
assemble: function(hostname, scriptlets) {
|
||||||
this.parts[this.jsonSlot] = JSON.stringify({ hostname });
|
this.parts[this.jsonSlot] = JSON.stringify({ hostname });
|
||||||
return this.parts.join('').replace('function(){}', scriptlets);
|
const code = this.parts.join('');
|
||||||
|
// Manually substitute noop function with scriptlet wrapper
|
||||||
|
// function, so as to not suffer instances of special
|
||||||
|
// replacement characters `$`,`\` when using String.replace()
|
||||||
|
// with in scriptlet code.
|
||||||
|
const match = /function\(\)\{\}/.exec(code);
|
||||||
|
return code.slice(0, match.index) +
|
||||||
|
scriptlets +
|
||||||
|
code.slice(match.index + match[0].length);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in a new issue