Add support to toggle no-scripting switch with keyboard shortcut

Related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/692
This commit is contained in:
Raymond Hill 2024-01-12 12:01:23 -05:00
parent c03c23d962
commit 936444883f
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
3 changed files with 15 additions and 0 deletions

View file

@ -30,6 +30,9 @@
},
"toggle-cosmetic-filtering": {
"description": "__MSG_toggleCosmeticFiltering__"
},
"toggle-javascript": {
"description": "__MSG_toggleJavascript__"
}
},
"content_scripts": [

View file

@ -1253,6 +1253,10 @@
"message": "Toggle cosmetic filtering",
"description": "Label for keyboard shortcut used to toggle cosmetic filtering"
},
"toggleJavascript": {
"message": "Toggle JavaScript",
"description": "Label for keyboard shortcut used to toggle no-scripting switch"
},
"relaxBlockingMode": {
"message": "Relax blocking mode",
"description": "Label for keyboard shortcut used to relax blocking mode"

View file

@ -136,6 +136,7 @@ vAPI.commands.onCommand.addListener(async command => {
// Tab-specific commands
const tab = await vAPI.tabs.getCurrent();
if ( tab instanceof Object === false ) { return; }
switch ( command ) {
case 'launch-element-picker':
case 'launch-element-zapper': {
@ -168,6 +169,13 @@ vAPI.commands.onCommand.addListener(async command => {
hostname: hostnameFromURI(µb.normalizeTabURL(tab.id, tab.url)),
});
break;
case 'toggle-javascript':
µb.toggleHostnameSwitch({
name: 'no-scripting',
hostname: hostnameFromURI(µb.normalizeTabURL(tab.id, tab.url)),
});
vAPI.tabs.reload(tab.id);
break;
default:
break;
}