Skip to content

Commit c3a7ab8

Browse files
committed
支持自定义黑名单
1 parent a178745 commit c3a7ab8

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11

22
.DS_Store
33
dev.html
4+
devblacklist.json

tianli_gpt.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ function tianliGPT(usePjax) {
313313

314314
function checkURLAndRun() {
315315
if (typeof tianliGPT_postURL === "undefined") {
316-
runTianliGPT(); // 如果没有设置自定义 URL,则直接执行 runTianliGPT() 函数
316+
tianliGPTCustomBlackList(); // 如果没有设置自定义 URL,则直接执行 runTianliGPT() 函数
317317
return;
318318
}
319319

@@ -330,7 +330,7 @@ function tianliGPT(usePjax) {
330330
const currentURL = window.location.href;
331331

332332
if (urlPattern.test(currentURL)) {
333-
runTianliGPT(); // 如果当前 URL 符合用户设置的 URL,则执行 runTianliGPT() 函数
333+
tianliGPTCustomBlackList(); // 如果当前 URL 符合用户设置的 URL,则执行 runTianliGPT() 函数
334334
} else {
335335
console.log("TianliGPT:因为不符合自定义的链接规则,我决定不执行摘要功能。");
336336
}
@@ -339,6 +339,32 @@ function tianliGPT(usePjax) {
339339
}
340340
}
341341

342+
function tianliGPTCustomBlackList() {
343+
if (typeof tianliGPT_blacklist === "undefined") {
344+
runTianliGPT(); // 如果没有设置自定义 URL,则直接执行 runTianliGPT() 函数
345+
return;
346+
}else {
347+
// 使用 fetch 请求 JSON 文件
348+
fetch(tianliGPT_blacklist)
349+
.then(response => response.json())
350+
.then(data => {
351+
const urlList = data.urls; // 假设 JSON 文件中有一个 urls 键
352+
let currentPageUrl = window.location.href;
353+
let isBlacklisted = urlList.some(pattern => {
354+
// 将通配符转换为正则表达式
355+
let regex = new RegExp("^" + pattern.replace(/\*/g, ".*") + "$");
356+
return regex.test(currentPageUrl);
357+
});
358+
359+
// 如果当前页面 URL 不在黑名单中,则执行 tianliGPT
360+
if (!isBlacklisted) {
361+
runTianliGPT();
362+
}
363+
})
364+
.catch(error => console.error('Error fetching blacklist:', error));
365+
}
366+
}
367+
342368
if (usePjax) {
343369
checkURLAndRun();
344370
} else {

tianli_gpt.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)