Fanfou Local Blacklist

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

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

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

(async function() {
    'use strict';
    GM_addStyle('#stream>ol>li>.content { filter:blur(10px) }');
    GM_addStyle('#stream>ol>li.good>.content { filter:none }');
    GM_addStyle(`#stream>ol>li.bad::before { 
    text-align: center;
    font-size: 1em;
    position: absolute;
    content: attr(data-blame);
    width: 100%;
    display: flex;
    height: 100%;
    top: 0;
    left: 0;
    justify-content: center;
    align-items: center;
    color: firebrick;
 }`);
    var list = await GM_getValue('blacklist');
    document.addEventListener("DOMContentLoaded", async function(){
        if (!list) list = '[]';
        list = JSON.parse(list);
        list = list.map(id => decodeURIComponent(id));
        if (window.location.pathname != '/home' && window.location.pathname != '/mentions') {
            var url = decodeURIComponent(window.location.pathname);
            var blocked = list.includes(url);
            var actions = document.querySelector('#panel .actions');
            if (actions === null)
              actions = document.querySelector('#profile-protected .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 = async 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);
                await GM_setValue('blacklist', JSON.stringify(list));
                clicking = false;
            };
            setButton(blocked);
            actions.appendChild(addButton);
        } else {
            var target = document.querySelector('#stream ol');
            var updating = false;
            var UpdateTL = function() {
                if (updating) return;
                updating = true;
                var messages = target.children;
                //var bad_msgs = [];
                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'));
                    var blame = "";
                    bad = bad || list.some(function(path){
                        return users.some(function(user){
                            var res = decodeURIComponent(user.href).endsWith(decodeURIComponent(path));
                            if (res) blame = user.textContent;
                            return res;
                        });
                    });
                    //if (bad) bad_msgs.push(message);
                    if (!bad) message.classList.add("good"); else {
                      message.setAttribute("data-blame", "因@" + blame + "而被屏蔽");
                      message.classList.add("bad");
                    }
                }
                //bad_msgs.forEach(function(msg) {msg.remove();});
                updating = false;
            };
            var observer = new MutationObserver(UpdateTL);
            observer.observe(target, {childList: true});
            UpdateTL();
        }
    });
})();

QingJ © 2025

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