diff --git a/src/_locales/dict.common.ts b/src/_locales/dict.common.ts index e94f1be3..c71dc206 100644 --- a/src/_locales/dict.common.ts +++ b/src/_locales/dict.common.ts @@ -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', @@ -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', diff --git a/src/page.setup/components/menu-editor.vue b/src/page.setup/components/menu-editor.vue index 8a08e9f0..50826f92 100644 --- a/src/page.setup/components/menu-editor.vue +++ b/src/page.setup/components/menu-editor.vue @@ -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')}} @@ -201,6 +201,7 @@ const TABS_MENU_OPTS: Record = { 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 = { @@ -225,6 +226,7 @@ const TABS_PANEL_MENU_OPTS: Record = { 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 = { diff --git a/src/services/menu.options.tabs.ts b/src/services/menu.options.tabs.ts index 1d570a9f..53c8ef16 100644 --- a/src/services/menu.options.tabs.ts +++ b/src/services/menu.options.tabs.ts @@ -642,6 +642,24 @@ export const tabsMenuOptions: Record 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 // - @@ -909,4 +927,23 @@ export const tabsMenuOptions: Record 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 + }, }