diff --git a/addon/chrome/content/icons/favicon@16.png b/addon/chrome/content/icons/favicon@16.png new file mode 100644 index 0000000..5b2a97a Binary files /dev/null and b/addon/chrome/content/icons/favicon@16.png differ diff --git a/addon/chrome/content/icons/favicon@20.png b/addon/chrome/content/icons/favicon@20.png new file mode 100644 index 0000000..0b500ea Binary files /dev/null and b/addon/chrome/content/icons/favicon@20.png differ diff --git a/addon/locale/en-US/mainWindow.ftl b/addon/locale/en-US/mainWindow.ftl new file mode 100644 index 0000000..73c8f57 --- /dev/null +++ b/addon/locale/en-US/mainWindow.ftl @@ -0,0 +1,4 @@ +itemPaneSection-header = + .label = 翻译 +itemPaneSection-sidenav = + .tooltiptext = 翻译 \ No newline at end of file diff --git a/addon/locale/zh-CN/mainWindow.ftl b/addon/locale/zh-CN/mainWindow.ftl new file mode 100644 index 0000000..73c8f57 --- /dev/null +++ b/addon/locale/zh-CN/mainWindow.ftl @@ -0,0 +1,4 @@ +itemPaneSection-header = + .label = 翻译 +itemPaneSection-sidenav = + .tooltiptext = 翻译 \ No newline at end of file diff --git a/package.json b/package.json index 08d20aa..39ff559 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ }, "homepage": "https://github.com/syt2/zotero-tldr#readme", "dependencies": { - "zotero-plugin-toolkit": "^2.3.25" + "zotero-plugin-toolkit": "^2.3.29" }, "devDependencies": { "@types/node": "^20.4.2", @@ -58,6 +58,6 @@ "release-it": "^16.1.0", "replace-in-file": "^7.0.1", "typescript": "^5.1.6", - "zotero-types": "^1.0.16" + "zotero-types": "^1.3.11" } -} +} \ No newline at end of file diff --git a/src/modules/Common.ts b/src/modules/Common.ts index b8b6207..7099869 100644 --- a/src/modules/Common.ts +++ b/src/modules/Common.ts @@ -73,6 +73,46 @@ export class UIFactory { // tldr行 static async registerTLDRItemBoxRow() { + const registeredID = Zotero.ItemPaneManager.registerSection({ + paneID: config.addonRef, + pluginID: config.addonID, + header: { + l10nID: `${config.addonRef}-itemPaneSection-header`, + icon: `chrome://${config.addonRef}/content/icons/favicon@16.png`, + }, + sidenav: { + l10nID: `${config.addonRef}-itemPaneSection-sidenav`, + icon: `chrome://${config.addonRef}/content/icons/favicon@20.png`, + }, + onRender: ({ body, item, editable, tabType }: any) => { + const noteKey = tldrs.get()[item.key]; + let str = ""; + if (noteKey) { + const obj = Zotero.Items.getByLibraryAndKey(item.libraryID, noteKey); + if ( + obj && + obj instanceof Zotero.Item && + item.getNotes().includes(obj.id) + ) { + str = obj.getNote(); + if (str.startsWith("

TL;DR

\n

")) { + str = str.slice("

TL;DR

\n

".length); + } + if (str.endsWith("

")) { + str = str.slice(0, -4); + } + } + } + body.textContent = str; + // body.textContent + // = JSON.stringify({ + // id: item?.id, + // editable, + // tabType, + // }); + }, + }); + return; await ztoolkit.ItemBox.register( "TLDR", getString("itembox-tldrlabel"),