Fanfou Local Blacklist

为饭否网页端加入了本地屏蔽功能,只要消息转发链中包含屏蔽列表中的用户,就能屏蔽那条消息。(暂时不能考虑因为消息过长被挤掉的用户)

目前為 2018-03-19 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Fanfou Local Blacklist
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  为饭否网页端加入了本地屏蔽功能,只要消息转发链中包含屏蔽列表中的用户,就能屏蔽那条消息。(暂时不能考虑因为消息过长被挤掉的用户)
// @author       You
// @include      http://fanfou.com/*
// @grant    GM.getValue
// @grant    GM.setValue
// @run-at document-end
// ==/UserScript==

(function() {
    'use strict';
    GM.getValue('blacklist').then(function(list){
        list = JSON.parse(list);
        if (window.location.pathname != '/home' && window.location.pathname != '/mentions') {
            var url = window.location.pathname;
            var blocked = list.includes(url);
            var actions = document.querySelector('#panel .actions');
            var addButton = document.createElement('a');
            addButton.href = 'javascript:void(0);';
            var setButton = function(b) {
                addButton.className = b?'bl':'bh';
                addButton.text = b?'取消屏蔽':'本地屏蔽';
            };
            var clicking = false;
            addButton.onclick = function(e) {
                if (clicking) return false;
                clicking = true;
                if (blocked) {
                    var index = list.indexOf(url);
                    list.splice(index, 1);
                } else {
                    list.push(url);
                }
                blocked = !blocked;
                setButton(blocked);
                GM.setValue('blacklist', JSON.stringify(list));
                clicking = false;
            };
            setButton(blocked);
            actions.appendChild(addButton);
        } else {
            var messages = document.querySelector('#stream ol').children;
            for (var i=0; i<messages.length; ++i) {
                var message = messages[i];
                var bad = false;
                var users = Array.from(message.querySelectorAll('.former'));
                users.push(message.querySelector('.author'));
                bad = bad || list.some(function(path){
                    return users.some(function(user){
                        return user.href.endsWith(path);
                    });
                });
                if (bad) message.remove();
            }
        }
    });
})();