-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNGAUserBlocker.user.js
More file actions
75 lines (65 loc) · 2.45 KB
/
NGAUserBlocker.user.js
File metadata and controls
75 lines (65 loc) · 2.45 KB
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
// ==UserScript==
// @name NGA User Blocker
// @name:zh NGA表情管理器
// @namespace https://github.com/jc3213/userscript
// @version 0.3
// @description Block user posts and quotes on NGA
// @description:zh 屏蔽用户的发言跟与之相关的引用
// @author jc3213
// @match *://bbs.nga.cn/*
// @match *://ngabbs.com/*
// @match *://nga.178.com/*
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
let storage = GM_getValue('block', []);
let blocker = new Map(storage);
function blockPosts(posts) {
[...posts].forEach((post) => {
if (post.localName !== 'table') {
return;
}
let title = post.children[0].children[0].children[0].children[0].children[0];
let body = title.children;
let user = body[1].textContent;
let id = body[body.length - 1].textContent;
if (blocker.has(id)) {
post.style.display = 'none';
}
let quote = post.children[0].children[0].children[1].children[4].children[2].children[0];
if (quote.localName === 'div' && quote.className === 'quote') {
let quser = quote.children[2];
let qname = quser.textContent;
let qid = quser.href.slice(quser.href.lastIndexOf('=') + 1);
if (blocker.has(qid)) {
quote.textContent = `${qname}已被屏蔽……`;
}
}
let button = document.createElement('button');
button.id = id;
button.user = user;
button.title = `屏蔽用户[${user}]`;
button.textContent = '屏蔽此人';
button.style.cssText = 'margin-left: 5px;';
button.addEventListener('click', blockThisUser);
button.post = post;
title.appendChild(button);
});
}
function blockThisUser(event) {
let {id, title, user, post} = event.target;
if (confirm(`确定要${title}吗?`)) {
blocker.set(id, user);
post.style.display = 'none';
GM_setValue('block', [...blocker]);
}
}
new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
let post = mutation.addedNodes[0];
if (post && post.id === 'm_posts') {
setTimeout(() => blockPosts(post.children[0].children), 100);
}
});
}).observe(document.getElementById('mc'), { childList: true, subtree: true });
blockPosts(document.getElementById('m_posts_c').children);