S1 User Blocker

Block certain user's content

当前为 2021-01-12 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         S1 User Blocker
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Block certain user's content
// @author       冰箱研会长
// @match        https://bbs.saraba1st.com/2b/*
// @grant GM_getValue
// @grant GM_setValue
// @require http://code.jquery.com/jquery-3.5.1.min.js
// @require https://greasyfork.org/scripts/420061-super-gm-setvalue-and-gm-getvalue-greasyfork-mirror-js/code/Super_GM_setValue_and_GM_getValue_greasyfork_mirrorjs.js?version=890160
// ==/UserScript==

//var User_Array = new Array(`三合一出现`,`Python3`,`westgun`);
//var Section_Array = new Array(``,``,``);
var User_Array = GM_SuperValue.get(`User Blocked`,new Array());
var Section_Array = GM_SuperValue.get(`Section 4 Each`,new Array());


function getElementByXpath(path) {
    return document.evaluate(path, document, null,
                             XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}

function Blockbutton_Appender(HtmlDiv,Block_Target,Block_Section,Counter){
    HtmlDiv.innerHTML = HtmlDiv.innerHTML.concat(`
        <div><button type="button" id="secblock-${Counter}">板块屏蔽</button></div>
        <div><button type="button" id="allblock-${Counter}">全局屏蔽</button></div>`);

    $(`#secblock-${Counter}`).click({bt:Block_Target,bs:Block_Section},function(event){
        console.log(event.data.bt+":"+event.data.bs);
        if(User_Array.includes(event.data.bt)){
            Section_Array[User_Array.indexOf(event.data.bt)] = Section_Array[User_Array.indexOf(event.data.bt)].concat(`${event.data.bs}`);
        }else{
            User_Array.push(event.data.bt);
            Section_Array[User_Array.indexOf(event.data.bt)] = event.data.bs;
        }
        GM_SuperValue.set(`User Blocked`,User_Array);
        GM_SuperValue.set(`Section 4 Each`,Section_Array);
        console.log(User_Array);
        console.log(Section_Array);
    });

    $(`#allblock-${Counter}`).click({bt:Block_Target},function(event){
        console.log(event.data.bt+":")
        if(User_Array.includes(event.data.bt)){
            Section_Array[User_Array.indexOf(event.data.bt)] = ``;
        }else{
            User_Array.push(event.data.bt);
            Section_Array[User_Array.indexOf(event.data.bt)] = ``;
        }
        GM_SuperValue.set(`User Blocked`,User_Array);
        GM_SuperValue.set(`Section 4 Each`,Section_Array);
        console.log(User_Array);
        console.log(Section_Array);
    });
}


function S1_Reply_Blocker(){
    var PostLists = getElementByXpath(`//div[@id='postlist']`);
    if(PostLists){
        var PostSection = getElementByXpath(`/html/body/div[8]/div[2]/div/a[4]`).innerText;
        var PostCounter = 1;

        while(getElementByXpath(`//div[@id='postlist']/div[${PostCounter}]`)){
            var PostAuthor = getElementByXpath(`//div[@id='postlist']/div[${PostCounter}]/table/tbody/tr[1]/td[1]/div/div[1]/div/a`);
            var PostAruthorColumn = getElementByXpath(`//div[@id='postlist']/div[${PostCounter}]/table[1]/tbody[1]/tr[1]/td[1]/div[1]`);
            if(PostAruthorColumn){
                Blockbutton_Appender(PostAruthorColumn,PostAuthor.innerText,PostSection,PostCounter);
            }
            if(PostAuthor){
                if( User_Array.includes(PostAuthor.innerText) ){
                    if(Section_Array[User_Array.indexOf(PostAuthor.innerText)] == ""){
                        getElementByXpath(`//div[@id='postlist']/div[${PostCounter}]`).style.display = `none`;
                    }else if(Section_Array[User_Array.indexOf(PostAuthor.innerText)].includes(PostSection)){
                        getElementByXpath(`//div[@id='postlist']/div[${PostCounter}]`).style.display = `none`;
                    }
                }
            }
            PostCounter = PostCounter + 1;
        }
    }
}

function S1_Sure_Blocker(){
    var SureList = getElementByXpath(`//*[@id="threadlisttableid"]`);
    if(SureList){
        var SureCounter = 1;
        while(getElementByXpath(`//*[@id="threadlisttableid"]/tbody[${SureCounter}]`)){
            var SureAuthor = getElementByXpath(`//*[@id="threadlisttableid"]/tbody[${SureCounter}]/tr/td[2]/cite/a`);
            if(SureAuthor){
                if(User_Array.includes(SureAuthor.innerText)){
                    var SureSection = getElementByXpath(`/html/body/div[8]/div[2]/div/a[4]`).innerText;
                    if(Section_Array[User_Array.indexOf(SureAuthor.innerText)] == ""){
                        getElementByXpath(`//*[@id="threadlisttableid"]/tbody[${SureCounter}]`).style.display = `none`;
                    }else if(Section_Array[User_Array.indexOf(SureAuthor.innerText)].includes(SureSection)){
                        getElementByXpath(`//*[@id="threadlisttableid"]/tbody[${SureCounter}]`).style.display = `none`;
                    }
                }
            }
            SureCounter = SureCounter + 1;
        }
    }
}

S1_Reply_Blocker();
S1_Sure_Blocker();
console.log(User_Array);
console.log(Section_Array);