From 5580f04fd81870033f46ccea839714a14c823a10 Mon Sep 17 00:00:00 2001 From: Jiawei Duan Date: Sun, 10 Sep 2023 17:07:37 -0700 Subject: [PATCH] Initial commit --- .gitignore | 1 + Makefile | 28 ++ README.md | 2 + src/bootstrap.js | 37 ++ src/chrome.manifest | 4 + src/chrome/content/overlay.js | 5 + src/chrome/content/overlay.xul | 9 + src/chrome/content/test.js | 446 +++++++++++++++++++++ src/chrome/content/threadpool.js | 60 +++ src/chrome/content/utilities.js | 80 ++++ src/chrome/content/zotmeta.js | 217 ++++++++++ src/chrome/locale/en-US/zotmeta.properties | 1 + src/defaults/preferences/prefs.js | 0 src/install.rdf | 33 ++ src/locale/en-US/zotmeta.ftl | 2 + src/manifest.json | 15 + updates.json | 21 + updates.json.tmpl | 21 + 18 files changed, 982 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 README.md create mode 100644 src/bootstrap.js create mode 100644 src/chrome.manifest create mode 100644 src/chrome/content/overlay.js create mode 100644 src/chrome/content/overlay.xul create mode 100644 src/chrome/content/test.js create mode 100644 src/chrome/content/threadpool.js create mode 100644 src/chrome/content/utilities.js create mode 100644 src/chrome/content/zotmeta.js create mode 100644 src/chrome/locale/en-US/zotmeta.properties create mode 100644 src/defaults/preferences/prefs.js create mode 100644 src/install.rdf create mode 100644 src/locale/en-US/zotmeta.ftl create mode 100644 src/manifest.json create mode 100644 updates.json create mode 100644 updates.json.tmpl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9ec2acf --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +# Define variables +SRC_DIR := src +BUILD_DIR := build +VERSION:=$(shell grep em:version src/install.rdf | head -n 1 | sed -e 's/ *//' -e 's/<\/em:version>//') +ZIP_FILE_NAME := zotmeta-$(VERSION).xpi +ZIP_FILE_PATH := $(BUILD_DIR)/$(ZIP_FILE_NAME) +JSON_FILE := updates.json + + +# Default target +all: $(ZIP_FILE_PATH) $(JSON_FILE) + +# Target to zip all files in the source folder +$(ZIP_FILE_PATH): | $(BUILD_DIR) + (cd $(SRC_DIR) && zip -r $(abspath $@) .) + +# Target to generate a updates.json file +$(JSON_FILE): | $(BUILD_DIR) + jq ".addons[\"zotmeta@roadtodream.tech\"].updates[0].update_hash = \"sha256:`shasum -a 256 $(ZIP_FILE_PATH) | cut -d' ' -f1`\"" updates.json.tmpl | \ + jq ".addons[\"zotmeta@roadtodream.tech\"].updates[0].update_link = \"https://github.com/RoadToDream/ZotMeta/releases/download/v$(VERSION)/$(ZIP_FILE_NAME)\"" > $@ + +# Create the build directory if it doesn't exist +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + +# Clean up generated files +clean: + rm -rf $(BUILD_DIR) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..21ceb4f --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# ZotMeta: Metadata update tool +ZotMeta is a Zotero plugin to update articles metadata. diff --git a/src/bootstrap.js b/src/bootstrap.js new file mode 100644 index 0000000..7351835 --- /dev/null +++ b/src/bootstrap.js @@ -0,0 +1,37 @@ +var ZotMeta; + +function log(msg) { + Zotero.debug("ZotMeta: " + msg); +} + +function install() { + log("Installed"); +} + +async function startup({ id, version, rootURI }) { + log("Starting"); + + // Load chrome/content file directly via file:/// URL + Services.scriptloader.loadSubScript(rootURI + 'chrome/content/utilities.js'); + Services.scriptloader.loadSubScript(rootURI + 'chrome/content/threadpool.js'); + Services.scriptloader.loadSubScript(rootURI + 'chrome/content/zotmeta.js'); + ZotMeta.init({ id, version, rootURI }); + ZotMeta.addToAllWindows(); +} + +function onMainWindowLoad({ window }) { + ZotMeta.addToWindow(window); +} + +function onMainWindowUnload({ window }) { + ZotMeta.removeFromWindow(window); +} + +function shutdown() { + log("Shutting down"); + ZotMeta.removeFromAllWindows(); +} + +function uninstall() { + log("Uninstalled"); +} diff --git a/src/chrome.manifest b/src/chrome.manifest new file mode 100644 index 0000000..772489c --- /dev/null +++ b/src/chrome.manifest @@ -0,0 +1,4 @@ +content zotmeta chrome/content/ +skin zotmeta default chrome/skin/ +locale zotmeta en-US chrome/locale/en-US/ +overlay chrome://zotero/content/zoteroPane.xul chrome://zotmeta/content/overlay.xul diff --git a/src/chrome/content/overlay.js b/src/chrome/content/overlay.js new file mode 100644 index 0000000..8256bc9 --- /dev/null +++ b/src/chrome/content/overlay.js @@ -0,0 +1,5 @@ +window.addEventListener('load', async function (event) { + await Zotero.initializationPromise; + ZotMeta.init(); + ZotMeta.addToWindow(window); +}); diff --git a/src/chrome/content/overlay.xul b/src/chrome/content/overlay.xul new file mode 100644 index 0000000..f9c25c8 --- /dev/null +++ b/src/chrome/content/overlay.xul @@ -0,0 +1,9 @@ + + + +