Block Douban User Status

Block Douban User's Status (including reposts)

目前為 2018-01-14 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Block Douban User Status
// @namespace    Zcc
// @version      0.3
// @description  Block Douban User's Status (including reposts)
// @author       Zcc
// @match        *://www.douban.com/*
// @match        *://www.douban.com/people/*
// @copyright    2017+, Zcc
// ==/UserScript==

// get blocking list
var blocked_UID = JSON.parse(localStorage.getItem('douban_blocked_UID')) || [],
    blocked_USR = JSON.parse(localStorage.getItem('douban_blocked_USR')) || [],
    ids_blocked = new RegExp(blocked_UID.join('|')),
    usr_blocked = new RegExp(blocked_USR.join('|'));

// modify blocking list
if(window.location.pathname === "/"){
    console.log("当前屏蔽的用户ID:", blocked_UID);
    console.log("当前屏蔽的用户昵称:", blocked_USR);
    $(".status-wrapper").each(function(index){  // 在each方法的回调函数中,其this指向DOM对象
        if (!blocked_UID.length || !blocked_USR.length) { return false; }
        var resharer = this.querySelector(".reshared_by > a"),
            usrname = resharer ? resharer.title : "";
        if (this.dataset.uid.match(ids_blocked) || usrname.match(usr_blocked)) {   // block the posts
            this.style.display = "none";
            // $(this).hide();
        }
    });
}else{
    var listEle = $('.more-opt .user-group-list');
    if (!listEle.length) { return false; }
    // let matches = $('#profile img').attr('src').match(/ul(\d+)/), usrid;
    // if (!matches || matches.length < 2) return false;
    // var usrid = matches[1];
    var usrid = people_info.id,     // is this method stable?
        usrname = people_info.name;
    if (blocked_UID.filter(function (num, nickname) {
            nickname = usrname;
            return num == usrid;
        }).length) {    // user already blocked
        listEle.prepend('<li><a href="javascript:;" class="cancel-block">取消屏蔽</a></li>');
    } else {
        listEle.prepend($('<li><a href="javascript:;" class="block-status">屏蔽广播</a></li>'));
    }
    // listEle.on( events, selector, data, handler );   // for jQuery v3.0+
    listEle.delegate('.cancel-block', 'click', function () {    // event delegation
        blocked_UID = blocked_UID.filter(function (num) {
            return usrid != num;
        });
        blocked_USR = blocked_USR.filter(function (nickname) {
            return usrname != nickname;
        });
        localStorage.setItem('douban_blocked_UID', JSON.stringify(blocked_UID));
        localStorage.setItem('douban_blocked_USR', JSON.stringify(blocked_USR));
        $(this).removeClass('cancel-block').addClass('block-status').text('屏蔽广播');
        console.log("当前屏蔽列表:", blocked_USR);
        // alert("当前屏蔽列表:", blocked_UID);   // Uncaught TypeError: Invalid Innovation
    })
    .delegate('.block-status', 'click', function () {
        blocked_UID.push(parseInt(usrid, 10));
        blocked_USR.push(usrname);
        localStorage.setItem('douban_blocked_UID', JSON.stringify(blocked_UID));
        localStorage.setItem('douban_blocked_USR', JSON.stringify(blocked_USR));
        $(this).removeClass('block-status').addClass('cancel-block').text('取消屏蔽');
        console.log("当前屏蔽列表:", blocked_USR);
    });
}