Created
February 7, 2025 12:01
-
-
Save danielgormly/04f2c24917a2b1e21a2817202f3677e4 to your computer and use it in GitHub Desktop.
Firefox: Add ctrl+option+left/right to jump tabs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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