-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
109 lines (96 loc) · 3.44 KB
/
Copy pathcontent.js
File metadata and controls
109 lines (96 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(function () {
'use strict';
// 域名白名单检查
const hostname = window.location.hostname;
const allowedKeywords = ['18comic', 'jmcomic', 'comic18'];
if (!allowedKeywords.some(kw => hostname.includes(kw))) return;
const BLOCK_KEY = 'blockedTags';
const HIGHLIGHT_KEY = 'highlightTags';
const DEFAULT_BLOCK = ['AI'];
const DEFAULT_HIGHLIGHT = [];
/**
* 处理所有标签:屏蔽优先 → 高亮1(红框) → 高亮2(蓝框)
*/
function processTags(blockTags, highlightTags) {
const tagLinks = document.querySelectorAll('a.tag');
tagLinks.forEach(link => {
const text = link.textContent;
const listCol = link.closest('.list-col');
if (!listCol) return;
// 1. 屏蔽判断:匹配任意屏蔽关键词则隐藏
if (blockTags && blockTags.length > 0) {
if (blockTags.some(kw => text.includes(kw))) {
listCol.style.display = 'none';
return; // 已隐藏,不再处理高亮
}
}
// 2. 高亮判断
if (highlightTags && highlightTags.length > 0) {
// 高亮1:红色边框 → 加在 .list-col 上
if (highlightTags[0] && text.includes(highlightTags[0])) {
listCol.style.border = '4px solid red';
}
// 高亮2:蓝色边框 → 加在内部 .thumb-overlay 或 .thumb-overlay-albums 上
if (highlightTags[1] && text.includes(highlightTags[1])) {
const overlay = listCol.querySelector('.thumb-overlay, .thumb-overlay-albums');
if (overlay) {
overlay.style.border = '4px solid blue';
}
}
}
});
}
/**
* 清除所有之前应用的高亮样式(用于实时更新时先重置)
*/
function clearHighlights() {
document.querySelectorAll('.list-col').forEach(el => {
el.style.border = '';
});
document.querySelectorAll('.thumb-overlay, .thumb-overlay-albums').forEach(el => {
el.style.border = '';
});
}
/**
* 完整重新处理:清除 → 过滤
*/
function refresh(blockTags, highlightTags) {
// 先恢复被隐藏的元素
document.querySelectorAll('.list-col[style*="display: none"], .list-col[style*="display:none"]').forEach(el => {
el.style.display = '';
});
clearHighlights();
processTags(blockTags, highlightTags);
}
// 从 storage 读取并执行
chrome.storage.sync.get(
{ [BLOCK_KEY]: DEFAULT_BLOCK, [HIGHLIGHT_KEY]: DEFAULT_HIGHLIGHT },
(result) => {
const blockTags = result[BLOCK_KEY] || [];
const highlightTags = result[HIGHLIGHT_KEY] || [];
processTags(blockTags, highlightTags);
// 监听动态加载内容
const observer = new MutationObserver(mutations => {
for (const mutation of mutations) {
if (mutation.addedNodes.length > 0) {
processTags(blockTags, highlightTags);
return;
}
}
});
observer.observe(document.body, { childList: true, subtree: true });
// 监听 storage 变化,实时刷新
chrome.storage.onChanged.addListener((changes) => {
if (changes[BLOCK_KEY] || changes[HIGHLIGHT_KEY]) {
const newBlock = changes[BLOCK_KEY]
? (changes[BLOCK_KEY].newValue || [])
: blockTags;
const newHighlight = changes[HIGHLIGHT_KEY]
? (changes[HIGHLIGHT_KEY].newValue || [])
: highlightTags;
refresh(newBlock, newHighlight);
}
});
}
);
})();