From 0de753767fb6e9000470ecbd45713ca1488578d6 Mon Sep 17 00:00:00 2001
From: pencilheart <495474804@qq.com>
Date: Sat, 7 Dec 2024 21:28:48 +0800
Subject: [PATCH] Big update
---
package.json | 2 +-
src/gscc.js | 108 ++++++++++---------------
src/locale/en-US/gscc-prefs.ftl | 5 +-
src/locale/es-ES/gscc-prefs.ftl | 5 +-
src/locale/fr-FR/gscc-prefs.ftl | 5 +-
src/locale/ja-JP/gscc-prefs.ftl | 5 +-
src/locale/zh-CH/gscc-prefs.ftl | 5 +-
src/locale/zh-CH/gscc.ftl | 6 +-
src/manifest.json | 2 +-
src/prefs.js | 6 +-
src/prefs.xhtml | 137 ++++++++------------------------
11 files changed, 88 insertions(+), 198 deletions(-)
diff --git a/package.json b/package.json
index a41546e..a9a58d6 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "zotero-google-scholar-citation-count",
- "version": "4.1.1",
+ "version": "5.0.0",
"bugs": {
"url": "https://github.com/justinribeiro/zotero-google-scholar-citation-count/issues"
},
diff --git a/src/gscc.js b/src/gscc.js
index 82a6198..6b76514 100644
--- a/src/gscc.js
+++ b/src/gscc.js
@@ -108,15 +108,6 @@ $__gscc.util = {
xhr.send();
});
},
- /**
- * Get a random number
- * @param {number} min
- * @param {number} max
- * @return {number}
- */
- randomInteger: function (min, max) {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- },
/**
* Checks to validate whether the source code has a recaptcha within it
* @param {string} source source code to parse and search for recaptcha
@@ -204,17 +195,12 @@ $__gscc.app = {
* @private
*/
__noData: 'NoCitationData',
- /**
- * API endpoint for Google Scholar
- * @private
- */
- __apiEndpoint: 'https://scholar.google.com/',
/**
* Default String search in Google Scholar,
* will override based on locale
* @private
*/
- __citedByPrefix: 'Cited by',
+ __citedByPrefix: '被引用次数:',
/**
* My own marker for init; not for general use
* @private
@@ -225,13 +211,11 @@ $__gscc.app = {
* @private
*/
__preferenceDefaults: {
- useRandomWait: true,
- randomWaitMinMs: 1000,
- randomWaitMaxMs: 5000,
useFuzzyMatch: false,
useSearchTitleFuzzyMatch: false,
useSearchAuthorsMatch: true,
useDateRangeMatch: false,
+ mirrorurl:'https://scholar.google.com/',
},
/**
* Initialize our world.
@@ -242,11 +226,23 @@ $__gscc.app = {
this.id = id;
this.version = version;
this.rootURI = rootURI;
-
+
// sanity
$__gscc.app.__initialized = true;
-
+
$__gscc.debugger.info(`Init() Complete! ${this.rootURI}`);
+
+ // Add event listener for new items
+ Zotero.Notifier.registerObserver($__gscc.app.notifierCallback, ['item']);
+ },
+
+ notifierCallback: {
+ notify: async function(event, type, ids, extraData) {
+ if (event === 'add' && type === 'item') {
+ const newItems = await Zotero.Items.getAsync(ids);
+ await $__gscc.app.updateItemMenuEntries(newItems);
+ }
+ }
},
main: async function () {
@@ -287,6 +283,7 @@ $__gscc.app = {
await Zotero.ItemTreeManager.registerColumns({
dataKey: 'gsccCount',
label: columnLabel,
+ flex:0.4,
pluginID: 'justin@justinribeiro.com',
dataProvider: (item, dataKey) => {
const data = item.getField('extra');
@@ -300,7 +297,7 @@ $__gscc.app = {
* @param {String} extraString
*/
setFieldFromExtra: function (extraString) {
- let count = 0;
+ let count = '';
if (extraString.startsWith(this.__extraEntryPrefix)) {
try {
const regex = new RegExp(
@@ -308,9 +305,11 @@ $__gscc.app = {
'g',
);
// meh
- const match = extraString.match(regex)[0];
- const split = match.split(':')[1].trim();
- count = parseInt(split);
+ const match = extraString.match(regex);
+ if (match){
+ const split = match[0].split(':')[1].trim();
+ count = parseInt(split);
+ }
} catch {
// dead case for weird behavior
}
@@ -384,10 +383,11 @@ $__gscc.app = {
window.alert(unSupportedEntryTypeString);
return;
},
- updateItemMenuEntries: async function () {
+
+ updateItemMenuEntries: async function (items = null) {
const zoteroPane = $__gscc.app.getActivePane();
const window = Zotero.getMainWindow();
-
+
if (!zoteroPane.canEditLibrary()) {
const permissionAlertString = await window.document.l10n.formatValue(
'gscc-lackPermissions',
@@ -395,7 +395,12 @@ $__gscc.app = {
window.alert(permissionAlertString);
return;
}
- await this.processItems(zoteroPane.getSelectedItems());
+
+ if (!items) {
+ items = zoteroPane.getSelectedItems();
+ }
+
+ await this.processItems(items);
},
updateGroup: async function () {
const window = Zotero.getMainWindow();
@@ -416,29 +421,6 @@ $__gscc.app = {
* @param {ZoteroGenericItem[]} items
*/
processItems: async function (items) {
- const useQueue = Zotero.Prefs.get(
- 'extensions.zotero.gscc.useRandomWait',
- $__gscc.app.__preferenceDefaults.useRandomWait,
- );
-
- let queueMinWaitMs;
- let queueMaxWaitMs;
-
- $__gscc.debugger.info(`Use Queue: ${useQueue}`);
-
- if (useQueue) {
- queueMinWaitMs = Zotero.Prefs.get(
- 'extensions.zotero.gscc.randomWaitMinMs',
- $__gscc.app.__preferenceDefaults.randomWaitMinMs,
- );
- queueMaxWaitMs = Zotero.Prefs.get(
- 'extensions.zotero.gscc.randomWaitMaxMs',
- $__gscc.app.__preferenceDefaults.randomWaitMaxMs,
- );
-
- $__gscc.debugger.info(`Min: ${queueMinWaitMs} Max: ${queueMaxWaitMs}`);
- }
-
/**
* @param {number} index
* @param {ZoteroGenericItem} item
@@ -451,19 +433,8 @@ $__gscc.app = {
)}': empty title or missing creator information'`,
);
} else {
- // check the prefs in case user override, don't use it on the first item
- // either way
- if (useQueue && index > 0) {
- const queueTime = $__gscc.util.randomInteger(
- queueMinWaitMs,
- queueMaxWaitMs,
- );
-
- $__gscc.debugger.info(`queued for ${queueTime} ms later.`);
- await $__gscc.util.sleep(queueTime);
- }
-
const response = await this.retrieveCitationData(item);
+ $__gscc.debugger.info(`ResponseText: ${response.responseText}`);
await this.processCitationResponse(
response.status,
response.responseText,
@@ -623,15 +594,16 @@ $__gscc.app = {
);
let titleSearchString;
+ let rawTitle = item.getField('title').replace(/<[^>]+>/g, '');
if (useSearchTitleFuzzyMatch) {
$__gscc.debugger.info(
`Search Param: Using Fuzzy Title Match per Preferences`,
);
- titleSearchString = `${item.getField('title')}`;
+ titleSearchString = `${rawTitle}`;
} else {
// this is a dead match; kinda risky for hand-entered data but match is
// good on Zotero grabs
- titleSearchString = `"${item.getField('title')}"`;
+ titleSearchString = `"${rawTitle}"`;
}
let paramAuthors = '';
@@ -661,7 +633,13 @@ $__gscc.app = {
}
}
- const targetUrl = `${this.__apiEndpoint}scholar?hl=en&q=${titleSearchString}&as_epq=&as_occt=title&num=1${paramAuthors}${paramYearRange}`;
+ const scholarurl = Zotero.Prefs.get(
+ 'extensions.zotero.gscc.mirrorurl',
+ $__gscc.app.__preferenceDefaults.mirrorurl,
+ );
+ const targetUrl = `${scholarurl}scholar?hl=zh&q=${titleSearchString}&as_epq=&as_occt=title&num=1${paramAuthors}${paramYearRange}`;
+
+
$__gscc.debugger.info(`Search Endpoint Ready: ${targetUrl}`);
return encodeURI(targetUrl);
diff --git a/src/locale/en-US/gscc-prefs.ftl b/src/locale/en-US/gscc-prefs.ftl
index f69f89d..ec970d8 100644
--- a/src/locale/en-US/gscc-prefs.ftl
+++ b/src/locale/en-US/gscc-prefs.ftl
@@ -1,7 +1,4 @@
-preferences-gscc-enable-random-wait-timing = Set Google Scholar Request Random Wait Intervals
-preferences-gscc-random-wait-timing-explain = To attempt to not trigger the IP shadow ban that Google Scholar implements, GSCC uses a random interval per HTTP request. You can change the window by revising the milliseconds below.
-preferences-gscc-randomWaitMinMs = Minimum Request Wait (milliseconds)
-preferences-gscc-randomWaitMaxMs = Maximum Request Wait (milliseconds)
+preferences-gscc-mirror-title=Mirror URL
preferences-gscc-search-params = Custom Search Parameters
preferences-gscc-search-params-explain = Depending on the types of papers you import, sometimes finding matches can be hard. The latest v4.1 of GSCC allows changing the search behavior through flags to help when you need it. In most cases, you shouldn't need the flags below, but if you're having issues, different combinations in different global regions can sometimes help.
preferences-gscc-useSearchTitleFuzzyMatch= Use Fuzzy Title Match
diff --git a/src/locale/es-ES/gscc-prefs.ftl b/src/locale/es-ES/gscc-prefs.ftl
index 98568be..7664557 100644
--- a/src/locale/es-ES/gscc-prefs.ftl
+++ b/src/locale/es-ES/gscc-prefs.ftl
@@ -1,7 +1,4 @@
-preferences-gscc-enable-random-wait-timing = Establecer intervalos de espera aleatorios para las solicitudes de Google Scholar
-preferences-gscc-random-wait-timing-explain = Para intentar no activar la prohibición de IP que implementa Google Scholar, GSCC utiliza un intervalo aleatorio por cada solicitud HTTP. Puede cambiar la ventana modificando los milisegundos a continuación.
-preferences-gscc-randomWaitMinMs = Espera mínima de solicitud (milisegundos)
-preferences-gscc-randomWaitMaxMs = Espera máxima de solicitud (milisegundos)
+preferences-gscc-mirror-title=Espejo URL
preferences-gscc-search-params = Parámetros de búsqueda personalizados
preferences-gscc-search-params-explain = Dependiendo de los tipos de documentos que importe, a veces puede ser difícil encontrar coincidencias. La última versión v4.1 de GSCC permite cambiar el comportamiento de búsqueda mediante opciones para ayudarle cuando lo necesite. En la mayoría de los casos, no necesitará las opciones a continuación, pero si tiene problemas, diferentes combinaciones en distintas regiones globales pueden ayudar.
preferences-gscc-useSearchTitleFuzzyMatch = Usar coincidencia de título difusa
diff --git a/src/locale/fr-FR/gscc-prefs.ftl b/src/locale/fr-FR/gscc-prefs.ftl
index 97a608a..c35ccb7 100644
--- a/src/locale/fr-FR/gscc-prefs.ftl
+++ b/src/locale/fr-FR/gscc-prefs.ftl
@@ -1,7 +1,4 @@
-preferences-gscc-enable-random-wait-timing = Définir des intervalles d'attente aléatoires pour les requêtes Google Scholar
-preferences-gscc-random-wait-timing-explain = Pour tenter de ne pas déclencher l'interdiction IP imposée par Google Scholar, GSCC utilise un intervalle aléatoire pour chaque requête HTTP. Vous pouvez modifier la fenêtre en révisant les millisecondes ci-dessous.
-preferences-gscc-randomWaitMinMs = Temps d'attente minimum (millisecondes)
-preferences-gscc-randomWaitMaxMs = Temps d'attente maximum (millisecondes)
+preferences-gscc-mirror-title=Miroir URL
preferences-gscc-search-params = Paramètres de recherche personnalisés
preferences-gscc-search-params-explain = En fonction des types de documents que vous importez, il peut parfois être difficile de trouver des correspondances. La dernière version v4.1 de GSCC permet de modifier le comportement de recherche via des options pour vous aider en cas de besoin. Dans la plupart des cas, vous n'aurez pas besoin de ces options, mais si vous rencontrez des problèmes, différentes combinaisons dans différentes régions peuvent parfois aider.
preferences-gscc-useSearchTitleFuzzyMatch = Utiliser la correspondance floue des titres
diff --git a/src/locale/ja-JP/gscc-prefs.ftl b/src/locale/ja-JP/gscc-prefs.ftl
index d7145d0..f07c678 100644
--- a/src/locale/ja-JP/gscc-prefs.ftl
+++ b/src/locale/ja-JP/gscc-prefs.ftl
@@ -1,7 +1,4 @@
-preferences-gscc-enable-random-wait-timing = Google Scholar リクエストのランダム待機間隔を設定
-preferences-gscc-random-wait-timing-explain = Google Scholar が実施する IP ブロックを回避するため、GSCC は各 HTTP リクエストにランダムな間隔を使用します。以下のミリ秒単位の設定を変更してウィンドウを調整できます。
-preferences-gscc-randomWaitMinMs = 最小リクエスト待機時間(ミリ秒)
-preferences-gscc-randomWaitMaxMs = 最大リクエスト待機時間(ミリ秒)
+preferences-gscc-mirror-title=ミラーURL
preferences-gscc-search-params = カスタム検索パラメータ
preferences-gscc-search-params-explain = インポートする論文の種類によっては、マッチを見つけるのが難しい場合があります。最新の GSCC v4.1 では、必要に応じてフラグを使用して検索動作を変更することができます。ほとんどの場合、以下のフラグは必要ありませんが、問題が発生した場合、異なる地域で異なる組み合わせが役立つことがあります。
preferences-gscc-useSearchTitleFuzzyMatch = タイトルのファジーマッチを使用
diff --git a/src/locale/zh-CH/gscc-prefs.ftl b/src/locale/zh-CH/gscc-prefs.ftl
index 8c8ef7a..0f5a8a9 100644
--- a/src/locale/zh-CH/gscc-prefs.ftl
+++ b/src/locale/zh-CH/gscc-prefs.ftl
@@ -1,7 +1,4 @@
-preferences-gscc-enable-random-wait-timing = 设置 Google 学术请求随机等待时间间隔
-preferences-gscc-random-wait-timing-explain = 为了尝试避免触发 Google 学术实施的 IP 阴影禁令,GSCC 对每个 HTTP 请求使用随机间隔。您可以通过修改下面的毫秒数来更改窗口。
-preferences-gscc-randomWaitMinMs = 最小请求等待时间(毫秒)
-preferences-gscc-randomWaitMaxMs = 最大请求等待时间(毫秒)
+preferences-gscc-mirror-title=镜像网址
preferences-gscc-search-params = 自定义搜索参数
preferences-gscc-search-params-explain = 根据您导入的论文类型,有时找到匹配项会很困难。最新的 GSCC v4.1 允许通过标志改变搜索行为,以便在需要时提供帮助。在大多数情况下,您不需要使用以下标志,但如果遇到问题,不同全球区域的不同组合有时会有所帮助。
preferences-gscc-useSearchTitleFuzzyMatch = 使用模糊标题匹配
diff --git a/src/locale/zh-CH/gscc.ftl b/src/locale/zh-CH/gscc.ftl
index 2c230ff..4315848 100644
--- a/src/locale/zh-CH/gscc.ftl
+++ b/src/locale/zh-CH/gscc.ftl
@@ -1,8 +1,8 @@
gscc-menuitem =
- .label = 更新 Google 学术引用次数
-gscc-column-name = 引用次数
+ .label = 更新 Google 学术被引次数
+gscc-column-name = 被引次数
gscc-update-all =
- .label = 更新所有 Google 学术引用次数。
+ .label = 更新所有 Google 学术被引次数。
gscc-recapatcha-alert = 请在现在打开的页面上输入验证码,然后重试更新引用,或者如果没有出现验证码,请等待一段时间以解除 Google 的限制。
gscc-citedByPrefix = 引用自
gscc-lackPermissions = 您没有权限编辑此库。
diff --git a/src/manifest.json b/src/manifest.json
index 499bbae..0f46cda 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Google Scholar Citation Count",
- "version": "4.1.1",
+ "version": "5.0.0",
"description": "Zotero plugin for fetching numbers of citations from Google Scholar.",
"homepage_url": "https://github.com/justinribeiro/zotero-google-scholar-citation-count",
"author": "Justin Ribeiro",
diff --git a/src/prefs.js b/src/prefs.js
index 4391f44..fcc86fa 100644
--- a/src/prefs.js
+++ b/src/prefs.js
@@ -1,6 +1,4 @@
-pref('extensions.zotero.gscc.useRandomWait', true);
-pref('extensions.zotero.gscc.randomWaitMinMs', 1000);
-pref('extensions.zotero.gscc.randomWaitMaxMs', 5000);
+pref('extensions.zotero.gscc.mirrorurl', 'https://scholar.google.com/');
pref('extensions.zotero.gscc.useSearchTitleFuzzyMatch', false);
-pref('extensions.zotero.gscc.useSearchAuthorsMatch', true);
pref('extensions.zotero.gscc.useDateRangeMatch', false);
+pref('extensions.zotero.gscc.useSearchAuthorsMatch', true);
\ No newline at end of file
diff --git a/src/prefs.xhtml b/src/prefs.xhtml
index 6f5f839..c55ec89 100644
--- a/src/prefs.xhtml
+++ b/src/prefs.xhtml
@@ -1,107 +1,36 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+