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>
|
||||||
@ -9,3 +9,4 @@ prefs-table-title = Title
|
|||||||
prefs-table-detail = Detail
|
prefs-table-detail = Detail
|
||||||
tabpanel-lib-tab-label = Lib Tab
|
tabpanel-lib-tab-label = Lib Tab
|
||||||
tabpanel-reader-tab-label = Reader Tab
|
tabpanel-reader-tab-label = Reader Tab
|
||||||
|
snapshot-dialog-title = Snapshot
|
||||||
@ -9,3 +9,4 @@ prefs-table-title = 标题
|
|||||||
prefs-table-detail = 详情
|
prefs-table-detail = 详情
|
||||||
tabpanel-lib-tab-label = 库标签
|
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",
|
"version": "3.0.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "zotero-plugin-template",
|
"name": "zetter",
|
||||||
"version": "3.0.2",
|
"version": "3.0.2",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
42
src/hooks.ts
42
src/hooks.ts
@ -5,7 +5,8 @@ import {
|
|||||||
PromptExampleFactory,
|
PromptExampleFactory,
|
||||||
UIExampleFactory,
|
UIExampleFactory,
|
||||||
} from "./modules/examples";
|
} 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 { getString, initLocale } from "./utils/locale";
|
||||||
import { registerPrefsScripts } from "./modules/preferenceScript";
|
import { registerPrefsScripts } from "./modules/preferenceScript";
|
||||||
@ -19,21 +20,8 @@ async function onStartup() {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
initLocale();
|
initLocale();
|
||||||
// BasicExampleFactory.registerPrefs();
|
|
||||||
|
|
||||||
// BasicExampleFactory.registerNotifier();
|
Zotero[config.addonInstance].views = new Views();
|
||||||
|
|
||||||
// KeyExampleFactory.registerShortcuts();
|
|
||||||
|
|
||||||
// await UIExampleFactory.registerExtraColumn();
|
|
||||||
|
|
||||||
// await UIExampleFactory.registerExtraColumnWithCustomCell();
|
|
||||||
|
|
||||||
// UIExampleFactory.registerItemPaneCustomInfoRow();
|
|
||||||
|
|
||||||
// UIExampleFactory.registerItemPaneSection();
|
|
||||||
|
|
||||||
// UIExampleFactory.registerReaderItemPaneSection();
|
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
Zotero.getMainWindows().map((win) => onMainWindowLoad(win)),
|
Zotero.getMainWindows().map((win) => onMainWindowLoad(win)),
|
||||||
@ -60,35 +48,19 @@ async function onMainWindowLoad(win: Window): Promise<void> {
|
|||||||
})
|
})
|
||||||
.show();
|
.show();
|
||||||
|
|
||||||
await Zotero.Promise.delay(1000);
|
await Zotero.Promise.delay(500);
|
||||||
popupWin.changeLine({
|
popupWin.changeLine({
|
||||||
progress: 30,
|
progress: 30,
|
||||||
text: `[30%] ${getString("startup-begin")}`,
|
text: `[30%] ${getString("startup-begin")}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// UIExampleFactory.registerStyleSheet(win);
|
// UIExampleFactory.registerRightClickMenuItem();
|
||||||
registerViews(win);
|
|
||||||
UIExampleFactory.registerRightClickMenuItem();
|
|
||||||
|
|
||||||
// UIExampleFactory.registerRightClickMenuPopup(win);
|
|
||||||
|
|
||||||
// UIExampleFactory.registerWindowMenuWithSeparator();
|
|
||||||
|
|
||||||
// PromptExampleFactory.registerNormalCommandExample();
|
|
||||||
|
|
||||||
// PromptExampleFactory.registerAnonymousCommandExample(win);
|
|
||||||
|
|
||||||
// PromptExampleFactory.registerConditionalCommandExample();
|
|
||||||
|
|
||||||
// await Zotero.Promise.delay(1000);
|
|
||||||
|
|
||||||
popupWin.changeLine({
|
popupWin.changeLine({
|
||||||
progress: 100,
|
progress: 100,
|
||||||
text: `[100%] ${getString("startup-finish")}`,
|
text: `[100%] ${getString("startup-finish")}`,
|
||||||
});
|
});
|
||||||
popupWin.startCloseTimer(3000);
|
popupWin.startCloseTimer(500);
|
||||||
|
|
||||||
// addon.hooks.onDialogEvents("dialogExample");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onMainWindowUnload(win: Window): Promise<void> {
|
async function onMainWindowUnload(win: Window): Promise<void> {
|
||||||
@ -101,7 +73,7 @@ function onShutdown(): void {
|
|||||||
addon.data.dialog?.window?.close();
|
addon.data.dialog?.window?.close();
|
||||||
// Remove addon object
|
// Remove addon object
|
||||||
addon.data.alive = false;
|
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 {
|
export class URLInputDialog {
|
||||||
private window: Window;
|
private window: Window;
|
||||||
private dialog: Window;
|
private dialog: Window | null;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.window = Zotero.getMainWindow();
|
this.window = Zotero.getMainWindow();
|
||||||
|
this.dialog = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public open() {
|
public open() {
|
||||||
@ -37,48 +38,48 @@ export class URLInputDialog {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 打开对话框
|
// 打开对话框
|
||||||
this.dialog = this.window.openDialog(
|
this.dialog = ztoolkit.getGlobal("openDialog")(
|
||||||
rootURI + "content/dialog/dialog.html",
|
`chrome://${config.addonRef}/content/dialog.xhtml`,
|
||||||
"",
|
"",
|
||||||
"chrome,centerscreen,resizable=false,width=500,height=200",
|
"chrome,centerscreen,resizable=false,width=500,height=300",
|
||||||
params,
|
params,
|
||||||
);
|
);
|
||||||
|
|
||||||
// 设置对话框内容和事件监听
|
// 设置对话框内容和事件监听
|
||||||
this.dialog.addEventListener("load", () => {
|
this.dialog!.addEventListener("load", () => {
|
||||||
const doc = this.dialog.document;
|
const doc = this.dialog!.document;
|
||||||
|
|
||||||
// 设置对话框标题
|
// 设置对话框标题
|
||||||
doc.title = getString("snapshot-dialog.title");
|
doc.title = getString("snapshot-dialog-title");
|
||||||
|
|
||||||
// 插入自定义内容
|
// 插入自定义内容
|
||||||
const container = doc.querySelector(".dialog-content");
|
const container = doc.getElementById("dialog-content");
|
||||||
container.innerHTML = dialogContent;
|
ztoolkit.log(container);
|
||||||
|
|
||||||
// 表单提交处理
|
// 表单提交处理
|
||||||
const form = doc.getElementById("snapshot-form") as HTMLFormElement;
|
// const form = doc.getElementById("snapshot-form") as HTMLFormElement;
|
||||||
form.addEventListener("submit", (e) => {
|
// form.addEventListener("submit", (e) => {
|
||||||
e.preventDefault();
|
// e.preventDefault();
|
||||||
const urlInput = doc.getElementById("url-input") as HTMLInputElement;
|
// const urlInput = doc.getElementById("url-input") as HTMLInputElement;
|
||||||
params.dataOut = {
|
// params.dataOut = {
|
||||||
url: urlInput.value,
|
// url: urlInput.value,
|
||||||
accepted: true,
|
// accepted: true,
|
||||||
};
|
// };
|
||||||
this.dialog.close();
|
// this.dialog?.close();
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 取消按钮处理
|
// 取消按钮处理
|
||||||
const cancelButton = doc.getElementById("cancel-button");
|
// const cancelButton = doc.getElementById("cancel-button")!;
|
||||||
cancelButton.addEventListener("click", () => {
|
// cancelButton.addEventListener("click", () => {
|
||||||
params.dataOut = {
|
// params.dataOut = {
|
||||||
accepted: false,
|
// accepted: false,
|
||||||
};
|
// };
|
||||||
this.dialog.close();
|
// this.dialog?.close();
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 自动聚焦到 URL 输入框
|
// 自动聚焦到 URL 输入框
|
||||||
const urlInput = doc.getElementById("url-input") as HTMLInputElement;
|
// const urlInput = doc.getElementById("url-input") as HTMLInputElement;
|
||||||
urlInput.focus();
|
// urlInput.focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 等待对话框关闭
|
// 等待对话框关闭
|
||||||
|
|||||||
@ -2,21 +2,38 @@ import { config } from "../../package.json";
|
|||||||
import { getString } from "../utils/locale";
|
import { getString } from "../utils/locale";
|
||||||
import { URLInputDialog } from "./urlDialog";
|
import { URLInputDialog } from "./urlDialog";
|
||||||
|
|
||||||
export async function registerViews(window: Window) {
|
export default class Views {
|
||||||
// 注册工具栏按钮
|
private id = "zotero-zetter-container";
|
||||||
ztoolkit.UI.createElement(window.document, "button", {
|
constructor() {
|
||||||
id: `${config.addonRef}-toolbar-button`,
|
this.registerViews();
|
||||||
listeners: [
|
}
|
||||||
{
|
private registerViews() {
|
||||||
type: "click",
|
const papersgptNode = Zotero.getMainWindow().document.querySelector(
|
||||||
listener: (e) => {
|
"#" + this.id,
|
||||||
const dialog = new URLInputDialog();
|
)!;
|
||||||
dialog.open();
|
if (papersgptNode) {
|
||||||
dialog.saveSnapshot(
|
return;
|
||||||
"https://blog.csdn.net/qq_43210428/article/details/120384547",
|
}
|
||||||
);
|
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