Skip to content

Commit 55b5fe7

Browse files
committed
feat: add PubScholar service and refactor cookie/CNKI logic
- Add PubScholar as a new metadata search source - Refactor cookiebox to use getCookieBoxFromUrl with customizable hint text - Split CNKI getRefworksText into mainland/overseas branches - Add version info and help message header to scraper tasks - Add attention animation for task message icon in progress window - Clear cookie on progress window unload
1 parent a693d93 commit 55b5fe7

File tree

10 files changed

+298
-323
lines changed

10 files changed

+298
-323
lines changed

addon/chrome/content/progress.xhtml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,48 @@ href="chrome://zotero-platform/content/zotero.css" type="text/css"?>
157157
width: 15px;
158158
margin-left: 8px;
159159
vertical-align: middle;
160+
cursor: pointer;
161+
display: inline-block;
162+
animation: attention-shake 2s ease-in-out infinite;
163+
}
164+
165+
/* 吸引注意力的动画:抖动 + 缩放 + 脉冲 */
166+
@keyframes attention-shake {
167+
0%,
168+
100% {
169+
transform: scale(1) rotate(0deg);
170+
opacity: 1;
171+
}
172+
10% {
173+
transform: scale(1.3) rotate(-10deg);
174+
}
175+
20% {
176+
transform: scale(1.3) rotate(10deg);
177+
}
178+
30% {
179+
transform: scale(1.3) rotate(-10deg);
180+
}
181+
40% {
182+
transform: scale(1.3) rotate(10deg);
183+
}
184+
50% {
185+
transform: scale(1.5) rotate(0deg);
186+
opacity: 0.8;
187+
}
188+
60% {
189+
transform: scale(1.2) rotate(0deg);
190+
}
191+
70% {
192+
transform: scale(1) rotate(0deg);
193+
opacity: 1;
194+
}
195+
}
196+
197+
/* 鼠标悬停时暂停动画并放大 */
198+
.task-msg:hover {
199+
animation-play-state: paused;
200+
transform: scale(1.5);
201+
filter: drop-shadow(0 0 3px rgba(255, 193, 7, 0.8));
160202
}
161203

162204
/* 黑暗模式样式 */
@@ -232,6 +274,10 @@ href="chrome://zotero-platform/content/zotero.css" type="text/css"?>
232274
});
233275
}
234276

277+
window.addEventListener("beforeunload", (e) => {
278+
Zotero.Jasminum.data.myCookieSandbox._CNKIHomeCookieBox = null;
279+
});
280+
235281
// 模拟数据
236282
const tasks = [
237283
{

addon/locale/en-US/addon.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ bookmark-add = Add bookmark
7272
bookmark-delete = Delete bookmark
7373
7474
# Progress window
75+
task-msg-header = If you need help with capture issues, please screenshot the following content and contact the developer: RedBook l0o0
7576
task-already-exists = Task already exists: { $title }

addon/locale/zh-CN/addon.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,5 @@ bookmark-add = 添加书签
7373
bookmark-delete = 删除书签
7474
7575
# Progress window
76+
task-msg-header = 如果抓取异常需要帮助,请截图以下内容并联系开发者:小红书l0o0
7677
task-already-exists = 任务已存在:{ $title }

addon/locale/zh-TW/addon.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,5 @@ bookmark-add = 添加書籤
7373
bookmark-delete = 刪除書籤
7474
7575
# Progress window
76+
task-msg-header = 如果抓取異常需要幫助,請截圖以下內容並聯繫開發者:小紅書l0o0
7677
task-already-exists = 已存在任務:{ $title }

src/modules/services/cnki.ts

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -188,58 +188,62 @@ async function getRefworksText(
188188
Referer: searchResult.url,
189189
};
190190
const isMainlandChina = getPref("isMainlandChina");
191-
const apiurl = isMainlandChina
192-
? "https://kns.cnki.net/dm8/API/GetExport"
193-
: "https://kns.cnki.net/kns8/manage/APIGetExport";
194-
195-
// "1": row's sequence in search result page, defualt 1; "0": index of page in search result pages, defualt 0.
196-
const platform = "NZKPT";
197-
let responseText: string;
198-
let postData = isMainlandChina
199-
? `filename=${searchResult.exportID}&uniplatform=${platform}`
200-
: `filename=${searchResult.dbname}!${searchResult.filename}!1!0`;
201-
postData += "&displaymode=GBTREFER%2Celearning%2CEndNote";
202-
const resp = await Zotero.HTTP.request("POST", apiurl, {
203-
body: postData,
204-
headers: headers,
205-
cookieSandbox: await addon.data.myCookieSandbox.getCNKIHomeCookieBox(),
206-
timeout: 10000,
207-
successCodes: [200, 403],
208-
});
209-
ztoolkit.log(`Endnote reference text from CNKI: ${resp.responseText}`);
210-
responseText = resp.responseText;
211-
if (resp.status === 403) {
212-
ztoolkit.log(
213-
"CNKI access forbidden (403). This is likely due to missing or invalid cookies.",
214-
);
215-
const respJson = JSON.parse(resp.responseText);
216-
217-
ztoolkit.log("Retrying CNKI search after updating cookies...");
218-
headers["Referer"] = respJson.message;
219-
const resp2 = await Zotero.HTTP.request("POST", apiurl, {
220-
headers: headers,
191+
if (getPref("isMainlandChina")) {
192+
// "1": row's sequence in search result page, defualt 1; "0": index of page in search result pages, defualt 0.
193+
const platform = "NZKPT";
194+
const apiUrl = "https://kns.cnki.net/dm8/API/GetExport";
195+
let responseText: string;
196+
let postData = isMainlandChina
197+
? `filename=${searchResult.exportID}&uniplatform=${platform}`
198+
: `filename=${searchResult.dbname}!${searchResult.filename}!1!0`;
199+
postData += "&displaymode=GBTREFER%2Celearning%2CEndNote";
200+
const resp = await Zotero.HTTP.request("POST", apiUrl, {
221201
body: postData,
222-
cookieSandbox: await addon.data.myCookieSandbox.passCaptchaToCookieBox(
223-
respJson.message,
224-
"CNKI:Home",
225-
),
202+
headers: headers,
203+
cookieSandbox: await addon.data.myCookieSandbox.getCNKIHomeCookieBox(),
226204
timeout: 10000,
227205
successCodes: [200, 403],
228206
});
229-
responseText = resp2.responseText;
230-
}
231-
const returnJson = JSON.parse(responseText);
232-
if (returnJson.code != 1) {
233-
return null;
234-
} else {
235-
const endnoteRef = returnJson.data.find(
236-
(i: Record<string, string>) => i.key === "EndNote",
237-
);
238-
if (endnoteRef) {
239-
return endnoteRef.value[0].replace(/<br>/g, "\n");
240-
} else {
207+
ztoolkit.log(`Endnote reference text from CNKI: ${resp.responseText}`);
208+
responseText = resp.responseText;
209+
if (resp.status === 403) {
210+
ztoolkit.log(
211+
"CNKI access forbidden (403). This is likely due to missing or invalid cookies.",
212+
);
213+
const respJson = JSON.parse(resp.responseText);
214+
215+
ztoolkit.log("Retrying CNKI search after updating cookies...");
216+
headers["Referer"] = respJson.message;
217+
const resp2 = await Zotero.HTTP.request("POST", apiUrl, {
218+
headers: headers,
219+
body: postData,
220+
cookieSandbox: await addon.data.myCookieSandbox.passCaptchaToCookieBox(
221+
respJson.message,
222+
"CNKI:Home",
223+
),
224+
timeout: 10000,
225+
successCodes: [200, 403],
226+
});
227+
responseText = resp2.responseText;
228+
}
229+
const returnJson = JSON.parse(responseText);
230+
if (returnJson.code != 1) {
241231
return null;
232+
} else {
233+
const endnoteRef = returnJson.data.find(
234+
(i: Record<string, string>) => i.key === "EndNote",
235+
);
236+
if (endnoteRef) {
237+
return endnoteRef.value[0].replace(/<br>/g, "\n");
238+
} else {
239+
return null;
240+
}
242241
}
242+
} else {
243+
ztoolkit.log("CNKI oversea export reference.");
244+
const apiUrl = "https://chn.oversea.cnki.net/kns/Manage/APIGetExport";
245+
// TODO: implement oversea export
246+
return null;
243247
}
244248
}
245249

0 commit comments

Comments
 (0)