豆瓣小组黑名单

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

目前為 2020-12-20 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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://greasyfork.org/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
            }
        }
    };

})();