diff --git a/README.md b/README.md index 51a9405..731fbef 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,12 @@ This is an addon/plugin template for [Zotero](https://www.zotero.org/). +[Documentation](https://zotero.yuque.com/books/share/8d230829-6004-4934-b4c6-685a7001bfa0/vec88d)(Chinese, provides English translation) + +> πŸ‘You are currently in `bootstrap` extension mode. To use `overlay` mode, plsase switch to `overlay` branch in git. + +> ⚠️`overlay` mode will no longer be supported in the coming Zotero 7. Please use the `bootstrap` extension mode instead. See discussion here: https://groups.google.com/g/zotero-dev/c/TT_rcLVpQwg + ## Features - TypeScript support; @@ -49,7 +55,7 @@ This section shows the directory structure of a template. ```shell β”‚ .gitignore β”‚ .release-it.json # release-it conf -| jsconfig.json # https://code.visualstudio.com/docs/languages/jsconfig# +| tsconfig.json # https://code.visualstudio.com/docs/languages/jsconfig# β”‚ build.js # esbuild β”‚ LICENSE β”‚ package.json # npm conf @@ -61,10 +67,10 @@ This section shows the directory structure of a template. β”œβ”€addon # addon dir β”‚ β”‚ chrome.manifest #addon conf β”‚ β”‚ install.rdf # addon install conf +β”‚ β”‚ bootstrap.js # addon load/unload script, like a main.c β”‚ β”‚ β”‚ └─chrome β”‚ β”œβ”€content # UI -β”‚ β”‚ β”‚ overlay.xul β”‚ β”‚ β”‚ preferences.xul β”‚ β”‚ β”‚ β”‚ β”‚ └─scripts @@ -152,6 +158,8 @@ You can also debug code in these ways: Zotero docs are outdated or incomplete. Searching the source code of Zotero is unavoidable. Clone https://github.com/zotero/zotero and search the keyword globally. You can search the UI text in `.xul`/`.dtd` files, and then search the keys of the text value in `.js`/`.xul` files. +> ⭐The [zotero-types](https://github.com/windingwind/zotero-types) provides most frequently used Zotero APIs. It's included in this template by default. + ## Disclaimer Use this code under AGPL. No warranties are provided. Keep the laws of your locality in mind! diff --git a/addon/bootstrap.js b/addon/bootstrap.js new file mode 100644 index 0000000..a22fe5b --- /dev/null +++ b/addon/bootstrap.js @@ -0,0 +1,71 @@ +/* Copyright 2012 Will Shanks. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; +/* global Components, Services */ +/* global addon, APP_SHUTDOWN */ +const { classes: Cc, utils: Cu } = Components; + +Cu.import("resource://gre/modules/Services.jsm"); + +function install(data, reason) {} + +function startup(data, reason) { + // Load the addon to Zotero if window is ready + const loadAddon = (window) => { + console.log(window); + if (window.document.readyState === "complete" && window.Zotero) { + Services.scriptloader.loadSubScript( + "chrome://__addonRef__/content/scripts/index.js" + ); + } else { + window.addEventListener("load", (e) => { + if (window.Zotero) { + Services.scriptloader.loadSubScript( + "chrome://__addonRef__/content/scripts/index.js" + ); + } + }); + } + }; + + // Listen to windows + var WindowListener = { + onOpenWindow: function (xulWindow) { + loadAddon( + xulWindow + .QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsIDOMWindow) + ); + }, + }; + Services.wm.addListener(WindowListener); + + // Scan current windows + const windows = Services.wm.getEnumerator("navigator:browser"); + while (windows.hasMoreElements()) { + loadAddon( + windows.getNext().QueryInterface(Components.interfaces.nsIDOMWindow) + ); + } +} + +function shutdown(data, reason) { + if (reason === APP_SHUTDOWN) { + return; + } + var _Zotero = Components.classes["@zotero.org/Zotero;1"].getService( + Components.interfaces.nsISupports + ).wrappedJSObject; + _Zotero.AddonTemplate.events.onUnInit(_Zotero); + + Cc["@mozilla.org/intl/stringbundle;1"] + .getService(Components.interfaces.nsIStringBundleService) + .flushBundles(); + + Cu.unload("chrome://_addonRef__/scripts/index.js"); +} + +function uninstall(data, reason) {} diff --git a/addon/chrome.manifest b/addon/chrome.manifest index 59b2482..6c33bcd 100644 --- a/addon/chrome.manifest +++ b/addon/chrome.manifest @@ -2,6 +2,3 @@ content __addonRef__ chrome/content/ skin __addonRef__ default chrome/skin/default/__addonRef__/ locale __addonRef__ en-US chrome/locale/en-US/ locale __addonRef__ zh-CN chrome/locale/zh-CN/ - -overlay chrome://zotero/content/zoteroPane.xul chrome://__addonRef__/content/overlay.xul -overlay chrome://zotero/content/preferences/preferences.xul chrome://__addonRef__/content/preferences.xul diff --git a/addon/chrome/content/overlay.xul b/addon/chrome/content/overlay.xul deleted file mode 100644 index 08a0402..0000000 --- a/addon/chrome/content/overlay.xul +++ /dev/null @@ -1,11 +0,0 @@ - - - - - -