V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
xarthur
V2EX  ›  分享创造

显示用户注册时间的油猴脚本

  •  
  •   xarthur · 351 天前 · 1102 次点击
    这是一个创建于 351 天前的主题,其中的信息可能已经有所发展或是发生改变。

    花了一点点时间,写了一个非常简单的油猴脚本,可以显示帖子回复用户的注册时间,希望在这个诸君情绪都不稳定的时代,给大家多一点的辨认信息。

    // ==UserScript==
    // @name         Aparecium
    // @namespace    http://tampermonkey.net/
    // @version      0.1
    // @description  Shows User's create time in V2ex.
    // @author       FledgeShiu
    // @copyright    No License
    // @match        *://*.v2ex.com/t/*
    // @match        *://v2ex.com/t/*
    // @icon         https://v2ex.com/static/icon-192.png
    // @grant        none
    // ==/UserScript==
    
    (function() {
        'use strict';
        async function run() {
            let comment_nodes = document.querySelectorAll("div[id^=r_].cell");
            comment_nodes.forEach(async function(node){
                const user = node.querySelectorAll("tr>td:last-child")[0];
                const user_info_url = user.querySelectorAll("strong>a")[0].href;
                const user_name = user_info_url.split('/').at(-1);
                const response = await fetch(`https://${window.location.host}/api/members/show.json?username=${user_name}`);
                const jsonData = await response.json();
                const date = new Date(jsonData.created * 1000).toLocaleDateString()
                const age_element = user.getElementsByClassName("ago")[0];
                const next_element = age_element.nextSibling
                const empty_text = document.createTextNode('\u00A0 \u00A0');
                user.insertBefore(empty_text, next_element);
                let new_element = document.createElement("span");
                new_element.innerHTML = date;
                new_element.classList.add("ago");
                user.insertBefore(new_element, next_element);
            });
        }
        run()
    })();
    
    第 1 条附言  ·  351 天前

    更新了缓存和移动设备的支持。

    https://gist.github.com/FledgeXu/fba309a7d1a44ab09dc68c954c47a138

    5 条回复    2023-05-24 14:48:27 +08:00
    westoy
        1
    westoy  
       351 天前
    站长喜提 CC
    xarthur
        2
    xarthur  
    OP
       351 天前
    @westoy api 应该是有每小时限制的,所以应该没事?
    lisongeee
        3
    lisongeee  
       351 天前
    api/members/show.json 接口获得的信息可以保存在本地,key 是 id

    而根据头像链接可以直接获得用户 id ,所以每个用户实际上只需要一次请求就行
    shyangs
        4
    shyangs  
       351 天前
    建議加一層存儲層,把查詢過的儲存起來,

    先從腳本儲存裡撈,不要反反覆覆網路請求 API.
    christin
        5
    christin  
       350 天前
    这算是查成分吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1003 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 21:27 · PVG 05:27 · LAX 14:27 · JFK 17:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.