-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.user.js
104 lines (97 loc) · 2.98 KB
/
script.user.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
95
96
97
98
99
100
101
102
103
104
// ==UserScript==
// @name GitHub Feed Blacklist
// @namespace https://github.com/helsonxiao
// @version 0.2.2
// @description GitHub Feed 黑名单插件
// @author helsonxiao
// @match https://github.com/
// @grant none
// ==/UserScript==
(function () {
"use strict";
const targetList = JSON.parse(
localStorage.getItem("feed-blacklist") || '[""]'
);
function removeTargets() {
console.info("[GitHub Feed Blacklist] start to remove targets");
const followingContainers = document.querySelectorAll(
"span.user-following-container"
);
const feedItems = document.querySelectorAll(".js-feed-item-component");
for (let i = 0; i < targetList.length; i++) {
const target = targetList[i];
// remove recommended users
for (const followingContainer of followingContainers) {
const form = followingContainer.querySelector(
`form[action="/users/follow?target=${target}"]`
);
if (form) {
const parent = followingContainer.closest(".col-12.col-xl-6");
parent.remove();
console.info(
"[GitHub Feed Blacklist] target has been removed:",
target,
parent
);
}
}
// remove recommended activities
feedItems.forEach((feedItem) => {
const anchor = feedItem.querySelector(`a[href="/${target}"]`);
if (anchor) {
feedItem.remove();
console.info(
"[GitHub Feed Blacklist] target has been removed:",
target,
feedItem
);
}
});
}
console.info("[GitHub Feed Blacklist] remove targets done");
}
function observeFeedFrame(feedFrame) {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
removeTargets();
mutation.addedNodes.forEach((node) => {
if (node.id === "conduit-feed-frame") {
observer.disconnect();
observeFeedFrame(node);
}
});
});
});
observer.observe(feedFrame, {
childList: true,
});
}
window.onload = function () {
const feedContainer = document
.querySelector("#panel-2")
.querySelector('[data-target="feed-container.content"]');
const initObserver = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.addedNodes.length > 0) {
const feedFrame = feedContainer.querySelector("#conduit-feed-frame");
console.info(
"[GitHub Feed Blacklist] initObserver found feedFrame:",
feedFrame
);
if (feedFrame) {
initObserver.disconnect();
removeTargets();
observeFeedFrame(feedFrame);
}
}
});
});
console.info(
"[GitHub Feed Blacklist] found feedContainer:",
feedContainer.cloneNode(true)
);
initObserver.observe(feedContainer, {
childList: true,
});
};
})();