import browser from 'webextension-polyfill'; import {deserializeQueue, serializeQueue} from '../settings/migrations.js'; export class History { public static async clear(): Promise { await browser.storage.local.remove('history'); } public static async fromLocalStorage(): Promise { const history = new History(); const stored = await browser.storage.local.get({history: []}); history.queue = deserializeQueue(stored.history); return history; } public queue: Queue.Item[]; private constructor() { this.queue = []; } public async clear(): Promise { await History.clear(); } public async insertItems(items: Queue.Item[]): Promise { this.queue = this.queue.concat(items); for (const [index, item] of this.queue.entries()) { item.id = index; } await this.save(); } public async save(): Promise { await browser.storage.local.set({ history: serializeQueue(this.queue), }); } }