This commit is contained in:
shenyutao 2024-03-11 11:47:42 +08:00
parent b56669ae8f
commit 735da8a43a
5 changed files with 24 additions and 15 deletions

View File

@ -18,13 +18,13 @@
"\tremoveIfExists: ${13:true},", "\tremoveIfExists: ${13:true},",
"\tcustomCheck: (doc: Document, options: ElementOptions) => ${14:true},", "\tcustomCheck: (doc: Document, options: ElementOptions) => ${14:true},",
"\tchildren: [$15]", "\tchildren: [$15]",
"}, ${16:container});" "}, ${16:container});",
] ],
}, },
"appendElement - minimum": { "appendElement - minimum": {
"scope": "javascript,typescript", "scope": "javascript,typescript",
"prefix": "appendElement", "prefix": "appendElement",
"body": "appendElement({ tag: '$1' }, $2);" "body": "appendElement({ tag: '$1' }, $2);",
}, },
"register Notifier": { "register Notifier": {
"scope": "javascript,typescript", "scope": "javascript,typescript",
@ -39,7 +39,7 @@
"\t) => {", "\t) => {",
"\t\t$0", "\t\t$0",
"\t}", "\t}",
"});" "});",
] ],
} },
} }

View File

@ -123,7 +123,7 @@ function onUpdateItems(items: Zotero.Item[], forceFetch: boolean = false) {
if (!item.getField("title")) { if (!item.getField("title")) {
return false; return false;
} }
if (!forceFetch && (item.key in tldrs.get())) { if (!forceFetch && item.key in tldrs.get()) {
return false; return false;
} }
return true; return true;

View File

@ -119,4 +119,6 @@ export class DataStorage {
} }
} }
export const tldrs = DataStorage.instance<string, string | false>("fetchedItems.json"); export const tldrs = DataStorage.instance<string, string | false>(
"fetchedItems.json",
);

View File

@ -38,21 +38,28 @@ export class TLDRFetcher {
match = true; match = true;
} }
if (match && info.tldr) { if (match && info.tldr) {
let note = new Zotero.Item('note'); let note = new Zotero.Item("note");
if (noteKey) { if (noteKey) {
const obj = Zotero.Items.getByLibraryAndKey(this.zoteroItem.libraryID, noteKey); const obj = Zotero.Items.getByLibraryAndKey(
if (obj && obj instanceof Zotero.Item && this.zoteroItem.getNotes().includes(obj.id)) { this.zoteroItem.libraryID,
noteKey,
);
if (
obj &&
obj instanceof Zotero.Item &&
this.zoteroItem.getNotes().includes(obj.id)
) {
note = obj; note = obj;
} }
} }
note.setNote(`<p>TL;DR</p>\n<p>${info.tldr}</p>`) note.setNote(`<p>TL;DR</p>\n<p>${info.tldr}</p>`);
note.parentID = this.zoteroItem.id; note.parentID = this.zoteroItem.id;
await note.saveTx(); await note.saveTx();
await tldrs.modify((data: any) => { await tldrs.modify((data: any) => {
data[this.zoteroItem.key] = note.key; data[this.zoteroItem.key] = note.key;
return data; return data;
}); });
return true return true;
} }
} }
await tldrs.modify((data: any) => { await tldrs.modify((data: any) => {

View File

@ -5,8 +5,8 @@
"target": "ES2016", "target": "ES2016",
"resolveJsonModule": true, "resolveJsonModule": true,
"skipLibCheck": true, "skipLibCheck": true,
"strict": true "strict": true,
}, },
"include": ["src", "typings", "node_modules/zotero-types"], "include": ["src", "typings", "node_modules/zotero-types"],
"exclude": ["build", "addon"] "exclude": ["build", "addon"],
} }