fixs dialog
This commit is contained in:
parent
859e3c6b48
commit
6401334731
@ -1,31 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
<dialog
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="保存网页快照"
|
||||
buttons="accept,cancel"
|
||||
onload="onLoad();"
|
||||
ondialogaccept="return onAccept();"
|
||||
>
|
||||
<script>
|
||||
function onLoad() {
|
||||
document.getElementById("url-textbox").focus();
|
||||
}
|
||||
|
||||
function onAccept() {
|
||||
let url = document.getElementById("url-textbox").value;
|
||||
if (!url) {
|
||||
alert("请输入 URL");
|
||||
return false;
|
||||
}
|
||||
|
||||
window.arguments[0].callback(url);
|
||||
return true;
|
||||
}
|
||||
</script>
|
||||
|
||||
<vbox>
|
||||
<label value="请输入网页 URL:" />
|
||||
<textbox id="url-textbox" width="400" />
|
||||
</vbox>
|
||||
</dialog>
|
||||
40
addon/content/dialog.xhtml
Normal file
40
addon/content/dialog.xhtml
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- prettier-ignore -->
|
||||
<!DOCTYPE window>
|
||||
<!-- prettier-ignore -->
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
<!-- prettier-ignore -->
|
||||
<?xml-stylesheet href="chrome://zotero/skin/zotero.css" type="text/css"?>
|
||||
<!-- prettier-ignore -->
|
||||
<?xml-stylesheet href="chrome://zotero-platform/content/zotero.css" type="text/css"?>
|
||||
<!-- prettier-ignore -->
|
||||
<window
|
||||
id="__addonRef__-standalone"
|
||||
title="Save Web Snapshot Panel"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
windowtype="__addonRef__-standalone"
|
||||
persist="screenX screenY width height"
|
||||
onload=""
|
||||
>
|
||||
<xul:linkset>
|
||||
<html:link rel="localization" href="browser/menubar.ftl" />
|
||||
<html:link rel="localization" href="browser/browserSets.ftl" />
|
||||
<html:link rel="localization" href="toolkit/global/textActions.ftl" />
|
||||
<html:link rel="localization" href="zotero.ftl" />
|
||||
<html:link rel="localization" href="__addonRef__-standalone.ftl" />
|
||||
</xul:linkset>
|
||||
<script src="chrome://zotero/content/include.js"></script>
|
||||
<script src="chrome://zotero/content/customElements.js"></script>
|
||||
<script src="chrome://__addonRef__/content/scripts/customElements.js"></script>
|
||||
<vbox id="dialog-content" align="center">
|
||||
<label value="请输入网页 URL:" />
|
||||
<textbox id="url-textbox" width="200" height="300" />
|
||||
<hbox>
|
||||
<button id="add-source" value="添加" data-l10n-id="add-source" />
|
||||
<button id="pin-window" data-l10n-id="pin-window" />
|
||||
</hbox>
|
||||
</vbox>
|
||||
<html:div class="separator"></html:div>
|
||||
</window>
|
||||
@ -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
|
||||
tabpanel-reader-tab-label = Reader Tab
|
||||
snapshot-dialog-title = Snapshot
|
||||
@ -8,4 +8,5 @@ prefs-title = 插件模板
|
||||
prefs-table-title = 标题
|
||||
prefs-table-detail = 详情
|
||||
tabpanel-lib-tab-label = 库标签
|
||||
tabpanel-reader-tab-label = 阅读器标签
|
||||
tabpanel-reader-tab-label = 阅读器标签
|
||||
snapshot-dialog-title = 快照
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@ -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": {
|
||||
|
||||
42
src/hooks.ts
42
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<void> {
|
||||
})
|
||||
.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<void> {
|
||||
@ -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];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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();
|
||||
});
|
||||
|
||||
// 等待对话框关闭
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user