Block Douban User Status

Block Douban User's Status (reposts excluded)

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

您需要先安裝使用者腳本管理器擴展,如 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.1
// @description  Block Douban User's Status (reposts excluded)
// @author       Zcc
// @match        *://www.douban.com/*
// @match        *://www.douban.com/people/*
// @copyright    2017+, Zcc
// ==/UserScript==

// window.onload = function () {
    // block
    var block_list = JSON.parse(localStorage.getItem('douban_block_list')) || [],
        r_block = new RegExp(block_list.join('|'));
    // console.log("block_list", block_list);
    // console.log("r_block", r_block);
    $(".status-wrapper, .status-wrapper > .reshared_by").each(function(index, wrapper){
        if (!block_list.length) { return false; }
        if (wrapper.dataset.uid.match(r_block)) {   // block the original posts
            // $(wrapper).find('.status-item').hide();  // hide()非法调用
            wrapper.parentNode.removeChild(wrapper);
        }
        // block the reposts
    });
    
    if(window.location.pathname !== "/"){
        // add user to block list
        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;
        // usrid = matches[1];
        var usrid = people_info.id;
        if (block_list.filter(function (num) {
                return num == usrid;
            }).length) {    // 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.delegate('.cancel-block', 'click', function () {
            block_list = block_list.filter(function (num) {
                return usrid != num;
            });
            localStorage.setItem('douban_block_list', JSON.stringify(block_list));
            $(this).removeClass('cancel-block').addClass('block-status').text('屏蔽广播');
        })
        .delegate('.block-status', 'click', function () {
            block_list.push(parseInt(usrid, 10));
            localStorage.setItem('douban_block_list', JSON.stringify(block_list));
            $(this).removeClass('block-status').addClass('cancel-block').text('取消屏蔽');
        });
    }
// };