Ich bin eher an das klassische Drei-Punkte menu
JavaScript
(function () {
"use strict";
if (location.href !== "chrome://browser/content/browser.xhtml")
return;
const tabContextMenu = document.getElementById("tabContextMenu");
const undoCloseTab = document.getElementById("context_undoCloseTab");
if (!tabContextMenu || !undoCloseTab)
return;
// Create menu item (XUL)
function createMenuItem(id, label) {
let item = document.getElementById(id);
if (!item) {
item = document.createXULElement("menuitem");
item.id = id;
item.setAttribute("label", label);
// role/class kann helfen, dass das Item korrekt dargestellt wird
item.className = "menuitem";
}
return item;
}
// Close Tabs to Left
const closeLeft = createMenuItem(
"context_closeLeftTabs",
"Close Tabs to Left"
);
closeLeft.addEventListener("command", function () {
const contextTab = TabContextMenu.contextTab;
if (!contextTab)
return;
const tabs = Array.from(gBrowser.tabs);
for (const tab of tabs) {
if (tab === contextTab)
break;
if (!tab.pinned)
gBrowser.removeTab(tab, { animate: true });
}
});
// Close Tabs to Right
const closeRight = createMenuItem(
"context_closeRightTabs",
"Close Tabs to Right"
);
closeRight.addEventListener("command", function () {
const contextTab = TabContextMenu.contextTab;
if (!contextTab)
return;
const tabs = Array.from(gBrowser.tabs);
const index = tabs.indexOf(contextTab);
if (index === -1)
return;
for (let i = tabs.length - 1; i > index; i--) {
const tab = tabs[i];
if (!tab.pinned)
gBrowser.removeTab(tab, { animate: true });
}
});
// Close Other Tabs
const closeOthers = createMenuItem(
"context_closeOtherTabsCustom",
"Close Other Tabs"
);
closeOthers.addEventListener("command", function () {
const contextTab = TabContextMenu.contextTab;
if (!contextTab)
return;
const tabs = Array.from(gBrowser.tabs);
for (const tab of tabs) {
if (tab !== contextTab && !tab.pinned)
gBrowser.removeTab(tab, { animate: true });
}
});
// Insert menu
// If items already exist, they will be reused; otherwise, they will be inserted.
tabContextMenu.insertBefore(closeLeft, undoCloseTab);
tabContextMenu.insertBefore(closeRight, undoCloseTab);
tabContextMenu.insertBefore(closeOthers, undoCloseTab);
// Update menu when opened (active/disabled)
tabContextMenu.addEventListener("popupshowing", function () {
const contextTab = TabContextMenu.contextTab;
if (!contextTab)
return;
const tabs = Array.from(gBrowser.tabs);
const index = tabs.indexOf(contextTab);
if (index === -1)
return;
let hasLeft = false;
let hasRight = false;
let hasOther = false;
for (let i = 0; i < tabs.length; i++) {
const tab = tabs[i];
if (tab.pinned)
continue;
if (i < index)
hasLeft = true;
if (i > index)
hasRight = true;
if (tab !== contextTab)
hasOther = true;
}
closeLeft.disabled = !hasLeft;
closeRight.disabled = !hasRight;
closeOthers.disabled = !hasOther;
});
})();
Alles anzeigen
Der Stil blendet den nicht mehr benötigten Menüpunkt aus und fügt Symbole hinzu.
CSS
/* userChrome.css */
/* Hide general item "Close Multiple Tabs" with drop-down menu */
#context_closeTabOptions {
display:none !important;
}
/* Icon "Close Tabs to Left" */
#context_closeLeftTabs::before {
background-image: url("./icons/L.png"); !important;
}
/* Icon "Close Tabs to Right" */
#context_closeRightTabs::before {
background-image: url("./icons/R.png"); !important;
}
/* Icon "Close Other Tabs" */
#context_closeOtherTabsCustom::before {
background-image: url("./icons/LR.png"); !important;
}
Alles anzeigen
