Tcafe Block User

try to take over the world!

As of 2020-12-15. See the latest version.

// ==UserScript==
// @name         Tcafe Block User
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  try to take over the world!
// @author       You
// @include      /tcafe2a.com/
// @require      http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant        GM_setValue
// @grant        GM_getValue
// @grant		 GM_addStyle
// @run-at       document-end
// ==/UserScript==
(function() { var css = document.createElement('link'); css.href = 'https://use.fontawesome.com/releases/v5.15.1/css/all.css'; css.rel = 'stylesheet'; css.type = 'text/css'; document.getElementsByTagName('head')[0].appendChild(css); })();

GM_addStyle (`
body {
    position: absolute!important;
    top: 0!important;
    bottom: 0!important;
    left: 0!important;
    right: 0!important;
    width: 1100px!important;
    margin: auto!important;
}
.BanList {
    position: absolute;
    left: 10px;
    top: 10px;
    z-index: 9999999;
    border: 2px solid #4CAF50;
    text-align: center;
	font-family: 'Nanum Gothic', "Malgun Gothic", dotum, sans-serif !important;	
    background-color: white;
    padding: .4em .4em;
}
.BanList-wrapper {
    text-align: left;
    font-size: 13px;
    font-family: 'Nanum Gothic', "Malgun Gothic", dotum, sans-serif !important;
    margin: auto;
}
.BanCheck {
    text-align: center !important;
    margin: auto;
}
`);

//document.querySelector('.top_bg').insertAdjacentHTML('beforeend', '&nbsp;<a class="BanIcon fas fa-ban" href="javascript:void(0)">BanLIST</>')
document.querySelector('body').insertAdjacentHTML('beforebegin', '<div class="BanList">BanList&nbsp;&nbsp;&nbsp;&nbsp;</><i class="BanListupdate far fa-save"></i>')

// 차단유저 ID
var IDs = JSON.parse(GM_getValue("IDs", "[]"))

// 대상 node 선택
const target = document.querySelector('body')


// 감시자 인스턴스 만들기
var observer = new MutationObserver(function(mutations) {

    IDs.forEach(function (ID, index, array) {
        let IDNode1 = document.querySelectorAll("div.user > a[onclick*=" + ID +"]")
        let IDNode2 = document.querySelectorAll("td > a[onclick*=" + ID +"]")

        if(IDNode2){
            for(var j=0; j < IDNode2.length; j++) {
                if (IDNode2[j].parentNode) {
                    console.log('게시글 번호  : ' + IDNode2[j].closest('tr').getAttribute('id') + ' -- ID : ' + ID)
                    $(IDNode2[j]).closest('tr').remove()
                }
            }
        }
        if(IDNode1 && /wr_id/.test(window.location.href)){
            for(var i=0; i < IDNode1.length; i++) {
                if (IDNode1[i].parentNode) {
                    console.log('코멘트 번호 : ' + IDNode1[i].closest('div.user').nextElementSibling.children[1].getAttribute('name') + ' -- ID : ' + ID)
                    $(IDNode1[i]).closest('div.box').remove()
                }
            }
        }
    })
    observer.disconnect()
})

// 감시자의 설정:
var config = { attributes: true, childList: true };

// 감시자 옵션 포함, 대상 노드에 전달
observer.observe(target, config);

function BanList() {
    let getids = document.querySelector('td#sideViewRow_mb_id > span > a').getAttribute('href')
    let id =getids.replace(/.*\&stx=/,'')
    if(IDs.indexOf(id) !== -1){
        alert("이미 차단 등록되었습니다!")
    } else{
        IDs.push(id)
        GM_setValue("IDs", JSON.stringify(IDs))
        Reload()
    }
}


let BanIDs = document.querySelectorAll('span.member')

for (let i = 0; i < BanIDs.length; i++) {
    BanIDs[i].addEventListener("click", async function(e){
        await sleep(150)
        let entries = document.querySelector('td#sideViewRow_mb_id')
        //console.log(entries)
        entries.closest('tr').insertAdjacentHTML('afterend', '<tr height="19"><td id="Banid">&nbsp;<font color="gray">·</font>&nbsp;<span style="color: #A0A0A0;"><a href="javascript:void(0);">Ban ID</a></span></td></tr>')
        document.querySelector('#Banid').addEventListener("click", function(e){
            e.preventDefault()
            BanList()
        });

    })
}

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

function update() {
    let BanCheck = document.querySelectorAll('.BanCheck')
    //console.log(BanCheck)
    for (let i = 0; i < BanCheck.length; i++) {
        if (BanCheck[i].checked == false){
            var AddID = BanCheck[i].getAttribute('id')
            //console.log(AddID)
            IDs.splice(IDs.indexOf(AddID), 1)
            //console.log(IDs)
        }
        if(i == BanCheck.length -1){
            GM_setValue("IDs", JSON.stringify(IDs))
            Reload()
        }
    }
}

const Bancontainer = document.querySelector('.BanList')
const BanUpdate = document.querySelector('.BanListUpdate')

BanUpdate.addEventListener("click", function(e){
    update()
})

MakeList()

function Reload() {
    var element = document.querySelectorAll('.BanList-wrapper')
    Array.prototype.forEach.call( element, function( node ) {
        node.parentNode.removeChild( node );
    });    
    MakeList()
}

function MakeList() {
    for (let i = 0; i < IDs.length; i++) {
        let wrapper = document.createElement('div')
        let label = document.createElement('label')
        let checkbox = document.createElement('input')

        wrapper.classList.add('BanList-wrapper')
        label.textContent = ' ' + IDs[i] + " [ " + document.querySelectorAll("td > a[onclick*=" + IDs[i] +"]").length + " | " + document.querySelectorAll("div.user > a[onclick*=" + IDs[i] +"]").length + " ]"
        checkbox.type = 'checkbox'
        checkbox.checked = true
        checkbox.setAttribute("class", 'BanCheck')
        checkbox.setAttribute("id", IDs[i])
        wrapper.appendChild(checkbox)
        wrapper.appendChild(label)
        Bancontainer.appendChild(wrapper)
    }
}