-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpixiv_blacklist.user.js
176 lines (165 loc) · 4.12 KB
/
pixiv_blacklist.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// ==UserScript==
// @name pixiv blacklist
// @version 0.03
// @description hide unwant artist in search
// @author x94fujo6
// @match https://www.pixiv.net/*
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
/* jshint esversion: 9 */
(async function () {
let current = window.location.href,
retry_count = 0,
delay = 1000;
console.log("script start");
window.onload = setTimeout(checkUrl, delay);
setInterval(() => {
let url = window.location.href;
if (url != current) {
console.log(`re-run script @${url}`);
window.onload = setTimeout(checkUrl, delay);
current = url;
}
}, 1000);
function checkUrl() {
let url = window.location.href;
if (url.includes("/tags/")) main("tag");
if (url.includes("/users/")) main("user");
}
async function main(mode = "") {
let
g = {
key: {
blacklist: "blacklist",
},
default: {
blacklist: [],
},
get(key) {
this.is_key(key);
return GM_getValue(key, this.default[key]);
},
set(key, value) {
this.is_key(key);
return GM_setValue(key, value);
},
is_key(key) {
if (!this.default[key]) throw Error("unknown key");
},
},
checkBlacklist = (ele) => {
let user_id = ele.querySelector("a[href*='/users/']");
if (user_id) {
user_id = Number(user_id.href.match(/users\/(\d+)/)[1]);
} else {
return false;
}
if (blacklist.has(user_id)) {
let nodes = [...ele.childNodes[0].childNodes];
nodes.pop();
nodes.forEach(node => {
node.style.opacity = 0;
node.style.pointerEvents = "none";
});
return true;
}
return false;
},
result = false,
blacklist = new Set(g.get(g.key.blacklist));
console.log("script main");
result = document.querySelectorAll(".juyBTC");
console.log("result", result);
if (mode == "user") {
console.log("user");
let b = null,
ids = {
remove: "_blacklist_remove",
add: "_blacklist_add",
},
add = document.getElementById(ids.add),
remove = document.getElementById(ids.remove);
if (add) {
add.remove();
add = null;
}
if (remove) {
remove.remove();
remove = null;
}
b = document.querySelector("button[data-gtm-user-id]");
if (b) {
let user_id = Number(b.getAttribute("data-gtm-user-id"));
if (blacklist.has(user_id)) {
remove = b.cloneNode();
remove.id = ids.remove;
remove.textContent = "blacklist--";
remove.type = "button";
remove.style = `
color: white;
background-color: limegreen;
`;
remove.onclick = () => {
blacklist.delete(user_id);
g.set(g.key.blacklist, [...blacklist]);
console.log(`user[${user_id}] is remove from blacklist`, [...blacklist]);
document.location.reload();
};
b.insertAdjacentElement("afterend", remove);
} else {
add = b.cloneNode();
add.id = ids.add;
add.textContent = "blacklist++";
add.type = "button";
add.style = `
color: white;
background-color: black;
`;
add.onclick = () => {
blacklist.add(user_id);
g.set(g.key.blacklist, [...blacklist]);
console.log(`user[${user_id}] is add to blacklist`, [...blacklist]);
document.location.reload();
};
b.insertAdjacentElement("afterend", add);
}
b.addEventListener("click", () => {
window.location.reload();
});
} else {
console.log("user button not found");
return false;
}
console.log("script end [user]");
return true;
}
if (mode == "tag") {
let count = 0;
console.log("search");
result.forEach(r => {
let all = r.querySelectorAll("li");
all.forEach(ele => {
if (checkBlacklist(ele)) count++;
});
});
console.log(`script hide ${count} artworks`);
console.log("script end [search]");
if (count == 0) {
console.log(`count = 0, retry(${retry_count})`);
if (retry_count < 3) {
retry_count++;
setTimeout(() => {
main("tag");
}, delay);
} else {
retry_count = 0;
console.log(`end retry`);
}
}
return count;
}
console.log("script end");
return false;
}
})();