Skip to content

Instantly share code, notes, and snippets.

@danielgormly
Created February 7, 2025 12:01
Show Gist options
  • Save danielgormly/04f2c24917a2b1e21a2817202f3677e4 to your computer and use it in GitHub Desktop.
Save danielgormly/04f2c24917a2b1e21a2817202f3677e4 to your computer and use it in GitHub Desktop.
Firefox: Add ctrl+option+left/right to jump tabs
// Note this goes in /usr/lib/firefox/defaults/pref/autoconfig.js
pref("general.config.filename", "firefox.js");
pref("general.config.obscure_value", 0);
pref("general.config.sandbox_enabled", false);
// IMPORTANT: Start your code on the 2nd line, Note this goes in /usr/lib/firefox/firefox.js
try {
let wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
// Global state to track AltGraph
let isAltGraphDown = false;
function handleKeyEvent(window, event) {
// Update AltGraph state
if (event.key === "AltGraph") {
isAltGraphDown = event.type === "keydown";
return;
}
// Check for our shortcuts
if (event.type === "keydown" && event.ctrlKey && (event.altKey || isAltGraphDown)) {
if (event.key === "ArrowLeft") {
window.gBrowser.tabContainer.advanceSelectedTab(-1, true);
event.preventDefault();
}
if (event.key === "ArrowRight") {
window.gBrowser.tabContainer.advanceSelectedTab(1, true);
event.preventDefault();
}
}
}
let windowListener = {
onOpenWindow: function(xulWindow) {
let window = xulWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowInternal ||
Components.interfaces.nsIDOMWindow);
window.addEventListener("load", function() {
if (window.document.documentElement.getAttribute("windowtype") === "navigator:browser") {
window.document.addEventListener("keydown", e => handleKeyEvent(window, e));
window.document.addEventListener("keyup", e => handleKeyEvent(window, e));
}
});
},
onCloseWindow: function() {},
onWindowTitleChange: function() {}
};
// Add listener for new windows
wm.addListener(windowListener);
// Handle existing windows
let windows = wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
let window = windows.getNext();
window.document.addEventListener("keydown", e => handleKeyEvent(window, e));
window.document.addEventListener("keyup", e => handleKeyEvent(window, e));
}
} catch(ex) {
Components.utils.reportError(ex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment