在Firefox中覆盖键盘快捷键

5

如何在Firefox中覆盖键盘快捷键,以便网页可以检测到

例如,我有一个网页会检测ctrl-shift-h,在版本56中运行良好,但现在在版本96中会弹出“显示完整历史记录”对话框。

我正在做很多类似的事情,因此我正在寻找一种通用的方法来覆盖Firefox键盘快捷方式。

2个回答

6
我找到一种方法,可以在Firefox目录下添加两个文件来实现。 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(); }

您可以通过在浏览器中输入以下网址来获取源键的ID列表:

view-source:chrome://browser/content/browser.xhtml

谢谢!那个view-source的参考真的很棒!!! - Wayne Walker
这在当前版本(119)上似乎没有任何作用,而且我无法禁用快捷键。没有错误,但是这个配置没有任何变化。 - undefined

0

抱歉,我还不能评论,但是为了扩展zackhalil 的回答

对于那些使用Linux或类似的Unix/Unix-like系统的人,请将Firefox64替换为/usr/lib/firefox。不要将其与$HOME/.mozilla/firefox混淆。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接