From e19b4f5414bea0773fea85f0a311a73d4d4fd746 Mon Sep 17 00:00:00 2001 From: l0o0 Date: Thu, 7 Sep 2023 17:09:57 +0800 Subject: [PATCH 1/6] =?UTF-8?q?fix:=20=E9=83=A8=E5=88=86=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E8=BD=AC=E6=8D=A2=E5=99=A8=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=EF=BC=8C=E5=BC=BA=E5=88=B6=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks.ts | 40 +++++++++++++++++++++++++++++++++ src/modules/preferenceScript.ts | 9 ++++---- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/hooks.ts b/src/hooks.ts index 0ddb4e5..44b964f 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -7,6 +7,7 @@ import { config } from "../package.json"; import { getString, initLocale } from "./utils/locale"; import { registerPrefsScripts } from "./modules/preferenceScript"; import { displayMenuitem } from "../src/modules/ui"; +import { showPop } from "./utils/window"; async function onStartup() { await Promise.all([ @@ -20,6 +21,23 @@ async function onStartup() { `chrome://${config.addonRef}/content/icons/icon.png` ); + const popupWin = new ztoolkit.ProgressWindow(config.addonName, { + closeOnClick: true, + closeTime: -1, + }) + .createLine({ + text: "startup-begin", + type: "default", + progress: 0, + }) + .show(); + + popupWin.changeLine({ + progress: 30, + text: `[30%] startup-begin`, + }); + + BasicExampleFactory.registerPrefs(); BasicExampleFactory.registerNotifier(); @@ -48,6 +66,9 @@ async function onStartup() { displayMenuitem, false ); + + // Migrate Prefs from Zotero 6 to 7 + migratePrefs(); } function onShutdown(): void { @@ -79,6 +100,25 @@ async function onNotify( } } + +// Run this when addon is first run +// Keep preferences startswith extensions.zotero.jasminum +function migratePrefs() { + ztoolkit.log("start to migrate"); + if ( Zotero.Prefs.get("jasminum.firstrun") != false ) { + const extensionBranch = Services.prefs.getBranch("extensions"); + const prefs = extensionBranch.getChildList("", {}); + const jasminmPrefs = prefs.filter((p: string) => p.includes(".jasminum.")) + const shortJasminumPrefs = jasminmPrefs.filter( (p: string) => p.startsWith(".jasminum.")); + shortJasminumPrefs.array.forEach((ele: string) => { + ztoolkit.log("extensions" + ele); + Zotero.Prefs.clear("extensions" + ele, true); + showPop("extensions" + ele); + }); + Zotero.Prefs.set("jasminum.firstrun", false); + } +} + /** * This function is just an example of dispatcher for Preference UI events. * Any operations should be placed in a function to keep this funcion clear. diff --git a/src/modules/preferenceScript.ts b/src/modules/preferenceScript.ts index 3521005..dcd1bc3 100644 --- a/src/modules/preferenceScript.ts +++ b/src/modules/preferenceScript.ts @@ -110,8 +110,8 @@ async function insertTable(): Promise { } async function updateTranslatorData(refresh = true): Promise { - const translatorUrl = Zotero.Prefs.get("jasminum.translatorurl"); - const url = translatorUrl + "/data/translators.json"; + const baseUrl = Zotero.Prefs.get("jasminum.translatorurl") ? Zotero.Prefs.get("jasminum.translatorurl") : "https://oss.wwang.de/translators_CN"; + const url = baseUrl + "/data/translators.json"; const cacheFile = ztoolkit.getGlobal("Zotero").getTempDirectory(); cacheFile.append("translator.json"); let contents; @@ -150,8 +150,9 @@ async function downloadTranslator(filename: string): Promise { } // var url = `https://gitee.com/l0o0/translators_CN/raw/master/translators/${label}`; // var url = `https://gitcode.net/goonback/translators_CN/-/raw/master/translators/${label}`; - // let url = `https://oss.wwang.de/translators_CN/translators/${label}`; - const url = Zotero.Prefs.get("jasminum.translatorurl") + "/" + filename; + // let url = `https://oss.wwang.de/translators_CN/${label}`; + const baseUrl = Zotero.Prefs.get("jasminum.translatorurl") ? Zotero.Prefs.get("jasminum.translatorurl") : "https://oss.wwang.de/translators_CN"; + const url = baseUrl + "/" + filename; ztoolkit.log(url); try { const contents = await ztoolkit.getGlobal("Zotero").File.getContentsFromURL(url); From 8a06c74f3f5e4e53ba1e5bfbad80775165537c4d Mon Sep 17 00:00:00 2001 From: l0o0 Date: Thu, 7 Sep 2023 17:11:09 +0800 Subject: [PATCH 2/6] Release 1.0.0-5 --- package.json | 2 +- update.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e7de8c1..90b1025 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jasminum", - "version": "1.0.0-4", + "version": "1.0.0-5", "description": "一个简单的 Zotero 中文插件", "config": { "addonName": "Jasminum", diff --git a/update.json b/update.json index 8b2ab82..475050f 100644 --- a/update.json +++ b/update.json @@ -3,7 +3,7 @@ "jasminum@linxzh.com": { "updates": [ { - "version": "1.0.0-4", + "version": "1.0.0-5", "update_link": "https://github.com/l0o0/jasminum/releases/latest/download/jasminum.xpi", "applications": { "zotero": { From 0f189a86c17d90a6b2c17260dccdd2c06bc36fc0 Mon Sep 17 00:00:00 2001 From: l0o0 Date: Sat, 9 Sep 2023 22:01:50 +0800 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20Zotero6=E4=B8=8E7=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=BC=82=E5=B8=B8=E9=80=A0=E6=88=90=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98.=20fixed=20#197?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addon/chrome/content/preferences.xhtml | 31 ++++++++++--------- addon/locale/zh-CN/addon.ftl | 4 ++- addon/locale/zh-CN/preferences.ftl | 1 - src/addon.ts | 4 +-- src/hooks.ts | 40 +++++++++--------------- src/modules/bookmark.ts | 5 +-- src/modules/cnki.ts | 7 +++-- src/modules/jasminum.ts | 9 +++--- src/modules/preferenceScript.ts | 42 +++++++++++++++++++------- src/modules/tools.ts | 5 +-- src/utils/cookiebox.ts | 4 ++- 11 files changed, 85 insertions(+), 67 deletions(-) diff --git a/addon/chrome/content/preferences.xhtml b/addon/chrome/content/preferences.xhtml index 019e127..cede2f2 100644 --- a/addon/chrome/content/preferences.xhtml +++ b/addon/chrome/content/preferences.xhtml @@ -8,19 +8,19 @@ - - + + preference="__prefsPrefix__.autobookmark" native="true" /> + preference="__prefsPrefix__.autolanguage" native="true" />