【问题标题】:Override Keyboard Shortcuts in Firefox在 Firefox 中覆盖键盘快捷键
【发布时间】:2022-12-31 04:12:50
【问题描述】:

如何覆盖 Firefox 中的键盘快捷键以便它可以被网页拾取

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

我正在做很多这样的事情,所以我正在寻找一种通用的方法来覆盖 Firefox 键盘快捷键

【问题讨论】:

    标签: firefox keyboard-shortcuts customization


    【解决方案1】:

    我找到了一种方法,在 Firefox 目录下添加两个文件

    Firefox64defaultsprefconfig-prefs.js

    pref("general.config.filename", "config.js");    
    pref("general.config.obscure_value", 0);  
    pref("general.config.sandbox_enabled", false); 
    

    Firefox64config.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(); }
    

    您可以通过将以下 URL 放入浏览器中来从源中获取密钥的 ID 列表

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

    【讨论】:

    • 谢谢!! view-source 参考太棒了!!!
    【解决方案2】:

    抱歉,我还不能发表评论,只能扩展 zackhalil answer

    对于那些在 Linux 或类似 Unix/类 Unix 系统上的用户,将 Firefox64 替换为 /usr/lib/firefox。不要与$HOME/.mozilla/firefox混淆

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-17
      • 1970-01-01
      • 2011-04-10
      • 2013-04-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-26
      • 2014-05-04
      相关资源
      最近更新 更多