Skip to content

Commit 5e1e9ce

Browse files
committed
feat: 更好的寻找未读过的文章,但可能有问题
1 parent d1817b8 commit 5e1e9ce

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

index_passage_list.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,28 @@
140140
); // 获取已阅读链接列表
141141

142142
// 筛选出未阅读的链接
143-
const unreadLinks = Array.from(links).filter(
144-
(link) => !alreadyReadLinks.includes(link.href)
145-
);
143+
const unreadLinks = Array.from(links).filter((link) => {
144+
// 检查链接是否已经被读过
145+
const isAlreadyRead = alreadyReadLinks.includes(link.href);
146+
if (isAlreadyRead) {
147+
return false; // 如果链接已被读过,直接排除
148+
}
149+
150+
// 向上遍历DOM树,查找包含'visited'类的父级元素,最多查找三次
151+
let parent = link.parentElement;
152+
let times = 0; // 查找次数计数器
153+
while (parent && times < 3) {
154+
if (parent.classList.contains("visited")) {
155+
// 如果找到包含'visited'类的父级元素,中断循环
156+
return false; // 父级元素包含'visited'类,排除这个链接
157+
}
158+
parent = parent.parentElement; // 继续向上查找
159+
times++; // 增加查找次数
160+
}
161+
162+
// 如果链接未被读过,且在向上查找三次内,其父级元素中没有包含'visited'类,则保留这个链接
163+
return true;
164+
});
146165

147166
// 如果找到了这样的链接
148167
if (unreadLinks.length > 0) {

0 commit comments

Comments
 (0)