red list

世界是由各种各样的人组成的,当你拉黑某个沙雕,你也屏蔽了世界的一部分信息,世界也就变得不再完整。怎么办?拉红他!拉红之后,他依然会出现在你的视线里,但是会被标记,以提示这是你认为的一个沙雕。

Verze ze dne 17. 08. 2019. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         red list
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  世界是由各种各样的人组成的,当你拉黑某个沙雕,你也屏蔽了世界的一部分信息,世界也就变得不再完整。怎么办?拉红他!拉红之后,他依然会出现在你的视线里,但是会被标记,以提示这是你认为的一个沙雕。
// @author       You
// @match        *://www.v2ex.com/*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// ==/UserScript==

(function() {
    'use strict';

    var username_in_infopage;
    var listName = 'red-list';
    var strlist = GM_getValue(listName, "");
    var redlist = strlist.split(';');
    var url = document.URL;
    var buttonName = 'redbutton';

// delete all
//GM_deleteValue('red-list');console.log('list:' + GM_getValue('red-list', 'empty'));return;

    function redthis() {
        var strlist = GM_getValue(listName, "");
        var redlist = strlist.split(';');
        // console.log('redlist:' + redlist, 'username_in_infopage:' + username_in_infopage, 'strlist:' + strlist);
        if (redlist.indexOf(username_in_infopage) >= 0) {
            GM_setValue(listName, strlist.replace(';' + username_in_infopage, ''));
        } else {
            GM_setValue(listName, strlist + ';' + username_in_infopage);
        }
        document.getElementById(buttonName).value = GM_getValue(listName, '').split(';').indexOf(username_in_infopage)>=0 ? 'Unred' : 'Red';
        // console.log('strlist:' + GM_getValue(listName, ""));
    }

    if ('https://www.v2ex.com/' == url || 'https://www.v2ex.com/?' == url.substr(0, 22) || 'https://www.v2ex.com/go/' == url.substr(0, 24)) {
        // 首页及类首页
        var home_list = document.getElementsByClassName('cell item');
        var len = home_list.length;
        for(var i=0; i<len; i++) {
            var username = home_list[i].getElementsByTagName('strong')[0];
            if (redlist.indexOf(username.innerText) >= 0) {
                // console.log('in red list: ' + username.innerText);
                home_list[i].style = "background-image:url(https://i.loli.net/2019/06/09/5cfbebdfd083a19907.png);background-size:contain;";
            }
        }
    } else if (url.substr(0, 23) == 'https://www.v2ex.com/t/') {
        // 帖子详情页
        var comments = document.getElementsByClassName('cell');
        var len = comments.length;
        for(var i=0; i<len; i++) {
            if (comments[i].id.substr(0, 2) != 'r_') {
                continue;
            }
            var username = comments[i].getElementsByTagName('strong')[0];
            if (redlist.indexOf(username.innerText) >= 0) {
                // console.log('in red list: ' + username.innerText);
                comments[i].style = "background-image:url(https://i.loli.net/2019/06/09/5cfbebdfd083a19907.png);background-size:contain;";
            }
        }
    } else if (url.substr(0, 28) == 'https://www.v2ex.com/member/') {
        // 个人主页
        username_in_infopage = document.getElementsByTagName('h1')[0].innerText;
        var button = document.getElementsByClassName('fr')[0];
        var red = document.createElement('input');
        red.setAttribute('type', 'button');
        red.setAttribute('id', buttonName);
        red.setAttribute('value', redlist.indexOf(username_in_infopage)>=0 ? 'Unred' : 'Red');
        red.setAttribute('class', 'super normal button');
        button.appendChild(red);
        document.getElementById(buttonName).onclick = redthis;
    }
})();