// ==UserScript==
// @name SCBOY论坛增强黑名单
// @namespace *://www.scboy.cc/
// @version 1.1
// @description 过滤页面中黑名单用户的主题和回复
// @author RustyHare
// @match *://*.scboy.cc/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @license MIT
// @downloadURL none
// ==/UserScript==
var mode = GM_getValue("mode");
var menu = ""
var usr=GM_getValue("blusr");
var kwd=GM_getValue("blkwd");
function forumCleaning() {
var threads = $("a.xs-thread-a");
for (var i = 0; i < threads.length; i++) {
for (var j = 0; j < kwd.length; j++) {
if (threads[i].innerText.indexOf(kwd[j]) != -1) {
if (mode == "remove") {
threads[i].parentElement.parentElement.parentElement.remove();
} else {
threads[i].parentElement.parentElement.parentElement.style.backgroundColor = "yellow";
}
}
}
}
var sps = $("span.username.hidden-sm");
for (var i = 0; i < sps.length; i++) {
if (usr.indexOf(sps[i].innerText) != -1) {
if (mode == "remove") {
sps[i].parentElement.parentElement.parentElement.parentElement.remove();
} else {
sps[i].parentElement.parentElement.parentElement.parentElement.style.backgroundColor = "yellow";
}
}
}
}
function threadCleaning() {
var ats = $("a.text-muted.font-weight-bold");
for (var i = 0; i < ats.length; i++) {
if (usr.indexOf(ats[i].innerText) != -1 || kwd.indexOf(ats[i].innerText) != -1) {
if (ats[i].parentElement.parentElement.parentElement.nodeName == "DD") {
if (mode == "remove") {
ats[i].parentElement.parentElement.parentElement.remove();
} else {
ats[i].parentElement.parentElement.parentElement.style.backgroundColor = "yellow";
}
} else if (ats[i].parentElement.parentElement.parentElement.parentElement.parentElement.nodeName ==
"LI") {
if (mode == "remove") {
ats[i].parentElement.parentElement.parentElement.parentElement.parentElement.remove();
} else {
ats[i].parentElement.parentElement.parentElement.parentElement.parentElement.style
.backgroundColor = "yellow";
}
}
}
}
}
function main() {
if (mode == "remove") {
menu = "切换到高亮模式";
} else {
menu = "切换到屏蔽模式";
}
const oSwitchModeCMD = GM_registerMenuCommand(menu, function(e) {
if (mode == "remove") {
GM_setValue("mode", "highlight")
} else {
GM_setValue("mode", "remove")
}
window.location.reload()
}, "a");
const oMenuCMD = GM_registerMenuCommand('管理屏蔽', function(e) {
unsafeWindow.shusr=function(){
let blusr=GM_getValue("blusr");
if(typeof(blusr)=="undefined"){
blusr=[];
GM_setValue("blusr",blusr);
}
let tbody=document.getElementById("RHBlackListTBody");
tbody.innerHTML=`
|
|
`;
blusr.forEach(function(e){
let tr=document.createElement("TR");
let thn=document.createElement("TH");
thn.innerText=e;
let thb=document.createElement("TH");
thb.innerHTML=``;
tr.appendChild(thn);
tr.appendChild(thb);
tbody.appendChild(tr);
})
document.getElementById("RHshusr").classList.remove("disabled");
document.getElementById("RHshkwd").classList.add("disabled");
}
unsafeWindow.shkwd=function(){
let blkwd=GM_getValue("blkwd");
if(typeof(blkwd)=="undefined"){
blkwd=[];
GM_setValue("blkwd",blkwd);
}
let tbody=document.getElementById("RHBlackListTBody");
tbody.innerHTML=`
|
|
`;
blkwd.forEach(function(e){
let tr=document.createElement("TR");
let thn=document.createElement("TH");
thn.innerText=e;
let thb=document.createElement("TH");
thb.innerHTML=``;
tr.appendChild(thn);
tr.appendChild(thb);
tbody.appendChild(tr);
})
document.getElementById("RHshusr").classList.add("disabled");
document.getElementById("RHshkwd").classList.remove("disabled");
}
unsafeWindow.addusr=function(){
let rhinput=document.getElementById("RHBlackListInput");
let blusr=GM_getValue("blusr");
if(typeof(blusr)=="undefined"){
blusr=[];
GM_setValue("blkwd",blusr);
}
if(blusr.indexOf(rhinput.value)==-1 && rhinput.value.length>0){
blusr.push(rhinput.value.toString())
}
GM_setValue("blusr",blusr)
shusr();
}
unsafeWindow.delusr=function(e){
let blusr=GM_getValue("blusr");
let i=blusr.indexOf(e.target.parentElement.parentElement.children[0].innerText)
if(i>-1){
blusr.splice(i,1);
GM_setValue("blusr",blusr);
}
shusr();
}
unsafeWindow.addkwd=function(){
let rhinput=document.getElementById("RHBlackListInput");
let blkwd=GM_getValue("blkwd");
if(typeof(blkwd)=="undefined"){
blkwd=[];
GM_setValue("blkwd",blkwd);
}
if(blkwd.indexOf(rhinput.value)==-1 && rhinput.value.length>0){
blkwd.push(rhinput.value.toString())
}
GM_setValue("blkwd",blkwd)
shkwd();
}
unsafeWindow.delkwd=function(e){
let blkwd=GM_getValue("blkwd");
let i=blkwd.indexOf(e.target.parentElement.parentElement.children[0].innerText)
if(i>-1){
blkwd.splice(i,1);
GM_setValue("blkwd",blkwd);
}
shkwd();
}
var dModalFrame=document.createElement("DIV");
dModalFrame.className="modal fade"
dModalFrame.style.display="none";
dModalFrame.id="RHBlackListModalFrame";
dModalFrame.innerHTML=`
`
document.body.appendChild(dModalFrame);
shusr();
$("#RHBlackListModalFrame").modal()
}, "c");
window.blackList = GM_getValue("blackList")
if (window.location.href.search("forum") > -1) {
forumCleaning()
} else if (window.location.href.search("thread") > -1) {
threadCleaning()
}
}
if (window.addEventListener != null) {
window.addEventListener("load", main, false);
} else if (window.attachEvent != null) {
window.attachEvent("onload", main);
}