S1 User Blocker

Block certain user's content

2021-01-12 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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 = 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);