Tcafe Block User

티카페 특정 유저 글과 코멘트 숨기기

Version au 17/12/2020. Voir la dernière version.

Vous devrez installer une extension telle que Tampermonkey, Greasemonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Userscripts pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension de gestionnaire de script utilisateur pour installer ce script.

(J'ai déjà un gestionnaire de scripts utilisateur, laissez-moi l'installer !)

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

(J'ai déjà un gestionnaire de style utilisateur, laissez-moi l'installer!)

// ==UserScript==
// @name         Tcafe Block User
// @namespace    http://tampermonkey.net/
// @version      3.2
// @description  티카페 특정 유저 글과 코멘트 숨기기
// @author       DandyClubs
// @match        *://tcafe2a.com/*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
// @grant        GM_setValue
// @grant        GM_getValue
// @grant		 GM_addStyle
// @run-at       document-start
// ==/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: 905px;
    top: 5px;
    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;
    margin: auto;
    font-size: 14px;
}
.BanButton {
    position : absolute;
    left: 905px;
    top: 5px;
    z-index: 9999998;
    font-family: 'Nanum Gothic', "Malgun Gothic", dotum, sans-serif !important;
    //background-color: white;
    padding: .5em;
    margin: auto;
    font-size: 16px;
}
.BanList-wrapper {
    text-align: left;
    font-size: 12px;
    font-family: 'Nanum Gothic', "Malgun Gothic", dotum, sans-serif !important;
    margin: auto;
}
.BanCheck {
    text-align: center !important;
    margin: auto;
}
.BanCounts.fa-layers-counter {
    background-color: #ff253a;
    border-radius: 1em;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    color: #fff;
    height: 1.5em;
    line-height: 1;
    max-width: 5em;
    min-width: 1.5em;
    overflow: hidden;
    padding: .25em;
    right: 0;
    text-overflow: ellipsis;
    top: 0;
    -webkit-transform: scale(0.65);
    transform: scale(0.65);
    -webkit-transform-origin: top right;
    transform-origin: top right;
}
.BanCounts.fa-layers-counter, .fa-layers-text {
    display: inline-block;
    position: absolute;
    text-align: center;
}
.BanNotice {
    display: inline-block;
    position: absolute;
    text-align: center;
    border-radius: 1em;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    color: white;
    padding: .25em;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
    font-family: 'Nanum Gothic', "Malgun Gothic", dotum, sans-serif !important;
}
`);

$(document).ready(function(){

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


    document.querySelector("table#cssImg").insertAdjacentHTML('afterend', '<div class="BanButton"><i class="BanButtonIcon far fa-angry fa-2x fa-spin" style="color:#FF2D00 !important;"></i><span class="BanCounts fa-layers-counter" style="background:Tomato">' + IDsCounts + '</span></>')
    document.querySelector("table#cssImg").insertAdjacentHTML('afterend', '<div class="BanList"><i class="BanListupdate far fa-save"></i>&nbsp;&nbsp;BanList&nbsp;&nbsp;<i class="BanListClose fas fa-times"></i></>')

    if(ShowHide == 'Hide'){
        $(".BanList").hide()
        $(".BanButton").show()
    }
    else{
        $(".BanButton").hide()
        $(".BanList").show()
    }

    IDs.forEach(function (item) {
        var idx = item.ID
        let IDNodeC = document.querySelectorAll('div.user > a[onclick*="' + idx +'"]')
        let IDNodeW = document.querySelectorAll('td > a[onclick*="' + idx +'"]')

        //코멘트 제거
        if(IDNodeC && /wr_id/.test(window.location.href)){
            for(var i=0; i < IDNodeC.length; i++) {
                var matchIDc = IDNodeC[i].outerHTML.match(/showSideView\(this, '(.*)',/)
                if (IDNodeC[i].parentNode.className ==='user' && matchIDc[1] == item.ID) {
                    console.log('코멘트 번호 : ' + IDNodeC[i].parentNode.nextElementSibling.children[1].getAttribute('name') + ' -- 닉네임 : ' + item.NickName)
                    IDNodeC[i].closest('div.box').style.display = 'none';
                }
            }
        }
        //글목록에서 제거
        if(IDNodeW){
            for(var j=0; j < IDNodeW.length; j++) {
                var matchID = IDNodeW[j].outerHTML.match(/showSideView\(this, '(.*)',/)
                if (IDNodeW[j].closest('tr') && matchID[1] == item.ID) {
                    console.log('게시글 번호  : ' + IDNodeW[j].closest('tr').getAttribute('id') + ' -- 닉네임 : ' + item.NickName)
                    IDNodeW[j].closest('tr').style.display = 'none';
                }
            }
        }
    })

    function BanList(GetID, GetNickName, AddBanNoticei) {

        let searchID = IDs.find( ({ ID }) => ID === GetID )
        let searchNickName = IDs.find( ({ NickName }) => NickName === GetNickName )
        if(searchNickName){
            //alert("[ " + GetNickName + " ] 이미 차단 등록되었습니다!")
            AddBanNoticei.textContent = GetNickName + ' 이미 차단 등록되었습니다!'
            $(AddBanNoticei).slideDown('fast')
            setTimeout(function(){ $(AddBanNoticei).slideUp('slow') }, 2000);
        } else if(searchID){
            //alert("[ " + GetID + " ] 이미 차단 등록되었습니다!")
            AddBanNoticei.textContent = GetID + ' 이미 차단 등록되었습니다!'
            $(AddBanNoticei).slideDown('fast')
            setTimeout(function(){ $(AddBanNoticei).slideUp('slow') }, 2000);
        } else {
            IDs.push({ID : GetID, NickName : GetNickName});
            GM_setValue("IDs", JSON.stringify(IDs))
            document.querySelector('.BanCounts').textContent = IDs.length
            AddBanNoticei.textContent = GetNickName + ' 차단 등록되었습니다.'
            $(AddBanNoticei).slideDown('fast')
            setTimeout(function(){ $(AddBanNoticei).slideUp('slow') }, 1000);
            Reload()
        }
    }

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

    for (let i = 0; i < BanIDs.length; i++) {
        BanIDs[i].parentNode.insertAdjacentHTML('afterend', '&nbsp;<a class="AddBan" href="javascript:void(0)"><i class="fas fa-user-slash" style="color:#FF2D00 !important;"><span class="BanNotice fa-layers-counter" style="background:Tomato; display:none;"></span></i></>')
    }

    function update() {
        let BanCheck = document.querySelectorAll('.BanCheck')
        //console.log(BanCheck)
        for (let i = 0; i < BanCheck.length; i++) {
            if (BanCheck[i].checked == false){
                var RemoveNickName = BanCheck[i].getAttribute('NickName')
                //console.log(AddID)
                var removeIndex = IDs.map(function(item) { return item.NickName; }).indexOf(RemoveNickName);

                // remove object
                IDs.splice(removeIndex, 1);

            }
            if(i == BanCheck.length -1){
                GM_setValue("IDs", JSON.stringify(IDs))
                document.querySelector('.BanCounts').textContent = IDs.length
                Reload()
            }
        }
    }



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

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

    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].NickName + " [ " + document.querySelectorAll("td > a[onclick*=" + IDs[i].ID +"]").length + " | " + document.querySelectorAll("div.user > a[onclick*=" + IDs[i].ID +"]").length + " ]"
            label.textContent = ' ' + IDs[i].NickName
            checkbox.type = 'checkbox'
            checkbox.checked = true
            checkbox.setAttribute("class", 'BanCheck')
            checkbox.setAttribute("NickName", IDs[i].NickName)
            wrapper.appendChild(checkbox)
            wrapper.appendChild(label)
            Bancontainer.appendChild(wrapper)
        }
    }

    var floatPosition = parseInt($(".BanButton").css('top'));

    $(window).scroll(function() {
        // 현재 스크롤 위치를 가져온다.
        var scrollTop = $(window).scrollTop();
        var newPosition = scrollTop + floatPosition + "px";

        $(".BanButton").css('top', newPosition);
        $(".BanList").css('top', newPosition);

    }).scroll();

    $(".BanListClose").click(function(){
        $(".BanList").slideUp(function() {
            $(".BanButton").slideDown()
            ShowHide = 'Hide'
            GM_setValue("ShowHide", ShowHide)
        })
    })

    $(".BanButtonIcon").click(function(){
        $(".BanButton").slideUp(function() {
            $(".BanList").slideDown()
            ShowHide = 'Show'
            GM_setValue("ShowHide", ShowHide)
        })
    })


    let AddBanIcon = document.querySelectorAll('.AddBan')
    let AddBanNotice = document.querySelectorAll('.BanNotice')

    for (let i = 0; i < AddBanIcon.length; i++) {
        AddBanIcon[i].addEventListener("click", function(e){
            let getinfo = AddBanIcon[i].previousElementSibling.getAttribute('onclick')
            let GetNickName = AddBanIcon[i].previousElementSibling.textContent
            let GetID = getinfo.match(/showSideView\(this, '(.*)',/)[1]
            BanList(GetID, GetNickName, AddBanNotice[i])
            AddBanIcon[i].childNodes[0].style = "color: Indigo !important;"
        })
    }

    MakeList()

})