豆瓣小组黑名单

移除豆瓣小组黑名单中发的帖子,黑名单为豆瓣-豆邮中添加的黑名单

目前为 2020-12-20 提交的版本。查看 最新版本

// ==UserScript==
// @name        豆瓣小组黑名单
// @version      1.0
// @description  移除豆瓣小组黑名单中发的帖子,黑名单为豆瓣-豆邮中添加的黑名单
// @author       cottonty
// @match        https://www.douban.com/group/*
// @grant GM_setValue
// @grant GM_getValue
// @connect  www.douban.com
// @namespace https://gf.qytechs.cn/users/719107
// ==/UserScript==

(function() {
    'use strict';

    var apiURL = "https://www.douban.com/contacts/blacklist";

    //var response;
    //GM_xmlhttpRequest ( {
    //    method:         "GET",
    //    url:            apiURL,
    //    onload:         process_Response,
    //} );

    var next = "";
    var re = /\?(.*)/i;
    var black_list = GM_getValue("blacklist");//GM_getValue('black_list', undefined);
    //console.log(black_list);
    if(black_list === undefined){
        black_list = []
        get_blacklist()
    }
    else{
        black_list = JSON.parse(black_list);
        process_Response(black_list)
        black_list = []
        get_blacklist()
    }
    function get_blacklist(){
        var request = new XMLHttpRequest();
        request.open("GET", apiURL+next);
        //console.log('test');
        request.onload = function(){
            if(request.readyState === XMLHttpRequest.DONE && request.status === 200){
                var black_list_doc = new DOMParser().parseFromString(request.response, "text/html");
                var black_list_name = black_list_doc.getElementsByClassName("obss namel")[0].firstElementChild
                while(black_list_name != null)
                {
                    //console.log(black_list_name);
                    black_list.push(black_list_name.firstElementChild.firstElementChild.href)
                    black_list_name = black_list_name.nextElementSibling
                    if(black_list_name.nextElementSibling == null){
                        break;
                    }
                }
                var nextelem = black_list_doc.getElementsByClassName("next")[0].firstElementChild;
                //console.log(nextelem)
                if(nextelem){
                    var matches = nextelem.href.match(re);
                    //console.log(matches);
                    next = matches[0];
                    //console.log(next);
                    get_blacklist();
                }
                else{
                    GM_setValue("blacklist", JSON.stringify(black_list))
                    process_Response(black_list)
                };
            };
        }
        request.send();
    };

    function process_Response(blk){
        var urlre = /https:\/\/www.douban.com\/group\/topic\/*/;
        if( window.location.href.match(urlre)){
            //console.log(window.location.href);
            Array.from(document.getElementsByClassName("clearfix comment-item reply-item ")).forEach(
                function(element, index, array) {
                    // do stuff
                    if(blk.includes(element.childNodes[1].childNodes[1].href)){
                        element.style.display='none';
                    }
                }
            );

            Array.from(document.getElementsByClassName("reply-quote-content")).forEach(
                function(element, index, array) {
                    // do stuff
                    //console.log(element)
                    //console.log(element.childNodes[7].firstElementChild.href)
                    if(blk.includes(element.childNodes[7].firstElementChild.href)){
                        element.style.display='none';
                    }
                }
            );

        }
        else{
            var threads = document.getElementsByClassName("olt")[0].childNodes[1]
            var thread = threads.firstElementChild.nextElementSibling
            var thread_to_del =[]
            while(thread != null)
            {
                //console.log(thread);
                //console.log(thread.childNodes[3].childNodes[1].href);
                if(blk.includes(thread.childNodes[3].childNodes[1].href)){
                    //console.log(thread);
                    //thread_to_del.push(thread)
                    thread.style.display = 'none';
                }
                thread = thread.nextElementSibling
            }
        }
    };

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址