From 640133473166a675bb20fccc290e8eb381e9d9cd Mon Sep 17 00:00:00 2001
From: denislov <2864326614@qq.com>
Date: Fri, 17 Jan 2025 23:11:52 +0800
Subject: [PATCH] fixs dialog
---
addon/content/dialog.html | 31 --------------------
addon/content/dialog.xhtml | 40 +++++++++++++++++++++++++
addon/locale/en-US/addon.ftl | 3 +-
addon/locale/zh-CN/addon.ftl | 3 +-
package-lock.json | 4 +--
src/hooks.ts | 42 +++++---------------------
src/modules/urlDialog.ts | 57 ++++++++++++++++++------------------
src/modules/views.ts | 51 +++++++++++++++++++++-----------
8 files changed, 116 insertions(+), 115 deletions(-)
delete mode 100644 addon/content/dialog.html
create mode 100644 addon/content/dialog.xhtml
diff --git a/addon/content/dialog.html b/addon/content/dialog.html
deleted file mode 100644
index a356b31..0000000
--- a/addon/content/dialog.html
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
diff --git a/addon/content/dialog.xhtml b/addon/content/dialog.xhtml
new file mode 100644
index 0000000..cd24abe
--- /dev/null
+++ b/addon/content/dialog.xhtml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/addon/locale/en-US/addon.ftl b/addon/locale/en-US/addon.ftl
index 892d267..51b1064 100644
--- a/addon/locale/en-US/addon.ftl
+++ b/addon/locale/en-US/addon.ftl
@@ -8,4 +8,5 @@ prefs-title = Template
prefs-table-title = Title
prefs-table-detail = Detail
tabpanel-lib-tab-label = Lib Tab
-tabpanel-reader-tab-label = Reader Tab
\ No newline at end of file
+tabpanel-reader-tab-label = Reader Tab
+snapshot-dialog-title = Snapshot
\ No newline at end of file
diff --git a/addon/locale/zh-CN/addon.ftl b/addon/locale/zh-CN/addon.ftl
index 16d97d3..6691918 100644
--- a/addon/locale/zh-CN/addon.ftl
+++ b/addon/locale/zh-CN/addon.ftl
@@ -8,4 +8,5 @@ prefs-title = 插件模板
prefs-table-title = 标题
prefs-table-detail = 详情
tabpanel-lib-tab-label = 库标签
-tabpanel-reader-tab-label = 阅读器标签
\ No newline at end of file
+tabpanel-reader-tab-label = 阅读器标签
+snapshot-dialog-title = 快照
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index 0d0c86a..09b477e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,11 +1,11 @@
{
- "name": "zotero-plugin-template",
+ "name": "zetter",
"version": "3.0.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
- "name": "zotero-plugin-template",
+ "name": "zetter",
"version": "3.0.2",
"license": "AGPL-3.0-or-later",
"dependencies": {
diff --git a/src/hooks.ts b/src/hooks.ts
index def69bb..e152c97 100644
--- a/src/hooks.ts
+++ b/src/hooks.ts
@@ -5,7 +5,8 @@ import {
PromptExampleFactory,
UIExampleFactory,
} from "./modules/examples";
-import { registerViews } from "./modules/views";
+import { config } from "../package.json";
+import Views from "./modules/views";
import { getString, initLocale } from "./utils/locale";
import { registerPrefsScripts } from "./modules/preferenceScript";
@@ -19,21 +20,8 @@ async function onStartup() {
]);
initLocale();
- // BasicExampleFactory.registerPrefs();
- // BasicExampleFactory.registerNotifier();
-
- // KeyExampleFactory.registerShortcuts();
-
- // await UIExampleFactory.registerExtraColumn();
-
- // await UIExampleFactory.registerExtraColumnWithCustomCell();
-
- // UIExampleFactory.registerItemPaneCustomInfoRow();
-
- // UIExampleFactory.registerItemPaneSection();
-
- // UIExampleFactory.registerReaderItemPaneSection();
+ Zotero[config.addonInstance].views = new Views();
await Promise.all(
Zotero.getMainWindows().map((win) => onMainWindowLoad(win)),
@@ -60,35 +48,19 @@ async function onMainWindowLoad(win: Window): Promise {
})
.show();
- await Zotero.Promise.delay(1000);
+ await Zotero.Promise.delay(500);
popupWin.changeLine({
progress: 30,
text: `[30%] ${getString("startup-begin")}`,
});
- // UIExampleFactory.registerStyleSheet(win);
- registerViews(win);
- UIExampleFactory.registerRightClickMenuItem();
-
- // UIExampleFactory.registerRightClickMenuPopup(win);
-
- // UIExampleFactory.registerWindowMenuWithSeparator();
-
- // PromptExampleFactory.registerNormalCommandExample();
-
- // PromptExampleFactory.registerAnonymousCommandExample(win);
-
- // PromptExampleFactory.registerConditionalCommandExample();
-
- // await Zotero.Promise.delay(1000);
+ // UIExampleFactory.registerRightClickMenuItem();
popupWin.changeLine({
progress: 100,
text: `[100%] ${getString("startup-finish")}`,
});
- popupWin.startCloseTimer(3000);
-
- // addon.hooks.onDialogEvents("dialogExample");
+ popupWin.startCloseTimer(500);
}
async function onMainWindowUnload(win: Window): Promise {
@@ -101,7 +73,7 @@ function onShutdown(): void {
addon.data.dialog?.window?.close();
// Remove addon object
addon.data.alive = false;
- delete Zotero[addon.data.config.addonInstance];
+ delete Zotero[config.addonInstance];
}
/**
diff --git a/src/modules/urlDialog.ts b/src/modules/urlDialog.ts
index 2825068..a718afc 100644
--- a/src/modules/urlDialog.ts
+++ b/src/modules/urlDialog.ts
@@ -3,10 +3,11 @@ import { getString } from "../utils/locale";
export class URLInputDialog {
private window: Window;
- private dialog: Window;
+ private dialog: Window | null;
constructor() {
this.window = Zotero.getMainWindow();
+ this.dialog = null;
}
public open() {
@@ -37,48 +38,48 @@ export class URLInputDialog {
};
// 打开对话框
- this.dialog = this.window.openDialog(
- rootURI + "content/dialog/dialog.html",
+ this.dialog = ztoolkit.getGlobal("openDialog")(
+ `chrome://${config.addonRef}/content/dialog.xhtml`,
"",
- "chrome,centerscreen,resizable=false,width=500,height=200",
+ "chrome,centerscreen,resizable=false,width=500,height=300",
params,
);
// 设置对话框内容和事件监听
- this.dialog.addEventListener("load", () => {
- const doc = this.dialog.document;
+ this.dialog!.addEventListener("load", () => {
+ const doc = this.dialog!.document;
// 设置对话框标题
- doc.title = getString("snapshot-dialog.title");
+ doc.title = getString("snapshot-dialog-title");
// 插入自定义内容
- const container = doc.querySelector(".dialog-content");
- container.innerHTML = dialogContent;
+ const container = doc.getElementById("dialog-content");
+ ztoolkit.log(container);
// 表单提交处理
- const form = doc.getElementById("snapshot-form") as HTMLFormElement;
- form.addEventListener("submit", (e) => {
- e.preventDefault();
- const urlInput = doc.getElementById("url-input") as HTMLInputElement;
- params.dataOut = {
- url: urlInput.value,
- accepted: true,
- };
- this.dialog.close();
- });
+ // const form = doc.getElementById("snapshot-form") as HTMLFormElement;
+ // form.addEventListener("submit", (e) => {
+ // e.preventDefault();
+ // const urlInput = doc.getElementById("url-input") as HTMLInputElement;
+ // params.dataOut = {
+ // url: urlInput.value,
+ // accepted: true,
+ // };
+ // this.dialog?.close();
+ // });
// 取消按钮处理
- const cancelButton = doc.getElementById("cancel-button");
- cancelButton.addEventListener("click", () => {
- params.dataOut = {
- accepted: false,
- };
- this.dialog.close();
- });
+ // const cancelButton = doc.getElementById("cancel-button")!;
+ // cancelButton.addEventListener("click", () => {
+ // params.dataOut = {
+ // accepted: false,
+ // };
+ // this.dialog?.close();
+ // });
// 自动聚焦到 URL 输入框
- const urlInput = doc.getElementById("url-input") as HTMLInputElement;
- urlInput.focus();
+ // const urlInput = doc.getElementById("url-input") as HTMLInputElement;
+ // urlInput.focus();
});
// 等待对话框关闭
diff --git a/src/modules/views.ts b/src/modules/views.ts
index acb2eb8..107aec7 100644
--- a/src/modules/views.ts
+++ b/src/modules/views.ts
@@ -2,21 +2,38 @@ import { config } from "../../package.json";
import { getString } from "../utils/locale";
import { URLInputDialog } from "./urlDialog";
-export async function registerViews(window: Window) {
- // 注册工具栏按钮
- ztoolkit.UI.createElement(window.document, "button", {
- id: `${config.addonRef}-toolbar-button`,
- listeners: [
- {
- type: "click",
- listener: (e) => {
- const dialog = new URLInputDialog();
- dialog.open();
- dialog.saveSnapshot(
- "https://blog.csdn.net/qq_43210428/article/details/120384547",
- );
- },
- },
- ],
- });
+export default class Views {
+ private id = "zotero-zetter-container";
+ constructor() {
+ this.registerViews();
+ }
+ private registerViews() {
+ const papersgptNode = Zotero.getMainWindow().document.querySelector(
+ "#" + this.id,
+ )!;
+ if (papersgptNode) {
+ return;
+ }
+ const toolbar = Zotero.getMainWindow().document.querySelector(
+ "#zotero-items-toolbar",
+ )!;
+ const lookupNode = toolbar.querySelector("#zotero-tb-lookup")!;
+ const newNode = lookupNode?.cloneNode(true) as XULToolBarButtonElement;
+ newNode.setAttribute("id", this.id);
+ newNode.setAttribute("tooltiptext", "Zotero Better Plugin");
+ newNode.setAttribute("command", "");
+ newNode.setAttribute("oncommand", "");
+ newNode.setAttribute("mousedown", "");
+ newNode.setAttribute("onmousedown", "");
+ newNode.addEventListener("click", async (event: any) => {
+ const papersgptState = Zotero.Prefs.get(
+ `${config.addonRef}.papersgptState`,
+ );
+ const dialog = new URLInputDialog();
+ dialog.open();
+ });
+ const searchNode = toolbar.querySelector("#zotero-tb-search");
+ newNode.style.listStyleImage = `url(chrome://${config.addonRef}/content/icons/favicon.png)`;
+ toolbar.insertBefore(newNode, searchNode);
+ }
}