From e66f2dc4ca3c0cb8521887a99803a9ef68b894ec Mon Sep 17 00:00:00 2001 From: jiaojiaodubai <63148861+jiaojiaodubai@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:08:51 +0800 Subject: [PATCH 1/2] MV3: Support CSL import from all .csl gitee pages --- src/browserExt/contentTypeHandler.js | 6 +++--- src/browserExt/styleInterceptRules.json | 14 ++++++++++++++ src/common/zotero.js | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/browserExt/contentTypeHandler.js b/src/browserExt/contentTypeHandler.js index 1d9bafd9c..ce4fdd2fa 100644 --- a/src/browserExt/contentTypeHandler.js +++ b/src/browserExt/contentTypeHandler.js @@ -48,6 +48,7 @@ Zotero.ContentTypeHandler = { mv3CSLWhitelistRegexp: { "https://www.zotero.org/styles/\\1": /https?:\/\/(?:www\.)zotero\.org\/styles\/?#importConfirm=(.*)$/, "https://raw.githubusercontent.com/\\1/\\2": /https?:\/\/github\.com\/([^/]*\/[^/]*)\/[^/]*\/([^.]*.csl)#importConfirm$/, + "https://gitee.com/\\1/raw/\\2": /https?:\/\/gitee\.com\/([^/]+\/[^/]+)\/blob\/(.+\.csl)$/ }, ignoreURL: new Set(), @@ -137,15 +138,14 @@ Zotero.ContentTypeHandler = { }, _isImportableStyle: function (url, contentType) { - const URI = new URL(url); // Offer to install CSL by Content-Type if (Zotero.ContentTypeHandler.cslContentTypes.has(contentType)) { return true; } // Offer to install CSL if URL path ends with .csl and host is allowed - else if (URI.pathname.match(/\.csl$/)) { + else if (/\.csl$/i.test(url)) { let hosts = Zotero.Prefs.get('allowedCSLExtensionHosts'); - if (Array.isArray(hosts) && hosts.includes(URI.hostname)) { + if (Array.isArray(hosts) && hosts.some(host => new RegExp(host).test(url))) { return true; } } diff --git a/src/browserExt/styleInterceptRules.json b/src/browserExt/styleInterceptRules.json index d87f62df4..4c321e632 100644 --- a/src/browserExt/styleInterceptRules.json +++ b/src/browserExt/styleInterceptRules.json @@ -26,5 +26,19 @@ "regexFilter": "^https://raw\\.githubusercontent\\.com/([^/]*/[^/]*)/([^/]*/[^#?]+.csl)$", "resourceTypes": ["main_frame"] } + }, + { + "id": 3, + "priority": 1, + "action": { + "type": "redirect", + "redirect": { + "regexSubstitution": "https://gitee.com/\\1/blob/\\2" + } + }, + "condition": { + "regexFilter": "^https://gitee\\.com/([^/]+/[^/]+)/raw/(.+\\.csl)$", + "resourceTypes": ["main_frame"] + } } ] \ No newline at end of file diff --git a/src/common/zotero.js b/src/common/zotero.js index c749198ab..99d0dc97a 100644 --- a/src/common/zotero.js +++ b/src/common/zotero.js @@ -374,7 +374,7 @@ Zotero.Prefs = new function() { "connector.url": 'http://127.0.0.1:23119/', "capitalizeTitles": false, "interceptKnownFileTypes": true, - "allowedCSLExtensionHosts": ["raw.githubusercontent.com"], + "allowedCSLExtensionHosts": ["^https://raw\\.githubusercontent\\.com/", "^https://gitee\\.com/.+/raw/"], "allowedInterceptHosts": [], "firstUse": true, "firstSaveToServer": true, From 765483d09fa72efc42351b6aa51751a1230c67b9 Mon Sep 17 00:00:00 2001 From: jiaojiaodubai <63148861+jiaojiaodubai@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:43:05 +0800 Subject: [PATCH 2/2] add `#importConfirm` --- src/browserExt/contentTypeHandler.js | 2 +- src/browserExt/styleInterceptRules.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/browserExt/contentTypeHandler.js b/src/browserExt/contentTypeHandler.js index ce4fdd2fa..e3372ccd1 100644 --- a/src/browserExt/contentTypeHandler.js +++ b/src/browserExt/contentTypeHandler.js @@ -48,7 +48,7 @@ Zotero.ContentTypeHandler = { mv3CSLWhitelistRegexp: { "https://www.zotero.org/styles/\\1": /https?:\/\/(?:www\.)zotero\.org\/styles\/?#importConfirm=(.*)$/, "https://raw.githubusercontent.com/\\1/\\2": /https?:\/\/github\.com\/([^/]*\/[^/]*)\/[^/]*\/([^.]*.csl)#importConfirm$/, - "https://gitee.com/\\1/raw/\\2": /https?:\/\/gitee\.com\/([^/]+\/[^/]+)\/blob\/(.+\.csl)$/ + "https://gitee.com/\\1/raw/\\2": /https?:\/\/gitee\.com\/([^/]+\/[^/]+)\/blob\/(.+\.csl)#importConfirm$/ }, ignoreURL: new Set(), diff --git a/src/browserExt/styleInterceptRules.json b/src/browserExt/styleInterceptRules.json index 4c321e632..778b4246d 100644 --- a/src/browserExt/styleInterceptRules.json +++ b/src/browserExt/styleInterceptRules.json @@ -33,7 +33,7 @@ "action": { "type": "redirect", "redirect": { - "regexSubstitution": "https://gitee.com/\\1/blob/\\2" + "regexSubstitution": "https://gitee.com/\\1/blob/\\2#importConfirm" } }, "condition": {