From 936444883fde6f3fae3ff3e95115e380784b52fc Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 12 Jan 2024 12:01:23 -0500 Subject: [PATCH] Add support to toggle no-scripting switch with keyboard shortcut Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/692 --- platform/chromium/manifest.json | 3 +++ src/_locales/en/messages.json | 4 ++++ src/js/commands.js | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/platform/chromium/manifest.json b/platform/chromium/manifest.json index 28ceec5d0a2b8..352dc57c5ea35 100644 --- a/platform/chromium/manifest.json +++ b/platform/chromium/manifest.json @@ -30,6 +30,9 @@ }, "toggle-cosmetic-filtering": { "description": "__MSG_toggleCosmeticFiltering__" + }, + "toggle-javascript": { + "description": "__MSG_toggleJavascript__" } }, "content_scripts": [ diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index b894121789e2e..e49503c25b7a4 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -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" diff --git a/src/js/commands.js b/src/js/commands.js index 8fd6341f6854e..0c862d078c94d 100644 --- a/src/js/commands.js +++ b/src/js/commands.js @@ -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; }