Skip to content

Commit

Permalink
Fix discarding selected tabs, partially fixes freddyb#4
Browse files Browse the repository at this point in the history
  • Loading branch information
Nothing4You committed Dec 25, 2023
1 parent 47909d3 commit 013d7a3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ browser.menus.create({
contexts: ["tab"]
});

browser.menus.onClicked.addListener(async (info, tab) => {
const discardTab = async (tab) => {
if (tab.discarded) {
return;
}
Expand All @@ -39,6 +39,18 @@ browser.menus.onClicked.addListener(async (info, tab) => {
}
}
browser.tabs.discard(tab.id);
}

browser.menus.onClicked.addListener(async (info, tab) => {
// A highlighted tab is a selected tab.
// If the tab is not highlighted, the user clicked on a tab that is neither selected nor the active tab.
// If the tab is highlighted it might be the active tab or one of multiple selected tabs.
if (tab.highlighted) {
const tabs = await browser.tabs.query({windowId: tab.windowId, active: false, discarded: false, highlighted: true});
tabs.forEach(async (it) => await discardTab(it));
} else {
discardTab(tab);
}
});

browser.storage.onChanged.addListener((changes) => {
Expand Down

0 comments on commit 013d7a3

Please sign in to comment.