Add clear history and next item functions.
This commit is contained in:
parent
265ca87a90
commit
0a2891d919
|
@ -199,3 +199,42 @@ export async function setBadgeText(): Promise<void> {
|
|||
action.setBadgeTextColor({color: "#f2efff"});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all historical items from local WebExtension storage.
|
||||
*/
|
||||
export async function clearHistory(): Promise<void> {
|
||||
const historyPrefix: ItemKeyPrefix = "history-";
|
||||
const historyItemKeys = await getItemKeys(historyPrefix);
|
||||
const storage = storageForPrefix(historyPrefix);
|
||||
await storage.remove(historyItemKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the next queued item if one is available, otherwise opens the
|
||||
* WebExtension options page.
|
||||
*
|
||||
* @param newTab Open the next item in a new tab (default `false`).
|
||||
*/
|
||||
export async function openNextItemOrOptionsPage(newTab = false): Promise<void> {
|
||||
const item = await nextItem();
|
||||
if (item === undefined) {
|
||||
await browser.runtime.openOptionsPage();
|
||||
return;
|
||||
}
|
||||
|
||||
const url = item.value.url;
|
||||
await (newTab
|
||||
? browser.tabs.create({active: true, url})
|
||||
: browser.tabs.update({url}));
|
||||
|
||||
await item.remove();
|
||||
await setBadgeText();
|
||||
|
||||
const historyItem = await createItem(
|
||||
item.value.text,
|
||||
item.value.url,
|
||||
"history-",
|
||||
);
|
||||
await historyItem.save();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue