Skip to content

Commit

Permalink
chore: Fix lint failures
Browse files Browse the repository at this point in the history
  • Loading branch information
gyng committed Feb 10, 2023
1 parent ae037b5 commit 733695e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"Headers": false,
"Shortcut": false,
"Router": false,
"SaveHistory": false,
"options": false,
"currentTab": false,
"requestedDownloadFlag": true,
Expand Down
7 changes: 6 additions & 1 deletion src/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions src/history.js
Original file line number Diff line number Diff line change
@@ -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)) || [],
};
9 changes: 4 additions & 5 deletions src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 6 additions & 3 deletions src/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,23 @@ 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);
};
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) {
Expand Down

0 comments on commit 733695e

Please sign in to comment.