Skip to content

Add "Shuffle all tabs" action to tab context menu #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,7 @@ document.addEventListener("DOMContentLoaded", () =>
document.getElementById("contextmenu-action-tab-restore-closed").addEventListener("click", (e) => { utils.tabs.restoreLastClosedTab(); });
document.getElementById("contextmenu-action-tab-bookmark-all").addEventListener("click", (e) => { let bookmarkFolderName = window.prompt("Name of bookmark directory:", "tabs"); utils.tabs.bookmarkAllVisibleTabs(contextmenuTarget, bookmarkFolderName); });
document.getElementById("contextmenu-action-tab-reload-all").addEventListener("click", (e) => { utils.tabs.reloadAllVisibleTabs(); });
document.getElementById("contextmenu-action-tab-shuffle-all").addEventListener("click", (e) => { utils.tabs.shuffleAllVisibleTabs(); });
document.getElementById("contextmenu-action-tab-close-below").addEventListener("click", (e) => { utils.tabs.closeTabsRelativeTo(contextmenuTarget, "below"); });
document.getElementById("contextmenu-action-tab-close-above").addEventListener("click", (e) => { utils.tabs.closeTabsRelativeTo(contextmenuTarget, "above"); });
document.getElementById("contextmenu-action-tab-close-others").addEventListener("click", (e) => { utils.tabs.closeTabsRelativeTo(contextmenuTarget, "others"); });
Expand Down
15 changes: 15 additions & 0 deletions utils/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ utils["tabs"] = class tabutils
});
}

static async shuffleAllVisibleTabs()
{
const tabs = [
...(
await browser.windows.getCurrent({
windowTypes: ["normal"],
populate: true
})
).tabs
];

tabs.sort(() => Math.random() - 0.5);
tabs.forEach((tab, index) => void browser.tabs.move(tab.id, { index }));
}

static bookmarkAllVisibleTabs(e, name)
{
if(name == null)
Expand Down