diff --git a/src/hooks.ts b/src/hooks.ts index 36603c0..69cd7ca 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -100,7 +100,7 @@ function onLoad() { } function noNotifyDeleteItem(ids: (string | number)[]) { - tldrs.modify(data => { + tldrs.modify((data) => { ids.forEach((id) => { delete data[id]; }); @@ -128,7 +128,7 @@ function onUpdateItems(items: Zotero.Item[], forceFetch: boolean = false) { return false; } if (!forceFetch) { - return tldrs.get()[item.id] === undefined + return tldrs.get()[item.id] === undefined; } return true; }); @@ -139,7 +139,9 @@ function onUpdateItems(items: Zotero.Item[], forceFetch: boolean = false) { return new ztoolkit.ProgressWindow(config.addonName, { closeOnClick: closeOnClick, }).createLine({ - text: `${getString("popWindow-waiting")}: ${items.length}; ${getString("popWindow-succeed")}: 0; ${getString("popWindow-failed")}: 0`, + text: `${getString("popWindow-waiting")}: ${items.length}; ${getString( + "popWindow-succeed", + )}: 0; ${getString("popWindow-failed")}: 0`, type: "default", progress: 0, }); @@ -158,7 +160,11 @@ function onUpdateItems(items: Zotero.Item[], forceFetch: boolean = false) { ztoolkit.ItemBox.refresh(); popupWin.changeLine({ progress: (index * 100) / count, - text: `${getString("popWindow-waiting")}: ${count - index - 1}; ${getString("popWindow-succeed")}: ${succeedItems.length}; ${getString("popWindow-failed")}: ${failedItems.length}`, + text: `${getString("popWindow-waiting")}: ${ + count - index - 1 + }; ${getString("popWindow-succeed")}: ${ + succeedItems.length + }; ${getString("popWindow-failed")}: ${failedItems.length}`, }); } })(); @@ -167,7 +173,9 @@ function onUpdateItems(items: Zotero.Item[], forceFetch: boolean = false) { popupWin.changeLine({ type: "success", progress: 100, - text: `${getString("popWindow-succeed")}: ${succeedItems.length}; ${getString("popWindow-failed")}: ${failedItems.length}`, + text: `${getString("popWindow-succeed")}: ${ + succeedItems.length + }; ${getString("popWindow-failed")}: ${failedItems.length}`, }); popupWin.startCloseTimer(3000); })(); diff --git a/src/modules/dataStorage.ts b/src/modules/dataStorage.ts index fe38219..3705e05 100644 --- a/src/modules/dataStorage.ts +++ b/src/modules/dataStorage.ts @@ -19,7 +19,9 @@ export class Data { return this.data; } - async modify(action: (data: Record) => Record | Promise>) { + async modify( + action: (data: Record) => Record | Promise>, + ) { await this.initDataIfNeed(); const data = this.data; const newData = await action(data); @@ -54,7 +56,9 @@ export class Data { } private async initDataIfNeed() { - if (this.inited) { return; } + if (this.inited) { + return; + } this.inited = true; try { this.data = await IOUtils.readJSON(this.filePath, { decompress: false }); @@ -74,7 +78,9 @@ export class DataStorage { private static shared = new DataStorage(); - static instance(dataType: string): Data { + static instance( + dataType: string, + ): Data { const path = PathUtils.join(this.shared.dataDir, dataType); if (this.shared.dataMap[dataType] === undefined) { const data = new Data(path); @@ -86,10 +92,13 @@ export class DataStorage { } private constructor() { - IOUtils.makeDirectory(this.dataDir, { createAncestors: true, ignoreExisting: true }); + IOUtils.makeDirectory(this.dataDir, { + createAncestors: true, + ignoreExisting: true, + }); } } export const TLDRUnrelated = "tldr-unrelated"; // semantic scholar 找到了该item,但是该item没有tldr export const TLDRItemNotFound = "tldr-itemnotfound"; // semantic scholar 找不到该item -export const tldrs = DataStorage.instance('TLDR.json'); \ No newline at end of file +export const tldrs = DataStorage.instance("TLDR.json");