Compare commits
2 Commits
e266e9dd7b
...
0a2891d919
Author | SHA1 | Date |
---|---|---|
Bauke | 0a2891d919 | |
Bauke | 265ca87a90 |
|
@ -31,6 +31,13 @@ export type SerializedItem = {
|
||||||
/** The key prefix for {@link Item}s. */
|
/** The key prefix for {@link Item}s. */
|
||||||
export type ItemKeyPrefix = "item-" | "history-";
|
export type ItemKeyPrefix = "item-" | "history-";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the dedicated WebExtension storage area for a given
|
||||||
|
* {@link ItemKeyPrefix}.
|
||||||
|
*
|
||||||
|
* @param prefix The target {@link ItemKeyPrefix}.
|
||||||
|
* @returns The WebExtension storage area.
|
||||||
|
*/
|
||||||
export function storageForPrefix(
|
export function storageForPrefix(
|
||||||
prefix: ItemKeyPrefix,
|
prefix: ItemKeyPrefix,
|
||||||
): browser.Storage.StorageArea {
|
): browser.Storage.StorageArea {
|
||||||
|
@ -192,3 +199,42 @@ export async function setBadgeText(): Promise<void> {
|
||||||
action.setBadgeTextColor({color: "#f2efff"});
|
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