Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
MuiseDestiny committed Jan 10, 2023
1 parent 89612a9 commit 3bc9840
Show file tree
Hide file tree
Showing 42 changed files with 10,642 additions and 135 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GITHUB_TOKEN="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"
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
**/builds
node_modules
package-lock.json
zotero-cmd.json
.vscode
.env
zotero-cmd.json
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
17 changes: 1 addition & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,2 @@
# 新版预览图
![ac5fa8b94cc961330e710186dfb33b8](https://user-images.githubusercontent.com/51939531/211480906-2192dcfd-7798-4809-9ee1-89a94b6dacd6.png)
做一些简单的可视化
![image](https://user-images.githubusercontent.com/51939531/211244957-cc6f293f-ba83-4325-bca0-47b10f461ee3.png)














149 changes: 94 additions & 55 deletions addon/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,117 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http:https://mozilla.org/MPL/2.0/. */

"use strict";
/* global Components, Services */
/* global addon, APP_SHUTDOWN */
const { classes: Cc, utils: Cu } = Components;
if (typeof Zotero == "undefined") {
var Zotero;
}

Cu.import("resource:https://gre/modules/Services.jsm");
var chromeHandle;

function install(data, reason) {
// console.log(data, reason)
console.log("install")
// In Zotero 6, bootstrap methods are called before Zotero is initialized, and using include.js
// to get the Zotero XPCOM service would risk breaking Zotero startup. Instead, wait for the main
// Zotero window to open and get the Zotero object from there.
//
// In Zotero 7, bootstrap methods are not called until Zotero is initialized, and the 'Zotero' is
// automatically made available.
async function waitForZotero() {
if (typeof Zotero != "undefined") {
await Zotero.initializationPromise;
}

var { Services } = ChromeUtils.import("resource:https://gre/modules/Services.jsm");
var windows = Services.wm.getEnumerator("navigator:browser");
var found = false;
while (windows.hasMoreElements()) {
let win = windows.getNext();
if (win.Zotero) {
Zotero = win.Zotero;
found = true;
break;
}
}
if (!found) {
await new Promise((resolve) => {
var listener = {
onOpenWindow: function (aWindow) {
// Wait for the window to finish loading
let domWindow = aWindow
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
domWindow.addEventListener(
"load",
function () {
domWindow.removeEventListener("load", arguments.callee, false);
if (domWindow.Zotero) {
Services.wm.removeListener(listener);
Zotero = domWindow.Zotero;
resolve();
}
},
false
);
},
};
Services.wm.addListener(listener);
});
}
await Zotero.initializationPromise;
}

function startup(data, reason) {
// Load the addon to Zotero if window is ready
console.log("startup")
const loadAddon = (window) => {
console.log(window);
if (window.document.readyState === "complete" && window.Zotero) {
Services.scriptloader.loadSubScript(
"chrome:https://__addonRef__/content/scripts/index.js"
);
} else {
window.addEventListener("load", (e) => {
if (window.Zotero) {
Services.scriptloader.loadSubScript(
"chrome:https://__addonRef__/content/scripts/index.js"
);
}
});
}
};
function install(data, reason) {}

// Listen to windows
var WindowListener = {
onOpenWindow: function (xulWindow) {
loadAddon(
xulWindow
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow)
);
},
};
Services.wm.addListener(WindowListener);
async function startup({ id, version, resourceURI, rootURI }, reason) {
await waitForZotero();

// Scan current windows
const windows = Services.wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
loadAddon(
windows.getNext().QueryInterface(Components.interfaces.nsIDOMWindow)
);
if (Zotero.platformMajorVersion >= 102) {
var aomStartup = Components.classes[
"@mozilla.org/addons/addon-manager-startup;1"
].getService(Components.interfaces.amIAddonManagerStartup);
var manifestURI = Services.io.newURI(rootURI + "manifest.json");
chromeHandle = aomStartup.registerChrome(manifestURI, [
["content", "__addonRef__", rootURI + "chrome/content/"],
["locale", "__addonRef__", "en-US", rootURI + "chrome/locale/en-US/"],
["locale", "__addonRef__", "zh-CN", rootURI + "chrome/locale/zh-CN/"],
]);
}

// String 'rootURI' introduced in Zotero 7
if (!rootURI) {
rootURI = resourceURI.spec;
}

// Global variables for plugin code
const ctx = {
rootURI,
};
ctx._globalThis = ctx;

Services.scriptloader.loadSubScript(
`${rootURI}/chrome/content/scripts/index.js`,
ctx
);
}

function shutdown(data, reason) {
console.log("shutdown")
function shutdown({ id, version, resourceURI, rootURI }, reason) {
if (reason === APP_SHUTDOWN) {
return;
}
var _Zotero = Components.classes["@zotero.org/Zotero;1"].getService(
Components.interfaces.nsISupports
).wrappedJSObject;
_Zotero.ZoteroStyle.events.onUnInit(_Zotero);
if (typeof Zotero === "undefined") {
Zotero = Components.classes["@zotero.org/Zotero;1"].getService(
Components.interfaces.nsISupports
).wrappedJSObject;
}
Zotero.AddonTemplate.hooks.onShutdown();

Cc["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService)
.flushBundles();

Cu.unload("chrome:https://_addonRef__/scripts/index.js");
}
Cu.unload(`${rootURI}/chrome/content/scripts/index.js`);

function uninstall(data, reason) {
// console.log(data, reason)
console.log("uninstall")
if (chromeHandle) {
chromeHandle.destruct();
chromeHandle = null;
}
}

function uninstall(data, reason) {}
2 changes: 0 additions & 2 deletions addon/chrome.manifest
Original file line number Diff line number Diff line change
@@ -1,5 +1,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/

20 changes: 20 additions & 0 deletions addon/chrome/content/addView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";

var AddView = new function () {
var _io;
var _window;
this.init = function (_window) {
this._io = window.arguments[0]
this._window = _window
console.log("init", this._io)
};

this.onDialogAccept = function () {
this._io.name = this._window.document.querySelector("#view-name").value
this._io.content = this._window.document.querySelector("#view-content").value
console.log("onDialogAccept", this._io)
};

this.onDialogCancel = function () {
};
};
27 changes: 27 additions & 0 deletions addon/chrome/content/addView.xul
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome:https://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome:https://zotero/skin/zotero.css" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome:https://zotero/locale/zotero.dtd">

<dialog xmlns="http:https://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="New View" buttons="cancel,accept"
id="save-current-view"
buttonlabelaccept="Add"
buttonlabelextra1="Add"
ondialogaccept="AddView.onDialogAccept()"
ondialogcancel="AddView.onDialogCancel()"
onload="AddView.init(window)"
width="350"
height="250">

<script src="include.js"/>
<script src="addView.js"/>

<vbox id="container">
<label value="Name"/>
<textbox id="view-name" flex="1"></textbox>
<separator/>
<label value="Content"/>
<textbox id="view-content" multiline="true" rows="4" flex="1"></textbox>
</vbox>
</dialog>
Binary file added addon/chrome/content/icons/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added addon/chrome/content/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions addon/chrome/content/preferences.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<vbox
id="zotero-prefpane-__addonRef__"
onload="Zotero.AddonTemplate.hooks.onPrefsEvent('load', {window})"
>
<groupbox>
<label><html:h2>&zotero.__addonRef__.pref.title;</html:h2></label>
<checkbox
id="zotero-prefpane-__addonRef__-enable"
label="&zotero.__addonRef__.pref.enable.label;"
preference="extensions.zotero.__addonRef__.enable"
/>
<hbox>
<html:label for="zotero-prefpane-__addonRef__-input"
>&zotero.__addonRef__.pref.input.label;</html:label
>
<html:input
type="text"
id="zotero-prefpane-__addonRef__-input"
preference="extensions.zotero.__addonRef__.input"
></html:input>
</hbox>
</groupbox>
</vbox>
<vbox>
<label
value="&zotero.__addonRef__.help.version.label; &zotero.__addonRef__.help.releasetime.label;"
></label>
</vbox>
15 changes: 15 additions & 0 deletions addon/chrome/content/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.tag-box .tag-swatch {
position: absolute;
display: inline-block;
height: .9em;
width: .9em;
border-radius: 100%;
font-size: 1em;
}

.tag-box {
display: inline-block;
position: relative;
height: 1em;
line-height: 1em;
}
9 changes: 9 additions & 0 deletions addon/chrome/locale/en-US/addon.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
startup.begin=Addon is loading
startup.finish=Addon is ready
menuitem.label=Addon Template: Menuitem
menupopup.label=Addon Template: Menupopup
menuitem.submenulabel=Addon Template
menuitem.filemenulabel=Addon Template: File Menuitem
prefs.title=Template
tabpanel.lib.tab.label=Lib Tab
tabpanel.reader.tab.label=Reader Tab
7 changes: 7 additions & 0 deletions addon/chrome/locale/en-US/overlay.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!ENTITY zotero.__addonRef__.pref.title "Addon Template Example">
<!ENTITY zotero.__addonRef__.itemmenu.test.label "addon template">
<!ENTITY zotero.__addonRef__.pref.enable.label "Enable">
<!ENTITY zotero.__addonRef__.pref.input.label "Input">

<!ENTITY zotero.__addonRef__.help.version.label "__addonName__ VERSION __buildVersion__">
<!ENTITY zotero.__addonRef__.help.releasetime.label "Build __buildTime__">
9 changes: 9 additions & 0 deletions addon/chrome/locale/zh-CN/addon.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
startup.begin=插件加载中
startup.finish=插件已就绪
menuitem.label=插件模板: 菜单
menupopup.label=插件模板: 弹出菜单
menuitem.submenulabel=插件模板:子菜单
menuitem.filemenulabel=插件模板: 文件菜单
prefs.title=插件模板
tabpanel.lib.tab.label=库标签
tabpanel.reader.tab.label=阅读器标签
7 changes: 7 additions & 0 deletions addon/chrome/locale/zh-CN/overlay.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!ENTITY zotero.__addonRef__.pref.title "插件模板设置示例">
<!ENTITY zotero.__addonRef__.itemmenu.test.label "插件模板">
<!ENTITY zotero.__addonRef__.pref.enable.label "开启">
<!ENTITY zotero.__addonRef__.pref.input.label "输入">

<!ENTITY zotero.__addonRef__.help.version.label "__addonName__ 版本 __buildVersion__">
<!ENTITY zotero.__addonRef__.help.releasetime.label "Build __buildTime__">
23 changes: 23 additions & 0 deletions addon/defaults/preferences/defaults.js
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
pref("extensions.zotero.__addonRef__.enable", true);

pref("extensions.zotero.__addonRef__.tagsColumn.align", "left");
pref("extensions.zotero.__addonRef__.tagsColumn.margin", "0.35");


pref("extensions.zotero.__addonRef__.titleColumn.color", "#FFC6D3");
pref("extensions.zotero.__addonRef__.titleColumn.opacity", "0.7");

pref("extensions.zotero.__addonRef__.IFColumn.color", "#A8D1D1");
pref("extensions.zotero.__addonRef__.IFColumn.opacity", "0.7");

pref("extensions.zotero.__addonRef__.progressColumn.color", "#86C8BC");
pref("extensions.zotero.__addonRef__.progressColumn.opacity", "0.7");
pref("extensions.zotero.__addonRef__.progressColumn.circle", true);

pref("extensions.zotero.__addonRef__.columnsViews", "[]");







2 changes: 1 addition & 1 deletion addon/install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
em:creator="__author__"
em:description="__description__"
em:homepageURL="__homepage__"
em:iconURL="chrome:https://__addonRef__/skin/favicon.png"
em:iconURL="chrome:https://__addonRef__/content/icons/favicon.png"
em:optionsURL="chrome:https://__addonRef__/content/preferences.xul"
em:updateURL="__updaterdf__"
em:multiprocessCompatible="true"
Expand Down
Loading

0 comments on commit 3bc9840

Please sign in to comment.