Funktioniert bestens.
Vielen Dank.
Freut mich, gern geschehen.![]()
Hier noch ein Script im Angebot zum Test.
JavaScript
// TabCloseButton.uc.js
// „Linke Tabs schließen“ und „Rechte Tabs schließen“ heißt, ab dem aktuellen Tab
// gibt es keine Auswahl dafür, so werden die Einträge ausgegraut
// alle Schließvorgänge müssen im Warndialog bestätigt werden
// Menü für "Kürzlich geschlossene Tabs" wird zusätzlich erstellt
(function() {
if (!window.gBrowser || !CustomizableUI) return;
// === User Einstellungen ===
let btn_id = 'alle_tabs_close';
const btn_icon = 'warnung2.png';
const iconPath = 'file:///C:/FoxIcons/';
const ImagePath = iconPath + btn_icon;
const btn_label = 'Tabs verwalten';
const btn_tooltiptext = 'Tabs verwalten';
// ===========================
// ---------------------------
// Styled confirm (Promise-based)
// ---------------------------
function showStyledConfirm(message, okLabel = 'Schließen', cancelLabel = 'Abbrechen') {
return new Promise(resolve => {
const existing = document.getElementById('ucjs_styled_confirm_overlay');
if (existing) existing.remove();
let overlay = document.createElement('div');
overlay.id = 'ucjs_styled_confirm_overlay';
overlay.style.position = 'fixed';
overlay.style.left = '0';
overlay.style.top = '0';
overlay.style.width = '100%';
overlay.style.height = '100%';
overlay.style.zIndex = '999999';
overlay.style.display = 'flex';
overlay.style.alignItems = 'center';
overlay.style.justifyContent = 'center';
overlay.style.background = 'rgba(0,0,0,0.35)';
let box = document.createElement('div');
box.style.minWidth = '380px';
box.style.maxWidth = '720px';
box.style.padding = '18px';
box.style.borderRadius = '8px';
box.style.background = 'linear-gradient(#fff,#f6f6f6)';
box.style.boxShadow = '0 10px 30px rgba(0,0,0,0.4)';
box.style.fontFamily = 'system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial';
box.style.color = '#111';
let msg = document.createElement('div');
msg.textContent = message;
msg.style.fontSize = '16px';
msg.style.fontWeight = '500';
msg.style.marginBottom = '14px';
msg.style.lineHeight = '1.3';
let btnRow = document.createElement('div');
btnRow.style.display = 'flex';
btnRow.style.justifyContent = 'flex-end';
btnRow.style.gap = '8px';
let btnCancel = document.createElement('button');
btnCancel.textContent = cancelLabel;
btnCancel.style.padding = '6px 10px';
btnCancel.style.borderRadius = '4px';
btnCancel.style.border = '1px solid #888';
btnCancel.style.background = '#fff';
let btnOK = document.createElement('button');
btnOK.textContent = okLabel;
btnOK.style.padding = '6px 10px';
btnOK.style.borderRadius = '4px';
btnOK.style.border = '0';
btnOK.style.background = '#d9534f';
btnOK.style.color = '#fff';
btnOK.style.fontWeight = '500';
function keyHandler(e) {
if (e.key === 'Escape') { cleanup(); resolve(false); }
if (e.key === 'Enter') { cleanup(); resolve(true); }
}
function cleanup() {
window.removeEventListener('keydown', keyHandler, true);
overlay.remove();
}
btnCancel.addEventListener('click', () => { cleanup(); resolve(false); });
btnOK.addEventListener('click', () => { cleanup(); resolve(true); });
btnRow.appendChild(btnCancel);
btnRow.appendChild(btnOK);
box.appendChild(msg);
box.appendChild(btnRow);
overlay.appendChild(box);
document.documentElement.appendChild(overlay);
btnCancel.focus();
window.addEventListener('keydown', keyHandler, true);
});
}
// ---------------------------
// Widget erstellen (falls nicht vorhanden)
// ---------------------------
try {
CustomizableUI.createWidget({
id: btn_id,
defaultArea: CustomizableUI.AREA_NAVBAR,
label: btn_label,
tooltiptext: btn_tooltiptext,
onCreated: (this_button) => {
this_button.style.MozContextProperties = 'fill, stroke, fill-opacity, stroke-opacity';
this_button.style.listStyleImage = 'url("' + ImagePath + '")';
this_button.style.minWidth = 'fit-content';
this_button.setAttribute('role', 'button');
}
});
} catch (e) {
// Widget eventuell schon vorhanden
}
// ---------------------------
// UndoListInTabmenu (gekapselt, angepasst)
// ---------------------------
const UndoListInTabmenu = {
_ss: SessionStore,
populateUndoSubmenu(undoPopup) {
if (!undoPopup) return;
while (undoPopup.hasChildNodes()) undoPopup.removeChild(undoPopup.firstChild);
let utils = RecentlyClosedTabsAndWindowsMenuUtils;
let tabsFragment = utils.getTabsFragment(window, "menuitem", true, "menu-history-reopen-all-tabs");
undoPopup.appendChild(tabsFragment);
let undoItems = this._ss.getClosedTabDataForWindow(window) || [];
for (let i = 0; i < undoItems.length; i++) {
let entries = undoItems[i].state.entries;
let tooltiptext = "";
for (let j = entries.length - 1; j > -1; j--) {
if (j !== entries.length - 1) tooltiptext += "\n";
if (undoItems[i].state.index - 1 !== j) {
tooltiptext += parseInt(j + 1, 10) + ". " + entries[j].title;
} else {
tooltiptext += "*" + ". " + entries[j].title;
}
}
if (undoPopup.childNodes[i]) {
undoPopup.childNodes[i].setAttribute("tooltiptext", tooltiptext);
}
}
undoPopup.appendChild(document.createXULElement("menuseparator"));
let m = undoPopup.appendChild(document.createXULElement("menuitem"));
m.setAttribute("label", "Liste der letzten Tabs löschen");
m.setAttribute("accesskey", "l");
m.addEventListener("command", function () {
let prefs = Services.prefs;
let max_undo = prefs.getIntPref("browser.sessionstore.max_tabs_undo");
prefs.setIntPref("browser.sessionstore.max_tabs_undo", 0);
prefs.setIntPref("browser.sessionstore.max_tabs_undo", max_undo);
}, false);
}
};
// ---------------------------
// Popup + Menüpunkte erzeugen
// ---------------------------
function ensurePopup() {
if (document.getElementById(btn_id + '_popup')) return;
let popup = document.createXULElement ? document.createXULElement('menupopup') : document.createElement('menupopup');
popup.id = btn_id + '_popup';
popup.setAttribute('class', 'toolbarbutton-popup');
popup.setAttribute('position', 'after_start');
function makeItem(id, label, accesskey, klass) {
let it = document.createXULElement ? document.createXULElement('menuitem') : document.createElement('menuitem');
it.id = id;
it.setAttribute('label', label);
if (accesskey) it.setAttribute('accesskey', accesskey);
it.setAttribute('class', klass || 'menuitem');
return it;
}
// Linke, Rechte, Alle
let miLeft = makeItem(btn_id + '_left', 'Linke Tabs schließen', 'L');
let miRight = makeItem(btn_id + '_right', 'Rechte Tabs schließen', 'R');
let miAll = makeItem(btn_id + '_all', 'Alle Tabs schließen', 'A', 'menuitem danger');
// Separator
let sep = document.createXULElement ? document.createXULElement('menuseparator') : document.createElement('menuseparator');
// Kürzlich geschlossene Tabs (aus UndoListInTabmenu)
let menuRecent = document.createXULElement ? document.createXULElement('menu') : document.createElement('menu');
menuRecent.setAttribute('label', 'Kürzlich geschlossene Tabs');
menuRecent.setAttribute('accesskey', 'T');
menuRecent.id = btn_id + '_recent_menu';
let popupForTabs = document.createXULElement ? document.createXULElement('menupopup') : document.createElement('menupopup');
popupForTabs.id = btn_id + '_recent_popup';
popupForTabs.addEventListener('popupshowing', function() {
UndoListInTabmenu.populateUndoSubmenu(popupForTabs);
});
menuRecent.appendChild(popupForTabs);
// "Alle Tabs auflisten" (öffnet built-in alltabs-button)
let menuAllList = document.createXULElement ? document.createXULElement('menuitem') : document.createElement('menuitem');
menuAllList.setAttribute('label', 'Alle Tabs auflisten');
menuAllList.setAttribute('accesskey', 'A');
menuAllList.addEventListener('command', () => {
let alltabsButton = document.getElementById("alltabs-button");
if (alltabsButton) alltabsButton.click();
});
// Append alles zum popup
popup.appendChild(miLeft);
popup.appendChild(miRight);
popup.appendChild(miAll);
popup.appendChild(sep);
popup.appendChild(menuRecent);
popup.appendChild(menuAllList);
let toolbox = document.getElementById('navigator-toolbox') || document.body;
toolbox.appendChild(popup);
// Hilfsfunktion: robusten Index eines Tabs ermitteln
function tabIndex(t) {
return (typeof t._tPos === 'number') ? t._tPos : (typeof t.index === 'number' ? t.index : -1);
}
// Dynamisch: vor Anzeige prüfen, ob links/rechts Tabs vorhanden sind
popup.addEventListener('popupshown', function() {
let current = gBrowser.selectedTab;
if (!current) {
miLeft.disabled = true;
miRight.disabled = true;
miAll.disabled = (gBrowser.tabs.length <= 0);
return;
}
let currentIndex = tabIndex(current);
let hasLeft = false, hasRight = false;
for (let i = 0; i < gBrowser.tabs.length; i++) {
let t = gBrowser.tabs[i];
let idx = tabIndex(t);
if (idx < currentIndex && !t.pinned) hasLeft = true;
if (idx > currentIndex && !t.pinned) hasRight = true;
if (hasLeft && hasRight) break;
}
miLeft.disabled = !hasLeft;
miRight.disabled = !hasRight;
miAll.disabled = (gBrowser.tabs.length <= 0);
});
// Fallback: manche Builds feuern popupshowing statt popupshown
popup.addEventListener('popupshowing', function() {
let ev = new Event('popupshown');
popup.dispatchEvent(ev);
});
// === Handler: Linke schließen ===
miLeft.addEventListener('command', async function() {
let current = gBrowser.selectedTab;
if (!current) return;
if (!(await showStyledConfirm('Warnung: Alle Tabs links vom aktuellen Tab werden geschlossen. Fortfahren?', 'Schließen', 'Abbrechen'))) return;
let currentIndex = tabIndex(current);
let toClose = [];
for (let i = 0; i < gBrowser.tabs.length; i++) {
let t = gBrowser.tabs[i];
let idx = tabIndex(t);
if (idx < currentIndex && !t.pinned) toClose.push(t);
}
for (let i = toClose.length - 1; i >= 0; i--) {
try { gBrowser.removeTab(toClose[i]); } catch (e) { console.error(e); }
}
});
// === Handler: Rechte schließen ===
miRight.addEventListener('command', async function() {
let current = gBrowser.selectedTab;
if (!current) return;
if (!(await showStyledConfirm('Warnung: Alle Tabs rechts vom aktuellen Tab werden geschlossen. Fortfahren?', 'Schließen', 'Abbrechen'))) return;
let currentIndex = tabIndex(current);
let toClose = [];
for (let i = 0; i < gBrowser.tabs.length; i++) {
let t = gBrowser.tabs[i];
let idx = tabIndex(t);
if (idx > currentIndex && !t.pinned) toClose.push(t);
}
for (let i = toClose.length - 1; i >= 0; i--) {
try { gBrowser.removeTab(toClose[i]); } catch (e) { console.error(e); }
}
});
// === Handler: Alle schließen ===
miAll.addEventListener('command', async function() {
if (!(await showStyledConfirm('Warnung: Alle Tabs werden geschlossen. Fortfahren?', 'Schließen', 'Abbrechen'))) return;
let tabs = Array.from(gBrowser.tabs);
for (let i = tabs.length - 1; i >= 0; i--) {
try { gBrowser.removeTab(tabs[i]); } catch (e) { console.error(e); }
}
});
}
// ---------------------------
// Klick-Handler: öffnet Popup über Button (nur linker Klick)
// ---------------------------
function attachClickHandler() {
let btn = document.getElementById(btn_id);
if (!btn) return;
ensurePopup();
btn.removeEventListener('click', _onClick);
function _onClick(event) {
if (event.button !== 0) return;
let popup = document.getElementById(btn_id + '_popup');
if (!popup) return;
try {
popup.openPopup(btn, 'after_start', 0, 0, true);
} catch (e) {
try { popup.showPopup(btn, -1, -1, 'popup', 'bottomleft'); } catch (err) { console.error(err); }
}
}
btn.addEventListener('click', _onClick);
}
// Initialisierung / Hooks
if (window.readyState !== "loading") {
setTimeout(attachClickHandler, 200);
} else {
window.addEventListener("DOMContentLoaded", attachClickHandler, { once: true });
}
window.addEventListener('aftercustomization', () => {
setTimeout(attachClickHandler, 100);
});
// Cleanup bei Unload
window.addEventListener('unload', () => {
let popup = document.getElementById(btn_id + '_popup');
if (popup && popup.parentNode) popup.parentNode.removeChild(popup);
let overlay = document.getElementById('ucjs_styled_confirm_overlay');
if (overlay && overlay.parentNode) overlay.parentNode.removeChild(overlay);
});
})();
Alles anzeigen



