red list

try to take over the world!

目前为 2019-08-17 提交的版本。查看 最新版本

// ==UserScript==
// @name         red list
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @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;
    }
})();

QingJ © 2025

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