mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 01:02:08 +01:00
Add command to toggle cosmetic filtering
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/2000
This commit is contained in:
parent
db5d598b59
commit
ad1800fbca
6 changed files with 39 additions and 21 deletions
|
@ -26,6 +26,9 @@
|
||||||
},
|
},
|
||||||
"relax-blocking-mode": {
|
"relax-blocking-mode": {
|
||||||
"description": "__MSG_relaxBlockingMode__"
|
"description": "__MSG_relaxBlockingMode__"
|
||||||
|
},
|
||||||
|
"toggle-cosmetic-filtering": {
|
||||||
|
"description": "__MSG_toggleCosmeticFiltering__"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
|
|
|
@ -35,6 +35,9 @@
|
||||||
},
|
},
|
||||||
"relax-blocking-mode": {
|
"relax-blocking-mode": {
|
||||||
"description": "__MSG_relaxBlockingMode__"
|
"description": "__MSG_relaxBlockingMode__"
|
||||||
|
},
|
||||||
|
"toggle-cosmetic-filtering": {
|
||||||
|
"description": "__MSG_toggleCosmeticFiltering__"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
},
|
},
|
||||||
"relax-blocking-mode": {
|
"relax-blocking-mode": {
|
||||||
"description": "__MSG_relaxBlockingMode__"
|
"description": "__MSG_relaxBlockingMode__"
|
||||||
|
},
|
||||||
|
"toggle-cosmetic-filtering": {
|
||||||
|
"description": "__MSG_toggleCosmeticFiltering__"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
|
|
|
@ -1221,13 +1221,13 @@
|
||||||
"message": "Select all",
|
"message": "Select all",
|
||||||
"description": "Label for buttons used to select all text in editor"
|
"description": "Label for buttons used to select all text in editor"
|
||||||
},
|
},
|
||||||
"toggleBlockingProfile": {
|
"toggleCosmeticFiltering": {
|
||||||
"message": "Toggle blocking profile",
|
"message": "Toggle cosmetic filtering",
|
||||||
"description": "Label for keyboard shortcut used to toggle blocking profile"
|
"description": "Label for keyboard shortcut used to toggle cosmetic filtering"
|
||||||
},
|
},
|
||||||
"relaxBlockingMode": {
|
"relaxBlockingMode": {
|
||||||
"message": "Relax blocking mode",
|
"message": "Relax blocking mode",
|
||||||
"description": "Label for keyboard shortcut used to relax blocking mode (meant to replace 'Toggle blocking profile')"
|
"description": "Label for keyboard shortcut used to relax blocking mode"
|
||||||
},
|
},
|
||||||
"storageUsed": {
|
"storageUsed": {
|
||||||
"message": "Storage used: {{value}} {{unit}}",
|
"message": "Storage used: {{value}} {{unit}}",
|
||||||
|
|
|
@ -160,11 +160,21 @@ const relaxBlockingMode = (( ) => {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
vAPI.commands.onCommand.addListener(async command => {
|
vAPI.commands.onCommand.addListener(async command => {
|
||||||
|
// Generic commands
|
||||||
|
if ( command === 'open-dashboard' ) {
|
||||||
|
µb.openNewTab({
|
||||||
|
url: 'dashboard.html',
|
||||||
|
select: true,
|
||||||
|
index: -1,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Tab-specific commands
|
||||||
|
const tab = await vAPI.tabs.getCurrent();
|
||||||
|
if ( tab instanceof Object === false ) { return; }
|
||||||
switch ( command ) {
|
switch ( command ) {
|
||||||
case 'launch-element-picker':
|
case 'launch-element-picker':
|
||||||
case 'launch-element-zapper': {
|
case 'launch-element-zapper': {
|
||||||
const tab = await vAPI.tabs.getCurrent();
|
|
||||||
if ( tab instanceof Object === false ) { return; }
|
|
||||||
µb.epickerArgs.mouse = false;
|
µb.epickerArgs.mouse = false;
|
||||||
µb.elementPickerExec(
|
µb.elementPickerExec(
|
||||||
tab.id,
|
tab.id,
|
||||||
|
@ -175,8 +185,6 @@ vAPI.commands.onCommand.addListener(async command => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'launch-logger': {
|
case 'launch-logger': {
|
||||||
const tab = await vAPI.tabs.getCurrent();
|
|
||||||
if ( tab instanceof Object === false ) { return; }
|
|
||||||
const hash = tab.url.startsWith(vAPI.getURL(''))
|
const hash = tab.url.startsWith(vAPI.getURL(''))
|
||||||
? ''
|
? ''
|
||||||
: `#_+${tab.id}`;
|
: `#_+${tab.id}`;
|
||||||
|
@ -187,16 +195,14 @@ vAPI.commands.onCommand.addListener(async command => {
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'open-dashboard': {
|
|
||||||
µb.openNewTab({
|
|
||||||
url: 'dashboard.html',
|
|
||||||
select: true,
|
|
||||||
index: -1,
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'relax-blocking-mode':
|
case 'relax-blocking-mode':
|
||||||
relaxBlockingMode(await vAPI.tabs.getCurrent());
|
relaxBlockingMode(tab);
|
||||||
|
break;
|
||||||
|
case 'toggle-cosmetic-filtering':
|
||||||
|
µb.toggleHostnameSwitch({
|
||||||
|
name: 'no-cosmetic-filtering',
|
||||||
|
hostname: hostnameFromURI(µb.normalizeTabURL(tab.id, tab.url)),
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -566,11 +566,14 @@ const matchBucket = function(url, hostname, bucket, start) {
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
µb.toggleHostnameSwitch = function(details) {
|
µb.toggleHostnameSwitch = function(details) {
|
||||||
|
const newState = typeof details.state === 'boolean'
|
||||||
|
? details.state
|
||||||
|
: sessionSwitches.evaluateZ(details.name, details.hostname) === false;
|
||||||
let changed = sessionSwitches.toggleZ(
|
let changed = sessionSwitches.toggleZ(
|
||||||
details.name,
|
details.name,
|
||||||
details.hostname,
|
details.hostname,
|
||||||
!!details.deep,
|
!!details.deep,
|
||||||
details.state
|
newState
|
||||||
);
|
);
|
||||||
if ( changed === false ) { return; }
|
if ( changed === false ) { return; }
|
||||||
|
|
||||||
|
@ -580,7 +583,7 @@ const matchBucket = function(url, hostname, bucket, start) {
|
||||||
this.updateToolbarIcon(details.tabId, 0b100);
|
this.updateToolbarIcon(details.tabId, 0b100);
|
||||||
break;
|
break;
|
||||||
case 'no-cosmetic-filtering': {
|
case 'no-cosmetic-filtering': {
|
||||||
const scriptlet = details.state ? 'cosmetic-off' : 'cosmetic-on';
|
const scriptlet = newState ? 'cosmetic-off' : 'cosmetic-on';
|
||||||
vAPI.tabs.executeScript(details.tabId, {
|
vAPI.tabs.executeScript(details.tabId, {
|
||||||
file: `/js/scriptlets/${scriptlet}.js`,
|
file: `/js/scriptlets/${scriptlet}.js`,
|
||||||
allFrames: true,
|
allFrames: true,
|
||||||
|
@ -590,7 +593,7 @@ const matchBucket = function(url, hostname, bucket, start) {
|
||||||
case 'no-large-media':
|
case 'no-large-media':
|
||||||
const pageStore = this.pageStoreFromTabId(details.tabId);
|
const pageStore = this.pageStoreFromTabId(details.tabId);
|
||||||
if ( pageStore !== null ) {
|
if ( pageStore !== null ) {
|
||||||
pageStore.temporarilyAllowLargeMediaElements(!details.state);
|
pageStore.temporarilyAllowLargeMediaElements(!newState);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -601,7 +604,7 @@ const matchBucket = function(url, hostname, bucket, start) {
|
||||||
details.name,
|
details.name,
|
||||||
details.hostname,
|
details.hostname,
|
||||||
!!details.deep,
|
!!details.deep,
|
||||||
details.state
|
newState
|
||||||
);
|
);
|
||||||
if ( changed ) {
|
if ( changed ) {
|
||||||
this.saveHostnameSwitches();
|
this.saveHostnameSwitches();
|
||||||
|
|
Loading…
Reference in a new issue