fix: use regex to fix incorrect CODE matching

This commit is contained in:
mrbunker
2023-04-14 22:50:59 +08:00
parent 110da4c67f
commit f252c91c69
2 changed files with 6 additions and 3 deletions

View File

@@ -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();

View File

@@ -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);