summaryrefslogtreecommitdiffstats
path: root/platform/mv3/extension/js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 05:50:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 05:50:18 +0000
commit55a5d29a66503248916f249ad2a1d8b37cde5a03 (patch)
treea3beb6a90dd3bdaaf67ecb05d42152a494aff946 /platform/mv3/extension/js
parentAdding upstream version 1.55.0+dfsg. (diff)
downloadublock-origin-55a5d29a66503248916f249ad2a1d8b37cde5a03.tar.xz
ublock-origin-55a5d29a66503248916f249ad2a1d8b37cde5a03.zip
Adding upstream version 1.57.0+dfsg.upstream/1.57.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'platform/mv3/extension/js')
-rw-r--r--platform/mv3/extension/js/background.js68
-rw-r--r--platform/mv3/extension/js/mode-manager.js45
-rw-r--r--platform/mv3/extension/js/scripting/css-procedural.js41
-rw-r--r--platform/mv3/extension/js/settings.js34
-rw-r--r--platform/mv3/extension/js/utils.js15
5 files changed, 160 insertions, 43 deletions
diff --git a/platform/mv3/extension/js/background.js b/platform/mv3/extension/js/background.js
index 5ceacc4..e65775e 100644
--- a/platform/mv3/extension/js/background.js
+++ b/platform/mv3/extension/js/background.js
@@ -19,47 +19,43 @@
Home: https://github.com/gorhill/uBlock
*/
-/* jshint esversion:11 */
-
-'use strict';
-
/******************************************************************************/
import {
+ adminRead,
browser,
dnr,
- runtime,
localRead, localWrite,
+ runtime,
sessionRead, sessionWrite,
- adminRead,
} from './ext.js';
import {
- getRulesetDetails,
+ broadcastMessage,
+ ubolLog,
+} from './utils.js';
+
+import {
defaultRulesetsFromLanguage,
enableRulesets,
getEnabledRulesetsDetails,
+ getRulesetDetails,
updateDynamicRules,
} from './ruleset-manager.js';
import {
- registerInjectables,
-} from './scripting-manager.js';
-
-import {
- getFilteringMode,
- setFilteringMode,
getDefaultFilteringMode,
- setDefaultFilteringMode,
+ getFilteringMode,
getTrustedSites,
+ setDefaultFilteringMode,
+ setFilteringMode,
setTrustedSites,
syncWithBrowserPermissions,
} from './mode-manager.js';
import {
- broadcastMessage,
- ubolLog,
-} from './utils.js';
+ registerInjectables,
+} from './scripting-manager.js';
/******************************************************************************/
@@ -67,10 +63,13 @@ const rulesetConfig = {
version: '',
enabledRulesets: [ 'default' ],
autoReload: true,
+ showBlockedCount: true,
};
const UBOL_ORIGIN = runtime.getURL('').replace(/\/$/, '');
+const canShowBlockedCount = typeof dnr.setExtensionActionOptions === 'function';
+
let firstRun = false;
let wakeupRun = false;
@@ -85,7 +84,12 @@ async function loadRulesetConfig() {
if ( data ) {
rulesetConfig.version = data.version;
rulesetConfig.enabledRulesets = data.enabledRulesets;
- rulesetConfig.autoReload = data.autoReload && true || false;
+ rulesetConfig.autoReload = typeof data.autoReload === 'boolean'
+ ? data.autoReload
+ : true;
+ rulesetConfig.showBlockedCount = typeof data.showBlockedCount === 'boolean'
+ ? data.showBlockedCount
+ : true;
wakeupRun = true;
return;
}
@@ -93,7 +97,12 @@ async function loadRulesetConfig() {
if ( data ) {
rulesetConfig.version = data.version;
rulesetConfig.enabledRulesets = data.enabledRulesets;
- rulesetConfig.autoReload = data.autoReload && true || false;
+ rulesetConfig.autoReload = typeof data.autoReload === 'boolean'
+ ? data.autoReload
+ : true;
+ rulesetConfig.showBlockedCount = typeof data.showBlockedCount === 'boolean'
+ ? data.showBlockedCount
+ : true;
sessionWrite('rulesetConfig', rulesetConfig);
return;
}
@@ -201,6 +210,8 @@ function onMessage(request, sender, callback) {
maxNumberOfEnabledRulesets: dnr.MAX_NUMBER_OF_ENABLED_STATIC_RULESETS,
rulesetDetails: Array.from(rulesetDetails.values()),
autoReload: rulesetConfig.autoReload,
+ showBlockedCount: rulesetConfig.showBlockedCount,
+ canShowBlockedCount,
firstRun,
});
firstRun = false;
@@ -216,6 +227,19 @@ function onMessage(request, sender, callback) {
});
return true;
+ case 'setShowBlockedCount':
+ rulesetConfig.showBlockedCount = request.state && true || false;
+ if ( canShowBlockedCount ) {
+ dnr.setExtensionActionOptions({
+ displayActionCountAsBadgeText: rulesetConfig.showBlockedCount,
+ });
+ }
+ saveRulesetConfig().then(( ) => {
+ callback();
+ broadcastMessage({ showBlockedCount: rulesetConfig.showBlockedCount });
+ });
+ return true;
+
case 'popupPanelData': {
Promise.all([
getFilteringMode(request.hostname),
@@ -329,8 +353,10 @@ async function start() {
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/declarativeNetRequest
// Firefox API does not support `dnr.setExtensionActionOptions`
- if ( wakeupRun === false && dnr.setExtensionActionOptions ) {
- dnr.setExtensionActionOptions({ displayActionCountAsBadgeText: true });
+ if ( wakeupRun === false && canShowBlockedCount ) {
+ dnr.setExtensionActionOptions({
+ displayActionCountAsBadgeText: rulesetConfig.showBlockedCount,
+ });
}
runtime.onMessage.addListener(onMessage);
diff --git a/platform/mv3/extension/js/mode-manager.js b/platform/mv3/extension/js/mode-manager.js
index bc76199..e75dbee 100644
--- a/platform/mv3/extension/js/mode-manager.js
+++ b/platform/mv3/extension/js/mode-manager.js
@@ -288,34 +288,53 @@ async function writeFilteringModeDetails(afterDetails) {
async function filteringModesToDNR(modes) {
const dynamicRuleMap = await getDynamicRules();
- const presentRule = dynamicRuleMap.get(TRUSTED_DIRECTIVE_BASE_RULE_ID);
+ const presentRule = dynamicRuleMap.get(TRUSTED_DIRECTIVE_BASE_RULE_ID+0);
const presentNone = new Set(
presentRule && presentRule.condition.requestDomains
);
if ( eqSets(presentNone, modes.none) ) { return; }
const removeRuleIds = [];
if ( presentRule !== undefined ) {
- removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID);
- dynamicRuleMap.delete(TRUSTED_DIRECTIVE_BASE_RULE_ID);
+ removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID+0);
+ removeRuleIds.push(TRUSTED_DIRECTIVE_BASE_RULE_ID+1);
+ dynamicRuleMap.delete(TRUSTED_DIRECTIVE_BASE_RULE_ID+0);
+ dynamicRuleMap.delete(TRUSTED_DIRECTIVE_BASE_RULE_ID+1);
}
const addRules = [];
- if ( modes.none.size !== 0 ) {
- const rule = {
- id: TRUSTED_DIRECTIVE_BASE_RULE_ID,
+ const noneHostnames = [ ...modes.none ];
+ const notNoneHostnames = [ ...modes.basic, ...modes.optimal, ...modes.complete ];
+ if ( noneHostnames.length !== 0 ) {
+ const rule0 = {
+ id: TRUSTED_DIRECTIVE_BASE_RULE_ID+0,
action: { type: 'allowAllRequests' },
condition: {
resourceTypes: [ 'main_frame' ],
},
priority: 100,
};
- if (
- modes.none.size !== 1 ||
- modes.none.has('all-urls') === false
- ) {
- rule.condition.requestDomains = Array.from(modes.none);
+ if ( modes.none.has('all-urls') === false ) {
+ rule0.condition.requestDomains = noneHostnames.slice();
+ } else if ( notNoneHostnames.length !== 0 ) {
+ rule0.condition.excludedRequestDomains = notNoneHostnames.slice();
}
- addRules.push(rule);
- dynamicRuleMap.set(TRUSTED_DIRECTIVE_BASE_RULE_ID, rule);
+ addRules.push(rule0);
+ dynamicRuleMap.set(TRUSTED_DIRECTIVE_BASE_RULE_ID+0, rule0);
+ // https://github.com/uBlockOrigin/uBOL-home/issues/114
+ const rule1 = {
+ id: TRUSTED_DIRECTIVE_BASE_RULE_ID+1,
+ action: { type: 'allow' },
+ condition: {
+ resourceTypes: [ 'script' ],
+ },
+ priority: 100,
+ };
+ if ( modes.none.has('all-urls') === false ) {
+ rule1.condition.initiatorDomains = noneHostnames.slice();
+ } else if ( notNoneHostnames.length !== 0 ) {
+ rule1.condition.excludedInitiatorDomains = notNoneHostnames.slice();
+ }
+ addRules.push(rule1);
+ dynamicRuleMap.set(TRUSTED_DIRECTIVE_BASE_RULE_ID+1, rule1);
}
const updateOptions = {};
if ( addRules.length ) {
diff --git a/platform/mv3/extension/js/scripting/css-procedural.js b/platform/mv3/extension/js/scripting/css-procedural.js
index 818e697..7f50f80 100644
--- a/platform/mv3/extension/js/scripting/css-procedural.js
+++ b/platform/mv3/extension/js/scripting/css-procedural.js
@@ -341,6 +341,38 @@ class PSelectorOthersTask extends PSelectorTask {
/******************************************************************************/
+class PSelectorShadowTask extends PSelectorTask {
+ constructor(task) {
+ super();
+ this.selector = task[1];
+ }
+ transpose(node, output) {
+ const root = this.openOrClosedShadowRoot(node);
+ if ( root === null ) { return; }
+ const nodes = root.querySelectorAll(this.selector);
+ output.push(...nodes);
+ }
+ get openOrClosedShadowRoot() {
+ if ( PSelectorShadowTask.openOrClosedShadowRoot !== undefined ) {
+ return PSelectorShadowTask.openOrClosedShadowRoot;
+ }
+ if ( typeof chrome === 'object' && chrome !== null ) {
+ if ( chrome.dom instanceof Object ) {
+ if ( typeof chrome.dom.openOrClosedShadowRoot === 'function' ) {
+ PSelectorShadowTask.openOrClosedShadowRoot =
+ chrome.dom.openOrClosedShadowRoot;
+ return PSelectorShadowTask.openOrClosedShadowRoot;
+ }
+ }
+ }
+ PSelectorShadowTask.openOrClosedShadowRoot = node =>
+ node.openOrClosedShadowRoot || null;
+ return PSelectorShadowTask.openOrClosedShadowRoot;
+ }
+}
+
+/******************************************************************************/
+
// https://github.com/AdguardTeam/ExtendedCss/issues/31#issuecomment-302391277
// Prepend `:scope ` if needed.
class PSelectorSpathTask extends PSelectorTask {
@@ -471,7 +503,6 @@ class PSelectorXpathTask extends PSelectorTask {
class PSelector {
constructor(o) {
- this.raw = o.raw;
this.selector = o.selector;
this.tasks = [];
const tasks = [];
@@ -542,6 +573,7 @@ PSelector.prototype.operatorToTaskMap = new Map([
[ 'min-text-length', PSelectorMinTextLengthTask ],
[ 'not', PSelectorIfNotTask ],
[ 'others', PSelectorOthersTask ],
+ [ 'shadow', PSelectorShadowTask ],
[ 'spath', PSelectorSpathTask ],
[ 'upward', PSelectorUpwardTask ],
[ 'watch-attr', PSelectorWatchAttrs ],
@@ -566,6 +598,13 @@ class PSelectorRoot extends PSelector {
}
return [];
}
+ exec(input) {
+ try {
+ return super.exec(input);
+ } catch (ex) {
+ }
+ return [];
+ }
}
/******************************************************************************/
diff --git a/platform/mv3/extension/js/settings.js b/platform/mv3/extension/js/settings.js
index 1a95ac0..6f50055 100644
--- a/platform/mv3/extension/js/settings.js
+++ b/platform/mv3/extension/js/settings.js
@@ -19,11 +19,9 @@
Home: https://github.com/gorhill/uBlock
*/
-'use strict';
-
-import { browser, sendMessage, localRead, localWrite } from './ext.js';
-import { i18n$, i18n } from './i18n.js';
+import { browser, localRead, localWrite, sendMessage } from './ext.js';
import { dom, qs$, qsa$ } from './dom.js';
+import { i18n, i18n$ } from './i18n.js';
import punycode from './punycode.js';
/******************************************************************************/
@@ -211,7 +209,17 @@ function renderWidgets() {
renderDefaultMode();
renderTrustedSites();
- qs$('#autoReload input[type="checkbox"').checked = cachedRulesetData.autoReload;
+ qs$('#autoReload input[type="checkbox"]').checked = cachedRulesetData.autoReload;
+
+ {
+ const input = qs$('#showBlockedCount input[type="checkbox"]');
+ if ( cachedRulesetData.canShowBlockedCount ) {
+ input.checked = cachedRulesetData.showBlockedCount;
+ } else {
+ input.checked = false;
+ dom.attr(input, 'disabled', '');
+ }
+ }
// Compute total counts
let rulesetCount = 0;
@@ -290,13 +298,20 @@ dom.on(
/******************************************************************************/
-dom.on('#autoReload input[type="checkbox"', 'change', ev => {
+dom.on('#autoReload input[type="checkbox"]', 'change', ev => {
sendMessage({
what: 'setAutoReload',
state: ev.target.checked,
});
});
+dom.on('#showBlockedCount input[type="checkbox"]', 'change', ev => {
+ sendMessage({
+ what: 'setShowBlockedCount',
+ state: ev.target.checked,
+ });
+});
+
/******************************************************************************/
function renderTrustedSites() {
@@ -455,6 +470,13 @@ bc.onmessage = ev => {
}
}
+ if ( message.showBlockedCount !== undefined ) {
+ if ( message.showBlockedCount !== local.showBlockedCount ) {
+ local.showBlockedCount = message.showBlockedCount;
+ render = true;
+ }
+ }
+
if ( message.enabledRulesets !== undefined ) {
if ( hashFromIterable(message.enabledRulesets) !== hashFromIterable(local.enabledRulesets) ) {
local.enabledRulesets = message.enabledRulesets;
diff --git a/platform/mv3/extension/js/utils.js b/platform/mv3/extension/js/utils.js
index b1a463a..cadeaea 100644
--- a/platform/mv3/extension/js/utils.js
+++ b/platform/mv3/extension/js/utils.js
@@ -131,11 +131,22 @@ export const broadcastMessage = message => {
/******************************************************************************/
const ubolLog = (...args) => {
- // Do not pollute dev console in stable release.
- if ( browser.runtime.id === 'ddkjiahejlhfcafbddmgiahcphecmpfh' ) { return; }
+ // Do not pollute dev console in stable releases.
+ if ( shouldLog !== true ) { return; }
console.info('[uBOL]', ...args);
};
+const shouldLog = (( ) => {
+ const { id } = browser.runtime;
+ // https://addons.mozilla.org/en-US/firefox/addon/ublock-origin-lite/
+ if ( id === 'uBOLite@raymondhill.net' ) { return false; }
+ // https://chromewebstore.google.com/detail/ddkjiahejlhfcafbddmgiahcphecmpfh
+ if ( id === 'ddkjiahejlhfcafbddmgiahcphecmpfh' ) { return false; }
+ // https://microsoftedge.microsoft.com/addons/detail/cimighlppcgcoapaliogpjjdehbnofhn
+ if ( id === 'cimighlppcgcoapaliogpjjdehbnofhn' ) { return false; }
+ return true;
+})();
+
/******************************************************************************/
export {