bump

查看用户的提升卡使用记录

当前为 2021-12-26 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         bump
// @version      0.0.2
// @include      https://www.mcbbs.net/home.php?mod=space*
// @include      https://www.mcbbs.net/?*
// @author       xmdhs
// @license MIT
// @description  查看用户的提升卡使用记录
// @namespace https://greasyfork.org/users/166541
// ==/UserScript==
(async () => {
    const uid = getuid();
    if (uid === null) {
        alert("无法获取 uid");
        return;
    }
    let d = {
        data: [],
        msg: "",
        code: 0
    };
    let f = await fetch(`https://auto.xmdhs.top/getforuid?uid=` + uid);
    d = await f.json();
    if (d.code != 0) {
        console.warn(d.msg);
        alert(d.msg);
        return;
    }
    if (d.data == null) {
        console.log("没有数据");
        return;
    }
    let p = document.querySelector("#ct > div > div.bm.bw0 > div > div.bm_c.u_profile");
    let div = document.createElement("div");
    p ? p.appendChild(div) : console.warn("没有找到");
    let text = document.createElement("h2");
    text.className = "mbn";
    text.innerText = "提升卡记录";
    div.appendChild(text);
    div.appendChild(makeTable(d.data));
    let psts = document.querySelector("#psts");
    psts && (psts.className = "pbm mbm bbda cl");
    function countData(data) {
        let m = {};
        for (const v of data) {
            if (v.operation.indexOf("提升卡") == -1) {
                continue;
            }
            if (m[v.tid] == undefined) {
                m[v.tid] = { count: 1, lastime: v.time };
            }
            else {
                m[v.tid].count++;
                v.time > m[v.tid].lastime && (m[v.tid].lastime = v.time);
            }
        }
        return m;
    }
    function makeTable(data) {
        const c = countData(data);
        let table = document.createElement("table");
        table.className = "bm dt";
        let tbody = document.createElement("tbody");
        table.appendChild(tbody);
        let tr = document.createElement("tr");
        tbody.appendChild(tr);
        tr.innerHTML = `<th class="xw1">tid</th><th class="xw1">数量</th><th class="xw1">上一次顶贴时间</th>`;
        for (const v in c) {
            let trr = document.createElement("tr");
            tbody.appendChild(trr);
            addTr(trr, `<a href="https://www.mcbbs.net/thread-${v}-1-1.html" target="_blank">${v}</a>`, true);
            addTr(trr, String(c[v].count));
            addTr(trr, transformTime(c[v].lastime));
        }
        return table;
    }
    function addTr(item, v, h) {
        let t = document.createElement("td");
        if (h === true) {
            t.innerHTML = v;
        }
        else {
            t.innerText = v;
        }
        item.appendChild(t);
    }
    function transformTime(timestamp) {
        var time = new Date(timestamp * 1000);
        var y = time.getFullYear();
        var M = time.getMonth() + 1;
        var d = time.getDate();
        var h = time.getHours();
        var m = time.getMinutes();
        return y + '-' + addZero(M) + '-' + addZero(d) + ' ' + addZero(h) + ':' + addZero(m);
    }
    function addZero(m) {
        return m < 10 ? '0' + String(m) : String(m);
    }
    function getuid() {
        let u = new URL(location.href);
        let uid = u.searchParams.get('uid');
        if (uid && uid.length > 0) {
            return uid;
        }
        u = new URL(location.href);
        return u.searchParams.get('uid');
    }
})();