-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremoveLinksFronOneTab.js
94 lines (88 loc) · 2.72 KB
/
removeLinksFronOneTab.js
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
// 复制到控制台
// 首页类,完全匹配。
const matchUrls = [
'https://duckduckgo.com/',
'https://www.bing.com/',
'https://weread.qq.com/',
'https://www.zhihu.com/follow',
'https://www.zhihu.com/collections/mine',
'https://www.google.com/',
'https://twitter.com/home',
'https://developer.mozilla.org/zh-CN/',
'https://weibo.com/',
'https://stackoverflow.com/',
'https://github.com/',
'https://css-tricks.com/',
'https://codepen.io/your-work',
'https://codepen.io/',
'https://www.v2ex.com/',
'https://www.nowcoder.com/',
'https://www.youtube.com/',
'https://www.zhihu.com/org/niu-ke-wang-53',
'https://www.bilibili.com/',
];
// 文档类、工具类,相关内容全部清除
const containUrls = [
'https://www.processon.com',
'https://keep.google.com/',
'https://fanyi.sogou.com/',
'https://www.amazon.com/',
'https://www.baidu.com/',
'https://item.jd.com/',
'https://www.jd.com/',
'https://post.smzdm.com/',
'https://www.smzdm.com/',
'https://detail.tmall.com/',
'https://account.aliyun.com/',
'https://ecs-workbench.aliyun.com',
'https://bulma.io/',
'https://tailwindcss.com/',
'chrome://bookmarks/',
'https://leetcode-cn.com/',
'https://papaly.com/',
'https://vue3js.cn',
'http://germ.run/',
'https://www.freecodecamp.org/',
'https://fastapi.tiangolo.com/',
'https://www.deepl.com/',
'https://translate.google.com/',
'https://vuejs.org',
'https://www.notion.so/',
'https://docs.google.com/',
'https://www.evernote.com/',
'https://mail.google.com/mail/u/0/',
];
const searchElementMatched = urls => {
const matchedElement = [];
urls.forEach(url => {
const linkElements = document.querySelectorAll(`[href="${url}"]`);
console.log(`完全匹配${url}的链接有${linkElements.length}个`);
matchedElement.push(...linkElements);
});
console.log(matchedElement.length);
return matchedElement;
};
const searchElementContained = urls => {
const containedElement = [];
urls.forEach(url => {
const linkElements = document.querySelectorAll(`[href*="${url}"]`);
console.log(`包含${url}的链接有${linkElements.length}个`);
containedElement.push(...linkElements);
});
console.log(containedElement.length);
return containedElement;
};
const deleteAll = elements => {
elements.forEach(e => {
e.nextElementSibling.dispatchEvent(new Event('mousedown'));
});
console.log('清除完毕');
};
const main = (matchUrls, containUrls) => {
const matchedElement = searchElementMatched(matchUrls);
const containedElement = searchElementContained(containUrls);
const allElements = [...matchedElement, ...containedElement];
console.log(`共计${allElements.length}`);
deleteAll(allElements);
};
main(matchUrls, containUrls);