red list

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

Verze ze dne 18. 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    https://greasyfork.org/zh-CN/scripts/388742-red-list
// @version      0.2.5
// @description  世界是由各种各样的人组成的,当你拉黑某个沙雕,你也屏蔽了世界的一部分信息,世界也就变得不再完整。怎么办?拉红他!拉红之后,他依然会出现在你的视线里,但是会被标记,以提示这是你认为的一个沙雕。
// @author       taxayd
// @match        *://*.v2ex.com/*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// ==/UserScript==

(function() {
    'use strict';

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

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

    function redthis() {
        let strlist = GM_getValue(listName, "");
        let 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 (path == '/' || path.startsWith('/go/'))
    {
        // 首页及类首页
        let home_list = document.getElementsByClassName('cell item');
        let len = home_list.length;
        for(let i=0; i<len; i++) {
            let 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 (path.startsWith('/t/')) {
        // 帖子详情页
        let comments = document.getElementsByClassName('cell');
        let len = comments.length;
        for(let i=0; i<len; i++) {
            if (comments[i].id.substr(0, 2) != 'r_') {
                continue;
            }
            let 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 (path.startsWith('/member/')) {
        // 个人主页
        username_in_infopage = document.getElementsByTagName('h1')[0].innerText;
        // let button = document.getElementsByClassName('fr')[0];
        let button_container = document.getElementsByTagName('input')[1].parentElement;
        let 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_container.appendChild(red);
        document.getElementById(buttonName).onclick = redthis;
    }
})();