u/x_ATOM_d

How to set a keyboard shortcut for "Unload Tab" in Zen Browser (macOS)

Hey everyone, I wanted to share a way to assign a keyboard shortcut to "Unload Tab" in Zen Browser on macOS, since there's no native option for this in the keyboard shortcuts settings.

What you need:
fx-autoconfig: https://github.com/MrOtherGuy/fx-autoconfig

Installation:

  1. Download fx-autoconfig and copy config.js and defaults/ from the program/ folder to /Applications/Zen.app/Contents/Resources/
  2. Copy the contents of the profile/ folder to your Zen profile's chrome/ folder (find it via about:profiles → Open Folder)
  3. Create a file chrome/JS/unload-tab.uc.js with this script:

​

let tabHistory = [];

gBrowser.tabContainer.addEventListener("TabSelect", (e) => {
  tabHistory = tabHistory.filter(t => t !== e.target);
  tabHistory.push(e.target);
  if (tabHistory.length > 20) tabHistory.shift();
}, true);

document.addEventListener("keydown", (e) => {
  if (e.ctrlKey && e.key.toLowerCase() === "u") {
    let tab = gBrowser.selectedTab;
    let prevTab = [...tabHistory].reverse().find(t => t !== tab && !t.closing && !t.hasAttribute("pending"));
    if (prevTab) {
      gBrowser.selectedTab = prevTab;
    }
    gBrowser.discardBrowser(tab);
  }
}, true);

Then restart Zen Browser

The shortcut is Ctrl+U, change it in the script to whatever you prefer. It unloads the current tab and switches to the last active non-unloaded tab.

Hope this helps!

reddit.com
u/x_ATOM_d — 1 day ago