From 733695e244c279a7f7130459c1af855465411075 Mon Sep 17 00:00:00 2001 From: Ng Guoyou Date: Sat, 11 Feb 2023 02:15:23 +0800 Subject: [PATCH] chore: Fix lint failures --- .eslintrc | 1 + src/download.js | 7 ++++++- src/history.js | 14 ++++++++------ src/menu.js | 9 ++++----- src/options/options.js | 9 ++++++--- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/.eslintrc b/.eslintrc index 72a1a8c..676c166 100644 --- a/.eslintrc +++ b/.eslintrc @@ -31,6 +31,7 @@ "Headers": false, "Shortcut": false, "Router": false, + "SaveHistory": false, "options": false, "currentTab": false, "requestedDownloadFlag": true, diff --git a/src/download.js b/src/download.js index 25ff46d..f627174 100644 --- a/src/download.js +++ b/src/download.js @@ -152,7 +152,12 @@ const Download = { Messaging.emit.downloaded(_state); window.lastDownloadState = _state; - SaveHistory.add({ timestamp: new Date().toISOString(), url: _state.info.url, finalFullPath, state: _state }) + SaveHistory.add({ + timestamp: new Date().toISOString(), + url: _state.info.url, + finalFullPath, + state: _state, + }); }; // Chrome: Skip HEAD request for Content-Disposition and use onDeterminingFilename diff --git a/src/history.js b/src/history.js index 137fce1..a414dae 100644 --- a/src/history.js +++ b/src/history.js @@ -1,11 +1,13 @@ +/* eslint-disable no-unused-vars */ + const HISTORY_KEY = "save-in-history"; const SaveHistory = { add: async (entry) => { - const current = await browser.storage.local.get(HISTORY_KEY) ?? {}; - await browser.storage.local.set({ [HISTORY_KEY]: [...current.history ?? [], entry] }) - }, - get: async () => { - return await browser.storage.local.get(HISTORY_KEY) ?? []; + const current = (await browser.storage.local.get(HISTORY_KEY)) || {}; + await browser.storage.local.set({ + [HISTORY_KEY]: [...(current.history || []), entry], + }); }, -} + get: async () => (await browser.storage.local.get(HISTORY_KEY)) || [], +}; diff --git a/src/menu.js b/src/menu.js index b7879e3..3d98abe 100644 --- a/src/menu.js +++ b/src/menu.js @@ -236,16 +236,15 @@ const Menus = { const title = meta.alias != null ? meta.alias : parsedDir; // splice the counter to fit current depth, resetting the farther depths - menuItemCounter.splice(depth + 1) + menuItemCounter.splice(depth + 1); if (menuItemCounter[depth] != null) { menuItemCounter[depth] += 1; } else { menuItemCounter[depth] = 1; } - const id = `save-in-${menuItemCounter.join('.')}-${`${i}${comment.replace( - "-", - "_" - )}`}-${parsedDir}`; + const id = `save-in-${menuItemCounter.join( + "." + )}-${`${i}${comment.replace("-", "_")}`}-${parsedDir}`; let parentId; if (depth === 0) { diff --git a/src/options/options.js b/src/options/options.js index 86d3686..1a872ae 100644 --- a/src/options/options.js +++ b/src/options/options.js @@ -136,7 +136,7 @@ const updateErrors = () => { const updateHistory = async () => { // Copied from history.js const HISTORY_KEY = "save-in-history"; - const history = await browser.storage.local.get(HISTORY_KEY) ?? {}; + const history = (await browser.storage.local.get(HISTORY_KEY)) || {}; const el = document.querySelector("#history"); el.value = JSON.stringify(history, null, 2); }; @@ -144,12 +144,15 @@ document.addEventListener("DOMContentLoaded", updateHistory); const deleteHistory = () => { const HISTORY_KEY = "save-in-history"; + // eslint-disable-next-line const answer = window.confirm("Delete all history?"); if (answer) { browser.storage.local.remove(HISTORY_KEY).then(updateHistory); } -} -document.querySelector("#history-delete")?.addEventListener("click", deleteHistory); +}; +document + .querySelector("#history-delete") + .addEventListener("click", deleteHistory); browser.runtime.onMessage.addListener((message) => { switch (message.type) {