V2EX自动Block"新"注册账号

try to take over the world!

// ==UserScript==
// @name         V2EX自动Block"新"注册账号
// @namespace    https://taosky.github.io/
// @version      0.3
// @description  try to take over the world!
// @author       You
// @match        https://www.v2ex.com/t/*
// @grant        none
// ==/UserScript==

//设定年份(大于则Block)
var afterYear = 2019;


function getUsers(){
    let users = [];
    let cellNodes = $('.cell');
    for (let cellNode of cellNodes){
        if (cellNode.id.startsWith('r_')){
            for (let aNode of cellNode.getElementsByTagName('a')){
                if (aNode.href.startsWith('https://www.v2ex.com/member/')){
                    users.push(aNode.text);
                }
            }
        }
    }
    return users;

}
function checkBlockUser(user, timeParam){
    console.log(timeParam)
    let reg = /加入于 (\d+)/;
    $.get(`https://www.v2ex.com/api/members/show.json?username=${user}`, function(result){
            let regDate = new Date(result.created * 1000)
            if (regDate.getUTCFullYear()> afterYear){
                $.get(`https://www.v2ex.com/block/${result.id}?t=${timeParam}`);
                console.log(user + ':' + '加入于'+regDate.getUTCFullYear() +'年, ' + '已Block')
            }else {
                console.log(user + ':' + '加入于'+regDate.getUTCFullYear() +'年, ' + '未Block')
            }
        });
}
(function() {
    'use strict';
        for (let aNode of $('.top')){
        if (aNode.href.startsWith('https://www.v2ex.com/member/')){
           $.get(`https://www.v2ex.com/api/members/show.json?username=${aNode.text}`, function(result){
               let timeParam = result.created;
               if (timeParam === null){
        console.log('未登录');
        return;
    }
    let users = getUsers();
    for (let user of users){
        checkBlockUser(user, timeParam);
    }
           });
        }
    }
})();