Skip to content
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

Feat: Go to a Random Tab from Panel and selected Tabs #1806

Open
wants to merge 1 commit into
base: v5
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
19 changes: 19 additions & 0 deletions src/_locales/dict.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,16 @@ export const commonTranslations: Translations = {
zh_TW: '關閉其他分頁',
ja: '他のタブを閉じる',
},
'menu.tab.random_tab': {
en: 'Go to Random Tab',
de: 'Go to Random Tab',
hu: 'Go to Random Tab',
pl: 'Go to Random Tab',
ru: 'Go to Random Tab',
zh_CN: 'Go to Random Tab',
zh_TW: 'Go to Random Tab',
ja: 'Go to Random Tab',
},
// - Tabs panel
'menu.tabs_panel.mute_all_audible': {
en: 'Mute all audible tabs',
Expand Down Expand Up @@ -1862,6 +1872,15 @@ export const commonTranslations: Translations = {
zh: '移除面板',
ja: 'パネルを削除',
},
'menu.tabs_panel.random_tab': {
en: 'Go to Random Tab',
de: 'Go to Random Tab',
hu: 'Go to Random Tab',
pl: 'Go to Random Tab',
ru: 'Go to Random Tab',
zh: 'Go to Random Tab',
ja: 'Go to Random Tab',
},
// - History
'menu.history.open': {
en: 'Open',
Expand Down
4 changes: 3 additions & 1 deletion src/page.setup/components/menu-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
.ctrls
.btn(@click="resetBookmarksMenu") {{translate('menu.editor.reset')}}
.btn(@click="createSeparator('bookmarks')") {{translate('menu.editor.create_separator')}}

section(ref="menuEditorBookmarksPanelEl" @click.stop @wheel="moveSelected($event, 'bookmarksPanel')")
h2 {{translate('menu.editor.bookmarks_panel_title')}}

Expand Down Expand Up @@ -201,6 +201,7 @@ const TABS_MENU_OPTS: Record<string, string> = {
closeTabsAbove: 'menu.tab.close_above',
closeTabsBelow: 'menu.tab.close_below',
closeOtherTabs: 'menu.tab.close_other',
goToRandomTabFromGroup: 'menu.tab.random_tab',
}

const TABS_PANEL_MENU_OPTS: Record<string, string> = {
Expand All @@ -225,6 +226,7 @@ const TABS_PANEL_MENU_OPTS: Record<string, string> = {
sortAllTabsByUrlDescending: 'menu.tabs_panel.sort_all_by_url_des',
sortAllTabsByAccessTimeAscending: 'menu.tabs_panel.sort_all_by_time_asc',
sortAllTabsByAccessTimeDescending: 'menu.tabs_panel.sort_all_by_time_des',
goToRandomTabFromPanel: 'menu.tabs_panel.random_tab',
}

const BOOKMARKS_MENU_OPTS: Record<string, string> = {
Expand Down
37 changes: 37 additions & 0 deletions src/services/menu.options.tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,24 @@ export const tabsMenuOptions: Record<string, () => MenuOption | MenuOption[] | u
return option
},

goToRandomTabFromGroup: () => {
const tabIds = Selection.get()

const option: MenuOption = {
label: 'Go to Random Tab',
icon: 'icon_reload',
onClick: () => {
const pick = tabIds[Math.floor(Math.random() * tabIds.length)];
browser.tabs.update(pick, { active: true });
}
}

const firstTab = Tabs.byId[Selection.getFirst()]
if (!firstTab || tabIds.length <= 1) return

return option
},

// ---
// -- Panel options
// -
Expand Down Expand Up @@ -909,4 +927,23 @@ export const tabsMenuOptions: Record<string, () => MenuOption | MenuOption[] | u
if (!Settings.state.ctxMenuRenderInact && option.inactive) return
return option
},

goToRandomTabFromPanel: () => {
const panel = Sidebar.panelsById[Selection.getFirst()]

if (!Utils.isTabsPanel(panel)) return

const tabIds = panel.tabs.map(t => t.id) ?? []

const option: MenuOption = {
label: translate('menu.tabs_panel.random_tab'),
icon: 'icon_reload',
onClick: () => {
const pick = tabIds[Math.floor(Math.random() * tabIds.length)];
browser.tabs.update(pick, { active: true });
}
}

return option
},
}