fix: use regex to fix incorrect CODE matching
This commit is contained in:
@@ -12,7 +12,7 @@ function main() {
|
||||
/** 当前匹配的图书馆站点对象 */
|
||||
const libItem = libSites.find((item) => item.href.test(window.location.href));
|
||||
if (!libItem) {
|
||||
console.error("脚本挂载错误");
|
||||
console.error("||脚本挂载错误");
|
||||
return;
|
||||
}
|
||||
const CODE = getCode(libItem);
|
||||
@@ -22,7 +22,7 @@ function main() {
|
||||
|
||||
const panel = document.querySelector<HTMLElement>(libItem.querys.panelQueryStr);
|
||||
if (!panel) {
|
||||
console.error("脚本挂载错误");
|
||||
console.error("||脚本挂载错误");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ function main() {
|
||||
panel.append(app);
|
||||
|
||||
render(<App libItem={libItem} CODE={CODE} />, app);
|
||||
console.log("||脚本挂载成功", CODE);
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
@@ -51,7 +51,9 @@ function serachPageParser(
|
||||
/** 空格版本的 code */
|
||||
// const formatCode = spaceCode ? CODE.replace("-", " ") : CODE;
|
||||
|
||||
const isSuccess = linkNode && titleNode && titleNodeText.includes(CODE);
|
||||
const codeRegex = /[a-zA-Z]{3,5}-\d{3,5}/;
|
||||
const matchCode = titleNodeText.match(codeRegex);
|
||||
const isSuccess = linkNode && titleNode && matchCode && matchCode[0] === CODE;
|
||||
|
||||
if (isSuccess) {
|
||||
const targetLinkText = linkNode.href.replace(linkNode.hostname, siteHostName);
|
||||
|
||||
Reference in New Issue
Block a user