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

2023-05-23 12:38:57 +08:00
 xarthur

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

// ==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()
})();
1127 次点击
所在节点    分享创造
5 条回复
westoy
2023-05-23 12:46:39 +08:00
站长喜提 CC
xarthur
2023-05-23 12:50:24 +08:00
@westoy api 应该是有每小时限制的,所以应该没事?
lisongeee
2023-05-23 14:54:56 +08:00
api/members/show.json 接口获得的信息可以保存在本地,key 是 id

而根据头像链接可以直接获得用户 id ,所以每个用户实际上只需要一次请求就行
shyangs
2023-05-23 15:03:12 +08:00
建議加一層存儲層,把查詢過的儲存起來,

先從腳本儲存裡撈,不要反反覆覆網路請求 API.
christin
2023-05-24 14:48:27 +08:00
这算是查成分吗?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/942232

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX