Remove Shortcuts when hiding menu items
I'm hiding menu items using userChrome.css with option “toolkit.legacyUserProfileCustomizations.stylesheets” set to “true”.
So I am hiding some menu items like for example
- menu_find { display: none !important }
however though the menu item is gone how do I get rid of the ctrl-F menu shortcut...
I have many such menu items to remove so I need a generic solution to override the short-cut icons associated with the menu items I want to remove
被采纳的解决方案
I found a way by adding two files under the Firefox directory
- Firefox64\defaults\pref\config-prefs.js**
pref("general.config.filename", "config.js"); pref("general.config.obscure_value", 0); pref("general.config.sandbox_enabled", false);
- Firefox64\config.js**
let { classes: Cc, interfaces: Ci, manager: Cm } = Components; const {Services} = Components.utils.import('resource://gre/modules/Services.jsm'); function ConfigJS() { Services.obs.addObserver(this, 'chrome-document-global-created', false); } ConfigJS.prototype = { observe: function (aSubject) { aSubject.addEventListener('DOMContentLoaded', this, {once: true}); }, handleEvent: function (aEvent) { let document = aEvent.originalTarget; let window = document.defaultView; let location = window.location; if (/^(chrome:(?!\/\/(global\/content\/commonDialog|browser\/content\/webext-panels)\.x?html)|about:(?!blank))/i.test(location.href)) { if (window._gBrowser) { let keys = ["key_find", "key_findAgain", "key_findPrevious", "key_gotoHistory", "addBookmarkAsKb", "bookmarkAllTabsKb", "showAllHistoryKb", "manBookmarkKb", "viewBookmarksToolbarKb", "key_savePage", "key_search", "key_search2", "focusURLBar", "focusURLBar2", "key_openDownloads", "openFileKb", "key_reload_skip_cache", "key_viewSource", "key_viewInfo", "key_privatebrowsing", "key_quitApplication", "context-bookmarklink"]; for (var i=0; i < keys.length; i++) { let keyCommand = window.document.getElementById(keys[i]); if (keyCommand != undefined) { keyCommand.removeAttribute("command"); keyCommand.removeAttribute("key"); keyCommand.removeAttribute("modifiers"); keyCommand.removeAttribute("oncommand"); keyCommand.removeAttribute("data-l10n-id"); } } } } } }; if (!Services.appinfo.inSafeMode) { new ConfigJS(); }
You can get a list of ids for the keys from the source by putting the following URL in your browser
view-source:chrome://browser/content/browser.xhtml定位到答案原位置 👍 0
所有回复 (5)
You can't disable a keyboard shortcut via CSS (you can only hide content), that is only possible via JavaScript and can possibly be achieved via an autoconfig.cfg file.
cor-el said
You can't disable a keyboard shortcut via CSS (you can only hide content), that is only possible via JavaScript and can possibly be achieved via an autoconfig.cfg file.
Is there any example how to use autoconfig.cfg to do this?
See threads like these:
由cor-el于
选择的解决方案
I found a way by adding two files under the Firefox directory
- Firefox64\defaults\pref\config-prefs.js**
pref("general.config.filename", "config.js"); pref("general.config.obscure_value", 0); pref("general.config.sandbox_enabled", false);
- Firefox64\config.js**
let { classes: Cc, interfaces: Ci, manager: Cm } = Components; const {Services} = Components.utils.import('resource://gre/modules/Services.jsm'); function ConfigJS() { Services.obs.addObserver(this, 'chrome-document-global-created', false); } ConfigJS.prototype = { observe: function (aSubject) { aSubject.addEventListener('DOMContentLoaded', this, {once: true}); }, handleEvent: function (aEvent) { let document = aEvent.originalTarget; let window = document.defaultView; let location = window.location; if (/^(chrome:(?!\/\/(global\/content\/commonDialog|browser\/content\/webext-panels)\.x?html)|about:(?!blank))/i.test(location.href)) { if (window._gBrowser) { let keys = ["key_find", "key_findAgain", "key_findPrevious", "key_gotoHistory", "addBookmarkAsKb", "bookmarkAllTabsKb", "showAllHistoryKb", "manBookmarkKb", "viewBookmarksToolbarKb", "key_savePage", "key_search", "key_search2", "focusURLBar", "focusURLBar2", "key_openDownloads", "openFileKb", "key_reload_skip_cache", "key_viewSource", "key_viewInfo", "key_privatebrowsing", "key_quitApplication", "context-bookmarklink"]; for (var i=0; i < keys.length; i++) { let keyCommand = window.document.getElementById(keys[i]); if (keyCommand != undefined) { keyCommand.removeAttribute("command"); keyCommand.removeAttribute("key"); keyCommand.removeAttribute("modifiers"); keyCommand.removeAttribute("oncommand"); keyCommand.removeAttribute("data-l10n-id"); } } } } } }; if (!Services.appinfo.inSafeMode) { new ConfigJS(); }
You can get a list of ids for the keys from the source by putting the following URL in your browser
view-source:chrome://browser/content/browser.xhtml
Note that in Firefox 117 and newer you need to remove this line:
const {Services} = Components.utils.import('resource://gre/modules/Services.jsm');
Add this line instead:
const Services = globalThis.Services || ChromeUtils.import("resource://gre/modules/Services.jsm").Services;