File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change 140
140
) ; // 获取已阅读链接列表
141
141
142
142
// 筛选出未阅读的链接
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
+ } ) ;
146
165
147
166
// 如果找到了这样的链接
148
167
if ( unreadLinks . length > 0 ) {
You can’t perform that action at this time.
0 commit comments