S1 User Blocker

Block certain user's content

Versión del día 12/01/2021. Echa un vistazo a la versión más reciente.

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

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

Necesitarás instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Necesitará instalar una extensión como Tampermonkey para instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión como Stylus para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

Necesitará instalar una extensión del gestor de estilos de usuario para instalar este estilo.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==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 = 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);