mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-04 16:47:15 +02:00
[mv3] Add option to disable toolbar icon badge
Related issue: https://github.com/uBlockOrigin/uBOL-home/issues/119
This commit is contained in:
parent
62965cd34f
commit
764a1772ba
@ -154,5 +154,9 @@
|
|||||||
"autoReloadLabel": {
|
"autoReloadLabel": {
|
||||||
"message": "Automatically reload page when changing filtering mode",
|
"message": "Automatically reload page when changing filtering mode",
|
||||||
"description": "Label for a checkbox in the options page"
|
"description": "Label for a checkbox in the options page"
|
||||||
|
},
|
||||||
|
"showBlockedCountLabel": {
|
||||||
|
"message": "Show the number of blocked requests on the toolbar icon",
|
||||||
|
"description": "Label for a checkbox in the options page"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,14 @@ p {
|
|||||||
white-space: pre-line;
|
white-space: pre-line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
section > div {
|
||||||
|
padding: 0 var(--default-gap-xxsmall);
|
||||||
|
}
|
||||||
|
|
||||||
|
#showBlockedCount:has(input[type="checkbox"][disabled]) {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
#defaultFilteringMode {
|
#defaultFilteringMode {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 1em;
|
gap: 1em;
|
||||||
|
@ -25,6 +25,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- -------- -->
|
<!-- -------- -->
|
||||||
<section data-pane="settings">
|
<section data-pane="settings">
|
||||||
|
<div>
|
||||||
|
<h3 data-i18n="behaviorSectionLabel"></h3>
|
||||||
|
<p><label id="autoReload" data-i18n="autoReloadLabel"><span class="input checkbox"><input type="checkbox"><svg viewBox="0 0 24 24"><path d="M1.73,12.91 8.1,19.28 22.79,4.59"/></svg></span>_</label>
|
||||||
|
</p>
|
||||||
|
<p><label id="showBlockedCount" data-i18n="showBlockedCountLabel"><span class="input checkbox"><input type="checkbox"><svg viewBox="0 0 24 24"><path d="M1.73,12.91 8.1,19.28 22.79,4.59"/></svg></span>_</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="firstRun">
|
<div class="firstRun">
|
||||||
<h3 data-i18n="firstRunSectionLabel"></h3>
|
<h3 data-i18n="firstRunSectionLabel"></h3>
|
||||||
<p data-i18n="firstRunDescription"></p>
|
<p data-i18n="firstRunDescription"></p>
|
||||||
@ -89,12 +96,6 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
|
||||||
<h3 data-i18n="behaviorSectionLabel"></h3>
|
|
||||||
<p><label id="autoReload" data-i18n="autoReloadLabel"><span class="input checkbox"><input type="checkbox"><svg viewBox="0 0 24 24"><path d="M1.73,12.91 8.1,19.28 22.79,4.59"/></svg></span>_</label>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h3 data-i18n="aboutFilterLists"></h3>
|
<h3 data-i18n="aboutFilterLists"></h3>
|
||||||
<div>
|
<div>
|
||||||
|
@ -19,58 +19,57 @@
|
|||||||
Home: https://github.com/gorhill/uBlock
|
Home: https://github.com/gorhill/uBlock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* jshint esversion:11 */
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
adminRead,
|
||||||
browser,
|
browser,
|
||||||
dnr,
|
dnr,
|
||||||
runtime,
|
|
||||||
localRead, localWrite,
|
localRead, localWrite,
|
||||||
|
runtime,
|
||||||
sessionRead, sessionWrite,
|
sessionRead, sessionWrite,
|
||||||
adminRead,
|
|
||||||
} from './ext.js';
|
} from './ext.js';
|
||||||
|
|
||||||
import {
|
|
||||||
getRulesetDetails,
|
|
||||||
defaultRulesetsFromLanguage,
|
|
||||||
enableRulesets,
|
|
||||||
getEnabledRulesetsDetails,
|
|
||||||
updateDynamicRules,
|
|
||||||
} from './ruleset-manager.js';
|
|
||||||
|
|
||||||
import {
|
|
||||||
registerInjectables,
|
|
||||||
} from './scripting-manager.js';
|
|
||||||
|
|
||||||
import {
|
|
||||||
getFilteringMode,
|
|
||||||
setFilteringMode,
|
|
||||||
getDefaultFilteringMode,
|
|
||||||
setDefaultFilteringMode,
|
|
||||||
getTrustedSites,
|
|
||||||
setTrustedSites,
|
|
||||||
syncWithBrowserPermissions,
|
|
||||||
} from './mode-manager.js';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
broadcastMessage,
|
broadcastMessage,
|
||||||
ubolLog,
|
ubolLog,
|
||||||
} from './utils.js';
|
} from './utils.js';
|
||||||
|
|
||||||
|
import {
|
||||||
|
defaultRulesetsFromLanguage,
|
||||||
|
enableRulesets,
|
||||||
|
getEnabledRulesetsDetails,
|
||||||
|
getRulesetDetails,
|
||||||
|
updateDynamicRules,
|
||||||
|
} from './ruleset-manager.js';
|
||||||
|
|
||||||
|
import {
|
||||||
|
getDefaultFilteringMode,
|
||||||
|
getFilteringMode,
|
||||||
|
getTrustedSites,
|
||||||
|
setDefaultFilteringMode,
|
||||||
|
setFilteringMode,
|
||||||
|
setTrustedSites,
|
||||||
|
syncWithBrowserPermissions,
|
||||||
|
} from './mode-manager.js';
|
||||||
|
|
||||||
|
import {
|
||||||
|
registerInjectables,
|
||||||
|
} from './scripting-manager.js';
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
const rulesetConfig = {
|
const rulesetConfig = {
|
||||||
version: '',
|
version: '',
|
||||||
enabledRulesets: [ 'default' ],
|
enabledRulesets: [ 'default' ],
|
||||||
autoReload: true,
|
autoReload: true,
|
||||||
|
showBlockedCount: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const UBOL_ORIGIN = runtime.getURL('').replace(/\/$/, '');
|
const UBOL_ORIGIN = runtime.getURL('').replace(/\/$/, '');
|
||||||
|
|
||||||
|
const canShowBlockedCount = typeof dnr.setExtensionActionOptions === 'function';
|
||||||
|
|
||||||
let firstRun = false;
|
let firstRun = false;
|
||||||
let wakeupRun = false;
|
let wakeupRun = false;
|
||||||
|
|
||||||
@ -85,7 +84,12 @@ async function loadRulesetConfig() {
|
|||||||
if ( data ) {
|
if ( data ) {
|
||||||
rulesetConfig.version = data.version;
|
rulesetConfig.version = data.version;
|
||||||
rulesetConfig.enabledRulesets = data.enabledRulesets;
|
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;
|
wakeupRun = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -93,7 +97,12 @@ async function loadRulesetConfig() {
|
|||||||
if ( data ) {
|
if ( data ) {
|
||||||
rulesetConfig.version = data.version;
|
rulesetConfig.version = data.version;
|
||||||
rulesetConfig.enabledRulesets = data.enabledRulesets;
|
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);
|
sessionWrite('rulesetConfig', rulesetConfig);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -201,6 +210,8 @@ function onMessage(request, sender, callback) {
|
|||||||
maxNumberOfEnabledRulesets: dnr.MAX_NUMBER_OF_ENABLED_STATIC_RULESETS,
|
maxNumberOfEnabledRulesets: dnr.MAX_NUMBER_OF_ENABLED_STATIC_RULESETS,
|
||||||
rulesetDetails: Array.from(rulesetDetails.values()),
|
rulesetDetails: Array.from(rulesetDetails.values()),
|
||||||
autoReload: rulesetConfig.autoReload,
|
autoReload: rulesetConfig.autoReload,
|
||||||
|
showBlockedCount: rulesetConfig.showBlockedCount,
|
||||||
|
canShowBlockedCount,
|
||||||
firstRun,
|
firstRun,
|
||||||
});
|
});
|
||||||
firstRun = false;
|
firstRun = false;
|
||||||
@ -216,6 +227,19 @@ function onMessage(request, sender, callback) {
|
|||||||
});
|
});
|
||||||
return true;
|
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': {
|
case 'popupPanelData': {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
getFilteringMode(request.hostname),
|
getFilteringMode(request.hostname),
|
||||||
@ -329,8 +353,10 @@ async function start() {
|
|||||||
|
|
||||||
// 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
|
||||||
// Firefox API does not support `dnr.setExtensionActionOptions`
|
// Firefox API does not support `dnr.setExtensionActionOptions`
|
||||||
if ( wakeupRun === false && dnr.setExtensionActionOptions ) {
|
if ( wakeupRun === false && canShowBlockedCount ) {
|
||||||
dnr.setExtensionActionOptions({ displayActionCountAsBadgeText: true });
|
dnr.setExtensionActionOptions({
|
||||||
|
displayActionCountAsBadgeText: rulesetConfig.showBlockedCount,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime.onMessage.addListener(onMessage);
|
runtime.onMessage.addListener(onMessage);
|
||||||
|
@ -19,11 +19,9 @@
|
|||||||
Home: https://github.com/gorhill/uBlock
|
Home: https://github.com/gorhill/uBlock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
import { browser, localRead, localWrite, sendMessage } from './ext.js';
|
||||||
|
|
||||||
import { browser, sendMessage, localRead, localWrite } from './ext.js';
|
|
||||||
import { i18n$, i18n } from './i18n.js';
|
|
||||||
import { dom, qs$, qsa$ } from './dom.js';
|
import { dom, qs$, qsa$ } from './dom.js';
|
||||||
|
import { i18n, i18n$ } from './i18n.js';
|
||||||
import punycode from './punycode.js';
|
import punycode from './punycode.js';
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -211,7 +209,17 @@ function renderWidgets() {
|
|||||||
renderDefaultMode();
|
renderDefaultMode();
|
||||||
renderTrustedSites();
|
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
|
// Compute total counts
|
||||||
let rulesetCount = 0;
|
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({
|
sendMessage({
|
||||||
what: 'setAutoReload',
|
what: 'setAutoReload',
|
||||||
state: ev.target.checked,
|
state: ev.target.checked,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dom.on('#showBlockedCount input[type="checkbox"]', 'change', ev => {
|
||||||
|
sendMessage({
|
||||||
|
what: 'setShowBlockedCount',
|
||||||
|
state: ev.target.checked,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
function renderTrustedSites() {
|
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 ( message.enabledRulesets !== undefined ) {
|
||||||
if ( hashFromIterable(message.enabledRulesets) !== hashFromIterable(local.enabledRulesets) ) {
|
if ( hashFromIterable(message.enabledRulesets) !== hashFromIterable(local.enabledRulesets) ) {
|
||||||
local.enabledRulesets = message.enabledRulesets;
|
local.enabledRulesets = message.enabledRulesets;
|
||||||
|
Loading…
Reference in New Issue
Block a user