mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-04 08:37:11 +02:00
[mv3] Mitigation: Inject CSS user styles to enforce cosmetic filtering
Related issues: - https://github.com/uBlockOrigin/uBOL-issues/issues/5#issuecomment-1575425913 - https://github.com/w3c/webextensions/issues/403 Currently, there is no other way to inject CSS user styles than to wake up the service worker, so that it can inject the CSS styles itself using the `scripting.insertCSS()` method. If ever the MV3 API supports injecting CSS user styles directly from a content script, uBOL will be back to be fully declarative. At this point the service worker is very lightweight since the filtering is completely declarative, so this is not too much of an issue performance-wise except for the fact that waking up the service worker for the sole purpose of injecting CSS user styles and nothing else introduces a pointless overhead. Hopefully the MV3 API will mature to address such inefficiency.
This commit is contained in:
parent
e16bd1bbbb
commit
6dbbb95b04
@ -53,6 +53,10 @@ import {
|
|||||||
syncWithBrowserPermissions,
|
syncWithBrowserPermissions,
|
||||||
} from './mode-manager.js';
|
} from './mode-manager.js';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ubolLog,
|
||||||
|
} from './utils.js';
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
const rulesetConfig = {
|
const rulesetConfig = {
|
||||||
@ -169,6 +173,28 @@ async function onPermissionsRemoved() {
|
|||||||
|
|
||||||
function onMessage(request, sender, callback) {
|
function onMessage(request, sender, callback) {
|
||||||
|
|
||||||
|
// Does not require trusted origin.
|
||||||
|
|
||||||
|
switch ( request.what ) {
|
||||||
|
|
||||||
|
case 'insertCSS': {
|
||||||
|
const tabId = sender?.tab?.id ?? false;
|
||||||
|
const frameId = sender?.frameId ?? false;
|
||||||
|
if ( tabId === false || frameId === false ) { return; }
|
||||||
|
browser.scripting.insertCSS({
|
||||||
|
css: request.css,
|
||||||
|
origin: 'USER',
|
||||||
|
target: { tabId, frameIds: [ frameId ] },
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Does requires trusted origin.
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/MessageSender
|
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/MessageSender
|
||||||
// Firefox API does not set `sender.origin`
|
// Firefox API does not set `sender.origin`
|
||||||
if ( sender.origin !== undefined && sender.origin !== UBOL_ORIGIN ) { return; }
|
if ( sender.origin !== undefined && sender.origin !== UBOL_ORIGIN ) { return; }
|
||||||
@ -284,7 +310,7 @@ async function start() {
|
|||||||
// We need to update the regex rules only when ruleset version changes.
|
// We need to update the regex rules only when ruleset version changes.
|
||||||
const currentVersion = getCurrentVersion();
|
const currentVersion = getCurrentVersion();
|
||||||
if ( currentVersion !== rulesetConfig.version ) {
|
if ( currentVersion !== rulesetConfig.version ) {
|
||||||
console.log(`Version change: ${rulesetConfig.version} => ${currentVersion}`);
|
ubolLog(`Version change: ${rulesetConfig.version} => ${currentVersion}`);
|
||||||
updateDynamicRules().then(( ) => {
|
updateDynamicRules().then(( ) => {
|
||||||
rulesetConfig.version = currentVersion;
|
rulesetConfig.version = currentVersion;
|
||||||
saveRulesetConfig();
|
saveRulesetConfig();
|
||||||
@ -300,10 +326,10 @@ async function start() {
|
|||||||
registerInjectables();
|
registerInjectables();
|
||||||
|
|
||||||
const enabledRulesets = await dnr.getEnabledRulesets();
|
const enabledRulesets = await dnr.getEnabledRulesets();
|
||||||
console.log(`Enabled rulesets: ${enabledRulesets}`);
|
ubolLog(`Enabled rulesets: ${enabledRulesets}`);
|
||||||
|
|
||||||
dnr.getAvailableStaticRuleCount().then(count => {
|
dnr.getAvailableStaticRuleCount().then(count => {
|
||||||
console.log(`Available static rule count: ${count}`);
|
ubolLog(`Available static rule count: ${count}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/declarativeNetRequest
|
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/declarativeNetRequest
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
import { browser, dnr, i18n } from './ext.js';
|
import { browser, dnr, i18n } from './ext.js';
|
||||||
import { fetchJSON } from './fetch.js';
|
import { fetchJSON } from './fetch.js';
|
||||||
|
import { ubolLog } from './utils.js';
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@ -72,8 +73,8 @@ function getDynamicRules() {
|
|||||||
const map = new Map(
|
const map = new Map(
|
||||||
rules.map(rule => [ rule.id, rule ])
|
rules.map(rule => [ rule.id, rule ])
|
||||||
);
|
);
|
||||||
console.info(`Dynamic rule count: ${map.size}`);
|
ubolLog(`Dynamic rule count: ${map.size}`);
|
||||||
console.info(`Available dynamic rule count: ${dnr.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES - map.size}`);
|
ubolLog(`Available dynamic rule count: ${dnr.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES - map.size}`);
|
||||||
return map;
|
return map;
|
||||||
});
|
});
|
||||||
return dynamicRuleMapPromise;
|
return dynamicRuleMapPromise;
|
||||||
@ -142,7 +143,7 @@ async function updateRegexRules() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( rejectedRegexRules.length !== 0 ) {
|
if ( rejectedRegexRules.length !== 0 ) {
|
||||||
console.info(
|
ubolLog(
|
||||||
'Rejected regexes:',
|
'Rejected regexes:',
|
||||||
rejectedRegexRules.map(rule => rule.condition.regexFilter)
|
rejectedRegexRules.map(rule => rule.condition.regexFilter)
|
||||||
);
|
);
|
||||||
@ -178,10 +179,10 @@ async function updateRegexRules() {
|
|||||||
if ( addRules.length === 0 && removeRuleIds.length === 0 ) { return; }
|
if ( addRules.length === 0 && removeRuleIds.length === 0 ) { return; }
|
||||||
|
|
||||||
if ( removeRuleIds.length !== 0 ) {
|
if ( removeRuleIds.length !== 0 ) {
|
||||||
console.info(`Remove ${removeRuleIds.length} DNR regex rules`);
|
ubolLog(`Remove ${removeRuleIds.length} DNR regex rules`);
|
||||||
}
|
}
|
||||||
if ( addRules.length !== 0 ) {
|
if ( addRules.length !== 0 ) {
|
||||||
console.info(`Add ${addRules.length} DNR regex rules`);
|
ubolLog(`Add ${addRules.length} DNR regex rules`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dnr.updateDynamicRules({ addRules, removeRuleIds });
|
return dnr.updateDynamicRules({ addRules, removeRuleIds });
|
||||||
@ -250,10 +251,10 @@ async function updateRemoveparamRules() {
|
|||||||
if ( addRules.length === 0 && removeRuleIds.length === 0 ) { return; }
|
if ( addRules.length === 0 && removeRuleIds.length === 0 ) { return; }
|
||||||
|
|
||||||
if ( removeRuleIds.length !== 0 ) {
|
if ( removeRuleIds.length !== 0 ) {
|
||||||
console.info(`Remove ${removeRuleIds.length} DNR removeparam rules`);
|
ubolLog(`Remove ${removeRuleIds.length} DNR removeparam rules`);
|
||||||
}
|
}
|
||||||
if ( addRules.length !== 0 ) {
|
if ( addRules.length !== 0 ) {
|
||||||
console.info(`Add ${addRules.length} DNR removeparam rules`);
|
ubolLog(`Add ${addRules.length} DNR removeparam rules`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dnr.updateDynamicRules({ addRules, removeRuleIds });
|
return dnr.updateDynamicRules({ addRules, removeRuleIds });
|
||||||
@ -322,10 +323,10 @@ async function updateRedirectRules() {
|
|||||||
if ( addRules.length === 0 && removeRuleIds.length === 0 ) { return; }
|
if ( addRules.length === 0 && removeRuleIds.length === 0 ) { return; }
|
||||||
|
|
||||||
if ( removeRuleIds.length !== 0 ) {
|
if ( removeRuleIds.length !== 0 ) {
|
||||||
console.info(`Remove ${removeRuleIds.length} DNR redirect rules`);
|
ubolLog(`Remove ${removeRuleIds.length} DNR redirect rules`);
|
||||||
}
|
}
|
||||||
if ( addRules.length !== 0 ) {
|
if ( addRules.length !== 0 ) {
|
||||||
console.info(`Add ${addRules.length} DNR redirect rules`);
|
ubolLog(`Add ${addRules.length} DNR redirect rules`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dnr.updateDynamicRules({ addRules, removeRuleIds });
|
return dnr.updateDynamicRules({ addRules, removeRuleIds });
|
||||||
@ -394,10 +395,10 @@ async function updateCspRules() {
|
|||||||
if ( addRules.length === 0 && removeRuleIds.length === 0 ) { return; }
|
if ( addRules.length === 0 && removeRuleIds.length === 0 ) { return; }
|
||||||
|
|
||||||
if ( removeRuleIds.length !== 0 ) {
|
if ( removeRuleIds.length !== 0 ) {
|
||||||
console.info(`Remove ${removeRuleIds.length} DNR csp rules`);
|
ubolLog(`Remove ${removeRuleIds.length} DNR csp rules`);
|
||||||
}
|
}
|
||||||
if ( addRules.length !== 0 ) {
|
if ( addRules.length !== 0 ) {
|
||||||
console.info(`Add ${addRules.length} DNR csp rules`);
|
ubolLog(`Add ${addRules.length} DNR csp rules`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dnr.updateDynamicRules({ addRules, removeRuleIds });
|
return dnr.updateDynamicRules({ addRules, removeRuleIds });
|
||||||
@ -482,10 +483,10 @@ async function enableRulesets(ids) {
|
|||||||
const disableRulesetIds = Array.from(disableRulesetSet);
|
const disableRulesetIds = Array.from(disableRulesetSet);
|
||||||
|
|
||||||
if ( enableRulesetIds.length !== 0 ) {
|
if ( enableRulesetIds.length !== 0 ) {
|
||||||
console.info(`Enable rulesets: ${enableRulesetIds}`);
|
ubolLog(`Enable rulesets: ${enableRulesetIds}`);
|
||||||
}
|
}
|
||||||
if ( disableRulesetIds.length !== 0 ) {
|
if ( disableRulesetIds.length !== 0 ) {
|
||||||
console.info(`Disable ruleset: ${disableRulesetIds}`);
|
ubolLog(`Disable ruleset: ${disableRulesetIds}`);
|
||||||
}
|
}
|
||||||
await dnr.updateEnabledRulesets({ enableRulesetIds, disableRulesetIds });
|
await dnr.updateEnabledRulesets({ enableRulesetIds, disableRulesetIds });
|
||||||
|
|
||||||
|
@ -472,21 +472,21 @@ async function registerInjectables(origins) {
|
|||||||
toRemove.push(...Array.from(before.keys()));
|
toRemove.push(...Array.from(before.keys()));
|
||||||
|
|
||||||
if ( toRemove.length !== 0 ) {
|
if ( toRemove.length !== 0 ) {
|
||||||
console.info(`Unregistered ${toRemove} content (css/js)`);
|
ut.ubolLog(`Unregistered ${toRemove} content (css/js)`);
|
||||||
promises.push(
|
promises.push(
|
||||||
browser.scripting.unregisterContentScripts({ ids: toRemove })
|
browser.scripting.unregisterContentScripts({ ids: toRemove })
|
||||||
.catch(reason => { console.info(reason); })
|
.catch(reason => { console.info(reason); })
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ( toAdd.length !== 0 ) {
|
if ( toAdd.length !== 0 ) {
|
||||||
console.info(`Registered ${toAdd.map(v => v.id)} content (css/js)`);
|
ut.ubolLog(`Registered ${toAdd.map(v => v.id)} content (css/js)`);
|
||||||
promises.push(
|
promises.push(
|
||||||
browser.scripting.registerContentScripts(toAdd)
|
browser.scripting.registerContentScripts(toAdd)
|
||||||
.catch(reason => { console.info(reason); })
|
.catch(reason => { console.info(reason); })
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ( toUpdate.length !== 0 ) {
|
if ( toUpdate.length !== 0 ) {
|
||||||
console.info(`Updated ${toUpdate.map(v => v.id)} content (css/js)`);
|
ut.ubolLog(`Updated ${toUpdate.map(v => v.id)} content (css/js)`);
|
||||||
promises.push(
|
promises.push(
|
||||||
browser.scripting.updateContentScripts(toUpdate)
|
browser.scripting.updateContentScripts(toUpdate)
|
||||||
.catch(reason => { console.info(reason); })
|
.catch(reason => { console.info(reason); })
|
||||||
|
@ -135,15 +135,13 @@ for ( const selector of selectors ) {
|
|||||||
|
|
||||||
if ( sheetText.length === 0 ) { return; }
|
if ( sheetText.length === 0 ) { return; }
|
||||||
|
|
||||||
try {
|
(function uBOL_injectCSS(css, count = 10) {
|
||||||
const sheet = new CSSStyleSheet();
|
chrome.runtime.sendMessage({ what: 'insertCSS', css }).catch(( ) => {
|
||||||
sheet.replace(`@layer{${sheetText.join('\n')}}`);
|
count -= 1;
|
||||||
document.adoptedStyleSheets = [
|
if ( count === 0 ) { return; }
|
||||||
...document.adoptedStyleSheets,
|
uBOL_injectCSS(css, count - 1);
|
||||||
sheet
|
});
|
||||||
];
|
})(sheetText.join('\n'));
|
||||||
} catch(ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ const hashFromStr = (type, s) => {
|
|||||||
for ( let i = 0; i < len; i += step ) {
|
for ( let i = 0; i < len; i += step ) {
|
||||||
hash = (hash << 5) + hash ^ s.charCodeAt(i);
|
hash = (hash << 5) + hash ^ s.charCodeAt(i);
|
||||||
}
|
}
|
||||||
return hash & 0xFF_FFFF;
|
return hash & 0xFFFFFF;
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -162,7 +162,8 @@ const uBOL_processNodes = ( ) => {
|
|||||||
if ( styleSheetTimer !== undefined ) { return; }
|
if ( styleSheetTimer !== undefined ) { return; }
|
||||||
styleSheetTimer = self.requestAnimationFrame(( ) => {
|
styleSheetTimer = self.requestAnimationFrame(( ) => {
|
||||||
styleSheetTimer = undefined;
|
styleSheetTimer = undefined;
|
||||||
uBOL_injectStyleSheet();
|
uBOL_injectCSS(`${styleSheetSelectors.join(',')}{display:none!important;}`);
|
||||||
|
styleSheetSelectors.length = 0;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -187,17 +188,12 @@ const uBOL_processChanges = mutations => {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
const uBOL_injectStyleSheet = ( ) => {
|
const uBOL_injectCSS = (css, count = 10) => {
|
||||||
try {
|
chrome.runtime.sendMessage({ what: 'insertCSS', css }).catch(( ) => {
|
||||||
const sheet = new CSSStyleSheet();
|
count -= 1;
|
||||||
sheet.replace(`@layer{${styleSheetSelectors.join(',')}{display:none!important;}}`);
|
if ( count === 0 ) { return; }
|
||||||
document.adoptedStyleSheets = [
|
uBOL_injectCSS(css, count - 1);
|
||||||
...document.adoptedStyleSheets,
|
});
|
||||||
sheet
|
|
||||||
];
|
|
||||||
} catch(ex) {
|
|
||||||
}
|
|
||||||
styleSheetSelectors.length = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -103,16 +103,12 @@ if ( selectors.length === 0 ) { return; }
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
const addStylesheet = text => {
|
const uBOL_injectCSS = (css, count = 10) => {
|
||||||
try {
|
chrome.runtime.sendMessage({ what: 'insertCSS', css }).catch(( ) => {
|
||||||
const sheet = new CSSStyleSheet();
|
count -= 1;
|
||||||
sheet.replace(`@layer{${text}}`);
|
if ( count === 0 ) { return; }
|
||||||
document.adoptedStyleSheets = [
|
uBOL_injectCSS(css, count - 1);
|
||||||
...document.adoptedStyleSheets,
|
});
|
||||||
sheet
|
|
||||||
];
|
|
||||||
} catch(ex) {
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const nonVisualElements = {
|
const nonVisualElements = {
|
||||||
@ -641,9 +637,7 @@ class ProceduralFilterer {
|
|||||||
if ( styleToken !== undefined ) { return styleToken; }
|
if ( styleToken !== undefined ) { return styleToken; }
|
||||||
styleToken = this.randomToken();
|
styleToken = this.randomToken();
|
||||||
this.styleTokenMap.set(style, styleToken);
|
this.styleTokenMap.set(style, styleToken);
|
||||||
addStylesheet(
|
uBOL_injectCSS(`[${this.masterToken}][${styleToken}]\n{${style}}\n`);
|
||||||
`[${this.masterToken}][${styleToken}]\n{${style}}\n`,
|
|
||||||
);
|
|
||||||
return styleToken;
|
return styleToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,15 +103,13 @@ if ( selectors.length === 0 ) { return; }
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
try {
|
(function uBOL_injectCSS(css, count = 10) {
|
||||||
const sheet = new CSSStyleSheet();
|
chrome.runtime.sendMessage({ what: 'insertCSS', css }).catch(( ) => {
|
||||||
sheet.replace(`@layer{${selectors.join(',')}{display:none!important;}}`);
|
count -= 1;
|
||||||
document.adoptedStyleSheets = [
|
if ( count === 0 ) { return; }
|
||||||
...document.adoptedStyleSheets,
|
uBOL_injectCSS(css, count - 1);
|
||||||
sheet
|
});
|
||||||
];
|
})(`${selectors.join(',')}{display:none!important;}`);
|
||||||
} catch(ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
@ -25,6 +25,10 @@
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
import { browser } from './ext.js';
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
function parsedURLromOrigin(origin) {
|
function parsedURLromOrigin(origin) {
|
||||||
try {
|
try {
|
||||||
return new URL(origin);
|
return new URL(origin);
|
||||||
@ -119,6 +123,14 @@ const hostnamesFromMatches = origins => {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
const ubolLog = (...args) => {
|
||||||
|
// Do not pollute dev console in stable release.
|
||||||
|
if ( browser.runtime.id === 'ddkjiahejlhfcafbddmgiahcphecmpfh' ) { return; }
|
||||||
|
console.info(...args);
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
export {
|
export {
|
||||||
parsedURLromOrigin,
|
parsedURLromOrigin,
|
||||||
toBroaderHostname,
|
toBroaderHostname,
|
||||||
@ -128,4 +140,5 @@ export {
|
|||||||
subtractHostnameIters,
|
subtractHostnameIters,
|
||||||
matchesFromHostnames,
|
matchesFromHostnames,
|
||||||
hostnamesFromMatches,
|
hostnamesFromMatches,
|
||||||
|
ubolLog,
|
||||||
};
|
};
|
||||||
|
@ -358,7 +358,6 @@ async function processNetworkFilters(assetDetails, network) {
|
|||||||
// Load all available scriptlets into a key-val map, where the key is the
|
// Load all available scriptlets into a key-val map, where the key is the
|
||||||
// scriptlet token, and val is the whole content of the file.
|
// scriptlet token, and val is the whole content of the file.
|
||||||
|
|
||||||
const scriptletDealiasingMap = new Map();
|
|
||||||
let scriptletsMapPromise;
|
let scriptletsMapPromise;
|
||||||
|
|
||||||
function loadAllSourceScriptlets() {
|
function loadAllSourceScriptlets() {
|
||||||
@ -367,28 +366,20 @@ function loadAllSourceScriptlets() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scriptletsMapPromise = fs.readdir('./scriptlets').then(files => {
|
scriptletsMapPromise = fs.readdir('./scriptlets').then(files => {
|
||||||
const reScriptletNameOrAlias = /^\/\/\/\s+(?:name|alias)\s+(\S+)/gm;
|
const readTemplateFile = file =>
|
||||||
|
fs.readFile(`./scriptlets/${file}`, { encoding: 'utf8' })
|
||||||
|
.then(text => ({ file, text }));
|
||||||
const readPromises = [];
|
const readPromises = [];
|
||||||
for ( const file of files ) {
|
for ( const file of files ) {
|
||||||
readPromises.push(
|
readPromises.push(readTemplateFile(file));
|
||||||
fs.readFile(`./scriptlets/${file}`, { encoding: 'utf8' })
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return Promise.all(readPromises).then(results => {
|
return Promise.all(readPromises).then(results => {
|
||||||
const originalScriptletMap = new Map();
|
const originalScriptletMap = new Map();
|
||||||
for ( const text of results ) {
|
for ( const details of results ) {
|
||||||
const aliasSet = new Set();
|
originalScriptletMap.set(
|
||||||
for (;;) {
|
details.file.replace('.template.js', ''),
|
||||||
const match = reScriptletNameOrAlias.exec(text);
|
details.text
|
||||||
if ( match === null ) { break; }
|
);
|
||||||
aliasSet.add(match[1]);
|
|
||||||
}
|
|
||||||
if ( aliasSet.size === 0 ) { continue; }
|
|
||||||
const aliases = Array.from(aliasSet);
|
|
||||||
originalScriptletMap.set(aliases[0], text);
|
|
||||||
for ( let i = 0; i < aliases.length; i++ ) {
|
|
||||||
scriptletDealiasingMap.set(aliases[i], aliases[0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return originalScriptletMap;
|
return originalScriptletMap;
|
||||||
});
|
});
|
||||||
@ -490,7 +481,7 @@ function groupHostnamesBySelectors(arrayin) {
|
|||||||
const out = Array.from(contentMap).map(a => [
|
const out = Array.from(contentMap).map(a => [
|
||||||
a[0], {
|
a[0], {
|
||||||
a: a[1].a,
|
a: a[1].a,
|
||||||
y: a[1].y ? Array.from(a[1].y).sort(hnSort) : undefined,
|
y: a[1].y ? Array.from(a[1].y).sort(hnSort) : '*',
|
||||||
n: a[1].n ? Array.from(a[1].n) : undefined,
|
n: a[1].n ? Array.from(a[1].n) : undefined,
|
||||||
}
|
}
|
||||||
]).sort((a, b) => {
|
]).sort((a, b) => {
|
||||||
@ -564,7 +555,6 @@ async function processCosmeticFilters(assetDetails, mapin) {
|
|||||||
// The cosmetic filters will be injected programmatically as content
|
// The cosmetic filters will be injected programmatically as content
|
||||||
// script and the decisions to activate the cosmetic filters will be
|
// script and the decisions to activate the cosmetic filters will be
|
||||||
// done at injection time according to the document's hostname.
|
// done at injection time according to the document's hostname.
|
||||||
const originalScriptletMap = await loadAllSourceScriptlets();
|
|
||||||
const generatedFiles = [];
|
const generatedFiles = [];
|
||||||
|
|
||||||
const argsMap = domainBasedEntries.map(entry => [
|
const argsMap = domainBasedEntries.map(entry => [
|
||||||
@ -602,6 +592,7 @@ async function processCosmeticFilters(assetDetails, mapin) {
|
|||||||
argsList[i] = details.a;
|
argsList[i] = details.a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const originalScriptletMap = await loadAllSourceScriptlets();
|
||||||
const patchedScriptlet = originalScriptletMap.get('css-specific')
|
const patchedScriptlet = originalScriptletMap.get('css-specific')
|
||||||
.replace(
|
.replace(
|
||||||
'$rulesetId$',
|
'$rulesetId$',
|
||||||
|
@ -164,7 +164,7 @@ export function compile(details, isTrusted) {
|
|||||||
|
|
||||||
export async function commit(rulesetId, path, writeFn) {
|
export async function commit(rulesetId, path, writeFn) {
|
||||||
const scriptletTemplate = await fs.readFile(
|
const scriptletTemplate = await fs.readFile(
|
||||||
'./scriptlet.template.js',
|
'./scriptlets/scriptlet.template.js',
|
||||||
{ encoding: 'utf8' }
|
{ encoding: 'utf8' }
|
||||||
);
|
);
|
||||||
const patchHnMap = hnmap => {
|
const patchHnMap = hnmap => {
|
||||||
|
@ -27,10 +27,6 @@
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
/// name css-declarative
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
// Important!
|
// Important!
|
||||||
// Isolate from global scope
|
// Isolate from global scope
|
||||||
(function uBOL_cssDeclarativeImport() {
|
(function uBOL_cssDeclarativeImport() {
|
@ -25,10 +25,6 @@
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
/// name css-generic
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
// Important!
|
// Important!
|
||||||
// Isolate from global scope
|
// Isolate from global scope
|
||||||
(function uBOL_cssGenericImport() {
|
(function uBOL_cssGenericImport() {
|
@ -27,10 +27,6 @@
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
/// name css-procedural
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
// Important!
|
// Important!
|
||||||
// Isolate from global scope
|
// Isolate from global scope
|
||||||
(function uBOL_cssProceduralImport() {
|
(function uBOL_cssProceduralImport() {
|
@ -1,51 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
|
|
||||||
uBlock Origin - a browser extension to block requests.
|
|
||||||
Copyright (C) 2019-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 */
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
/// name css-specific.entity
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
// Important!
|
|
||||||
// Isolate from global scope
|
|
||||||
(function uBOL_cssSpecificEntityImport() {
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
// $rulesetId$
|
|
||||||
|
|
||||||
const argsList = self.$argsList$;
|
|
||||||
|
|
||||||
const entitiesMap = new Map(self.$entitiesMap$);
|
|
||||||
|
|
||||||
self.specificEntityImports = self.specificEntityImports || [];
|
|
||||||
self.specificEntityImports.push({ argsList, entitiesMap });
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
})();
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
@ -27,10 +27,6 @@
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
/// name css-specific
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
// Important!
|
// Important!
|
||||||
// Isolate from global scope
|
// Isolate from global scope
|
||||||
(function uBOL_cssSpecificImports() {
|
(function uBOL_cssSpecificImports() {
|
Loading…
Reference in New Issue
Block a user