Compare commits
No commits in common. "0a2891d919512e45307f2cc4cbc8a10b62d7e6dc" and "e266e9dd7bc4cbdd7772c83528b6a9d2ceae3730" have entirely different histories.
0a2891d919
...
e266e9dd7b
|
@ -31,13 +31,6 @@ 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 {
|
||||||
|
@ -199,42 +192,3 @@ 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