在 Firefox Quantum 中更改键绑定(键盘快捷键)

Fin*_*inn 42 firefox firefox-extensions firefox-quantum

由于量子更新所有允许更改 Firefox 中的键绑定的附加组件似乎已停止工作/被支持。

有没有一种方法可以更改 Firefox Quantum 中的默认键绑定?

小智 18

有一种方法。这不是超级官方,但基本上你可以解压browser/omni.ja,编辑键绑定chrome/browser/content/browser/browser.xul,重新打包,删除启动缓存,它会工作。

或者,您可以编译您自己的 firefox,然后您不需要解压缩二进制文件,如果您认为解包和重新打包比构建更难。

构建的另一个优点是你可以将你的修改存储在 git 中的官方源之上,并且总是 rebase,就像我在这里做的那样:https : //github.com/errge/gecko-dev/tree/gregzilla-patched-20181223

我建议您首先从二进制选项开始,因为您将在 20 分钟内使用键盘快捷键,而不仅仅是在 mercurial 克隆过程的开始:)

这两种方法都独立于任何扩展程序/网络扩展程序,并且始终有效,即使在地址栏甚至受保护的页面上也是如此(正如您在评论中所问的那样)。所以它们会比重新映射 webextensions 更好地工作。

我写了一篇文章,其中包含您可能感兴趣的所有细节:https : //github.com/nilcons/firefox-hacks

如果您有更多问题,请在github上报告问题。

  • 欢迎使用超级用户。在没有实际提供必须采取的步骤的情况下,这篇文章中没有答案。请[编辑]您的帖子以包含此信息,包括链接材料的基本内容。 (4认同)
  • `browser.xul` 重命名为 `browser.xhtml`:https://www.userchrome.org/firefox-changes-userchrome-css.html#fx69 (2认同)

Ben*_*pel 12

您可以使用AutoConfig更改 Firefox 中的键绑定,而无需解压和修改 Firefox 二进制文件。

创建一个config-prefs.jsconfig.js文件:

在 Windows 上:

  • C:\Program Files\Mozilla Firefox\defaults\pref\config-prefs.js
  • C:\Program Files\Mozilla Firefox\defaults\pref\config.js

在 macOS 上:

  • Firefox.app\Contents\Resources\config.js
  • Firefox.app\Contents\Resources\defaults\pref\config-prefs.js

在 Linux 上:

  • /usr/lib/firefox/config.js
  • /usr/lib/firefox/browser/defaults/preferences/config-prefs.js

包含以下内容:

config-prefs.js:

pref("general.config.filename", "config.js");    
pref("general.config.obscure_value", 0);  
pref("general.config.sandbox_enabled", false);  
Run Code Online (Sandbox Code Playgroud)

config.js:

try {
  let { classes: Cc, interfaces: Ci, manager: Cm  } = Components;
  const Services = globalThis.Services;
  const {SessionStore} = Components.utils.import('resource:///modules/sessionstore/SessionStore.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) {

          // Place your keyboard shortcut changes here
          // ...
          // ...


        }
      }
    }
  };
  if (!Services.appinfo.inSafeMode) { new ConfigJS(); }
} catch(ex) {};
Run Code Online (Sandbox Code Playgroud)

修改这些文件后,您始终必须转到about:support并运行Clear startup cache,以使用新配置重新启动浏览器。

您可以做什么的一些示例:

将这些片段放入config.js我写的地方Place your keyboard shortcut changes here

删除现有的键盘快捷键

// remove Ctrl-Shift-X, so that I can map it to 1Password in the 1Password app later
let keySwitchDirection = window.document.getElementById('key_switchTextDirection');
keySwitchDirection.remove();
Run Code Online (Sandbox Code Playgroud)

更改现有键盘快捷键

// remap Ctrl-J to downloads (removing it from focusing the browser bar)
let search2 = window.document.getElementById('key_search2')
search2.remove();
let openDownloads = window.document.getElementById('key_openDownloads')
openDownloads.setAttribute("modifiers", "accel");
openDownloads.setAttribute("key", "J");
Run Code Online (Sandbox Code Playgroud)

创建新的键盘快捷键

// create keyboard shortcut to Toolbar > Settings with Ctrl-,
let settingsKey = window.document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'key');
settingsKey.setAttribute("id", "key_Settings");
settingsKey.setAttribute("modifiers", "accel,shift");
settingsKey.setAttribute("key", "U");
settingsKey.setAttribute("oncommand", "openPreferences()");
settingsKey.addEventListener('command', this, false);
mainKeyset.appendChild(settingsKey);
Run Code Online (Sandbox Code Playgroud)

完全定制的东西。(Firefox 引入了 Shift-Ctrl-T 作为通用撤消(更改集),因此不再需要此处的示例。我将其留在这里作为其他自定义的示例。

// make Ctrl-Shift-T reopen last tab OR last window, depending on which one was closed last
let undoCloseTabKey = window.document.getElementById('key_undoCloseTab');
undoCloseTabKey.removeAttribute('command');
undoCloseTabKey.setAttribute('oncommand', 'undoCloseLastClosedTabOrWindow()');
undoCloseTabKey.addEventListener('command', this, false);

window.undoCloseLastClosedTabOrWindow = function() {
  // don't have any tabs to restore
  if (SessionStore.getClosedTabCount(window) == 0) {
    // we don't need to worry whether there are any windows to restore - undoCloseWindow does that for us
    window.undoCloseWindow();
  }

  // don't have any windows to restore
  else if (SessionStore.getClosedWindowCount() == 0) {
    // we don't need to worry whether there are any tabs to restore - undoCloseTab does that for us
    window.undoCloseTab();
  }

  // restore whichever was closed more recently
  else if (SessionStore.getClosedTabData(window)[0].closedAt > SessionStore.getClosedWindowData()[0].closedAt) {
    window.undoCloseTab();
  } else {
    window.undoCloseWindow();
  }
}
Run Code Online (Sandbox Code Playgroud)

指示:

要查找现有的键盘快捷键:

  • 汉堡菜单 > 更多工具 > 浏览器工具箱
  • 在检查器中,搜索#mainKeyset
  • 在那里,您可以看到所有分配的键盘快捷键

查找可以使用键盘快捷键触发的菜单操作

  • 汉堡菜单 > 更多工具 > 浏览器工具箱
  • 例如,使用检查器查找要通过键盘快捷键触发的元素appMenu-settings-button
  • oncommand从菜单项中获取属性,并将其用作oncommand键标签的属性

或者

  • 使用检查器,搜索#mainCommandSet
  • 并获取命令的id,并将其用作command(而不是oncommand)键标签的属性。

定义键盘快捷键:

  • 使用属性指定修饰符modifiers。您可以使用accel(Ctrl),shift并且alt
  • key使用属性指定键本身

所有这些的来源:Reddit、u/aveyo、通过设置 config.js 恢复 Ctrl+Shift+B = Library

更多详细信息:Firefox 键盘快捷键(网络存档)

  • 这个答案写得非常好,似乎描述了兼容性和长期使用的最佳方法。但这对用户来说并不友好,Mozilla 不提供这种基本功能的代价是我无法理解的选择。 (7认同)

fre*_*nte 5

如果您使用 macOS,则可以自定义任何 app\xe2\x80\x99s 快捷方式,只要它们出现在应用程序菜单中即可。macOS 13+ 的说明

\n
\n
    \n
  1. 在 Mac 上,选取 \xef\xa3\xbf 菜单 > “系统设置”,点按边栏中的“键盘” (您可能需要向下滚动),然后点按右侧的“键盘快捷键” 。

    \n
  2. \n
  3. 选择左侧的“应用程序快捷方式” ,点按“添加”按钮,点按“应用程序”弹出式菜单,然后选取特定应用程序或“所有应用程序”

    \n
  4. \n
  5. “菜单标题”字段中,键入要为其创建快捷方式的菜单命令,与应用程序中显示的命令完全相同

    \n
  6. \n
\n
\n

有关 Apple\xe2\x80\x99s 网站的更多详细信息:https://support.apple.com/guide/mac-help/create-keyboard-shortcuts-for-apps-mchlp2271/mac

\n


Fox*_*ole 2

编辑:现已从 Firefox 支持中删除: https://support.mozilla.org/en-US/kb/keyboard-shortcuts-perform-firefox-tasks-quickly

注意:您可以使用https://addons.mozilla.org/firefox/addon/saka-key/扩展自定义 Firefox 的键盘快捷键。

我希望这是您正在寻找的。

  • 谢谢,不幸的是这个扩展不太实用。如果它有效,这个:https://github.com/mikecrittenden/shortkeys 会很好。但 Firefox 似乎允许网站抑制绑定,当您的绑定仅在少数网站上运行时,这非常烦人:( (4认同)
  • 完全同意,他们需要找到一个好的解决方法来解决这个问题 (2认同)
  • 键盘快捷键文档与更改键绑定无关。 (2认同)