import browser from 'webextension-polyfill'; import {Settings} from '../settings/settings.js'; import {updateBadge} from '../utilities/badge.js'; // Chromium action handler in service worker. export async function actionClicked(): Promise { await nextItem(); } let timeoutId: number | undefined; // Firefox browser action handler in background script. export async function browserActionClicked(): Promise { // When the extension icon is initially clicked, create a timeout for 500ms // that will open the next queue item when it expires. if (timeoutId === undefined) { timeoutId = window.setTimeout(async () => { timeoutId = undefined; await nextItem(); }, 500); return; } // If the icon is clicked again in those 500ms, open the options page instead. window.clearTimeout(timeoutId); timeoutId = undefined; await browser.runtime.openOptionsPage(); } async function nextItem(): Promise { const settings = await Settings.fromSyncStorage(); const nextItem = settings.nextQueueItem(); if (nextItem === undefined) { await browser.runtime.openOptionsPage(); return; } await browser.tabs.update({url: nextItem.url}); await settings.removeQueueItem(nextItem.id); await updateBadge(settings); }