1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-05 11:37:01 +02:00

[mv3] Let the scriplet sort out targeted sites when too many targets

This is too avoid `matches` property with too many hostnames at
registerContentScripts() time. Threshold has been arbitrarily
set at 100.
This commit is contained in:
Raymond Hill 2023-06-05 12:14:37 -04:00
parent d300f2119a
commit 7e712246a9
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -369,20 +369,26 @@ function registerScriptlet(context, scriptletDetails) {
const matches = [];
const excludeMatches = [];
let targetHostnames = [];
if ( hasBroadHostPermission ) {
excludeMatches.push(...permissionRevokedMatches);
matches.push(...ut.matchesFromHostnames(scriptletHostnames));
if ( scriptletHostnames.length > 100 ) {
targetHostnames = [ '*' ];
} else {
targetHostnames = scriptletHostnames;
}
} else if ( permissionGrantedHostnames.length !== 0 ) {
matches.push(
...ut.matchesFromHostnames(
ut.intersectHostnameIters(
permissionGrantedHostnames,
scriptletHostnames
)
)
);
if ( scriptletHostnames.includes('*') ) {
targetHostnames = permissionGrantedHostnames;
} else {
targetHostnames = ut.intersectHostnameIters(
permissionGrantedHostnames,
scriptletHostnames
);
}
}
if ( matches.length === 0 ) { continue; }
if ( targetHostnames.length === 0 ) { continue; }
matches.push(...ut.matchesFromHostnames(targetHostnames));
before.delete(id); // Important!