mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
[mv3] Safari: expand rsach requestDomains entries into own rule
Related issue: https://github.com/uBlockOrigin/uBOL-home/issues/358
This commit is contained in:
parent
76d8b97869
commit
9f3282d74f
2 changed files with 72 additions and 38 deletions
|
|
@ -324,38 +324,12 @@ const isURLSkip = rule =>
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
function patchRuleset(ruleset) {
|
||||
if ( platform !== 'safari' ) { return ruleset; }
|
||||
const out = [];
|
||||
for ( const rule of ruleset ) {
|
||||
const condition = rule.condition;
|
||||
if ( rule.action.type === 'modifyHeaders' ) {
|
||||
log(`Safari's incomplete API: ${JSON.stringify(rule)}`, true);
|
||||
continue;
|
||||
}
|
||||
if ( Array.isArray(rule.condition.responseHeaders) ) {
|
||||
log(`Safari's incomplete API: ${JSON.stringify(rule)}`, true);
|
||||
continue;
|
||||
}
|
||||
if ( Array.isArray(condition.requestMethods) ) {
|
||||
log(`Safari's incomplete API: ${JSON.stringify(rule)}`, true);
|
||||
continue;
|
||||
}
|
||||
if ( Array.isArray(condition.excludedRequestMethods) ) {
|
||||
log(`Safari's incomplete API: ${JSON.stringify(rule)}`, true);
|
||||
continue;
|
||||
}
|
||||
if ( Array.isArray(condition.initiatorDomains) ) {
|
||||
condition.domains = condition.initiatorDomains;
|
||||
delete condition.initiatorDomains;
|
||||
}
|
||||
if ( Array.isArray(condition.excludedInitiatorDomains) ) {
|
||||
condition.excludedDomains = condition.excludedInitiatorDomains;
|
||||
delete condition.excludedInitiatorDomains;
|
||||
}
|
||||
out.push(rule);
|
||||
}
|
||||
return out;
|
||||
async function patchRuleset(ruleset) {
|
||||
return import(`./${platform}/patch-ruleset.js`).then(module => {
|
||||
return module.patchRuleset(ruleset)
|
||||
}).catch(( ) => {
|
||||
return ruleset;
|
||||
});
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
@ -550,7 +524,7 @@ async function processNetworkFilters(assetDetails, network) {
|
|||
}
|
||||
}
|
||||
|
||||
const plainGood = patchRuleset(
|
||||
const plainGood = await patchRuleset(
|
||||
rules.filter(rule => isSafe(rule) && isRegex(rule) === false)
|
||||
);
|
||||
log(`\tPlain good: ${plainGood.length}`);
|
||||
|
|
@ -560,12 +534,12 @@ async function processNetworkFilters(assetDetails, network) {
|
|||
.join('\n'), true
|
||||
);
|
||||
|
||||
const regexes = patchRuleset(
|
||||
const regexes = await patchRuleset(
|
||||
rules.filter(rule => isSafe(rule) && isRegex(rule))
|
||||
);
|
||||
log(`\tMaybe good (regexes): ${regexes.length}`);
|
||||
|
||||
const redirects = patchRuleset(
|
||||
const redirects = await patchRuleset(
|
||||
rules.filter(rule =>
|
||||
isUnsupported(rule) === false &&
|
||||
isRedirect(rule)
|
||||
|
|
@ -579,19 +553,19 @@ async function processNetworkFilters(assetDetails, network) {
|
|||
});
|
||||
log(`\tredirect=: ${redirects.length}`);
|
||||
|
||||
const removeparamsGood = patchRuleset(
|
||||
const removeparamsGood = await patchRuleset(
|
||||
rules.filter(rule =>
|
||||
isUnsupported(rule) === false && isRemoveparam(rule)
|
||||
)
|
||||
);
|
||||
const removeparamsBad = patchRuleset(
|
||||
const removeparamsBad = await patchRuleset(
|
||||
rules.filter(rule =>
|
||||
isUnsupported(rule) && isRemoveparam(rule)
|
||||
)
|
||||
);
|
||||
log(`\tremoveparams= (accepted/discarded): ${removeparamsGood.length}/${removeparamsBad.length}`);
|
||||
|
||||
const modifyHeaders = patchRuleset(
|
||||
const modifyHeaders = await patchRuleset(
|
||||
rules.filter(rule =>
|
||||
isUnsupported(rule) === false &&
|
||||
isModifyHeaders(rule)
|
||||
|
|
|
|||
60
platform/mv3/safari/patch-ruleset.js
Normal file
60
platform/mv3/safari/patch-ruleset.js
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*******************************************************************************
|
||||
|
||||
uBlock Origin - a comprehensive, efficient content blocker
|
||||
Copyright (C) 2025-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
|
||||
*/
|
||||
|
||||
function patchRuleWithRequestDomains(rule, out) {
|
||||
const requestDomains = rule.condition.requestDomains;
|
||||
delete rule.condition.requestDomains;
|
||||
for ( const domain of requestDomains ) {
|
||||
const newRule = structuredClone(rule);
|
||||
newRule.condition.urlFilter = `||${domain}^`;
|
||||
out.push(newRule);
|
||||
}
|
||||
}
|
||||
|
||||
export function patchRuleset(ruleset) {
|
||||
const out = [];
|
||||
for ( const rule of ruleset ) {
|
||||
const condition = rule.condition;
|
||||
if ( rule.action.type === 'modifyHeaders' ) { continue; }
|
||||
if ( Array.isArray(rule.condition.responseHeaders) ) { continue; }
|
||||
if ( Array.isArray(condition.requestMethods) ) { continue; }
|
||||
if ( Array.isArray(condition.excludedRequestMethods) ) { continue; }
|
||||
if ( Array.isArray(condition.initiatorDomains) ) {
|
||||
condition.domains = condition.initiatorDomains;
|
||||
delete condition.initiatorDomains;
|
||||
}
|
||||
if ( Array.isArray(condition.excludedInitiatorDomains) ) {
|
||||
condition.excludedDomains = condition.excludedInitiatorDomains;
|
||||
delete condition.excludedInitiatorDomains;
|
||||
}
|
||||
if (
|
||||
Array.isArray(condition.requestDomains) &&
|
||||
Array.isArray(condition.excludedRequestDomains) === false &&
|
||||
Boolean(condition.regexFilter) === false &&
|
||||
Boolean(condition.urlFilter) === false
|
||||
) {
|
||||
patchRuleWithRequestDomains(rule, out);
|
||||
} else {
|
||||
out.push(rule);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
Loading…
Reference in a new issue