查看 Trust Level 以及距离下一级的差距的油猴脚本 (偷自 linux.do)

查看 Trust Level 距离下一级的差距的油猴脚本
修改自 linux.do,原帖:https://linux.do/t/topic/29204 https://linux.do/t/topic/29483

  1. 浏览器安装油猴插件,Firefox 用户可以下载:Tampermonkey – Get this Extension for 🦊 Firefox (en-US)

  2. 填写用户名(不是“昵称”):

  1. 复制脚本:
// ==UserScript==
// @name         xjtu.app 等级
// @namespace    http://tampermonkey.net/
// @version      2024-03-06
// @description  Helps track progress towards Level 3 on xjtu.app
// @author       wen
// @match        https://xjtu.app/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=xjtu.app
// @grant        window.onurlchange
// @require      https://scriptcat.org/lib/513/2.0.0/ElementGetter.js
// ==/UserScript==

(function() {
    'use strict';

    async function fetchAboutData() {
        try {
            let response = await fetch(`https://xjtu.app/about.json`, {
                "headers": {
                    "Accept": "application/json",
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/117.0"
                },
                "method": "GET",
            });
            if (!response.ok) {
                throw new Error(`HTTP error! status: ${response.status}`);
            }
            return await response.json();
        } catch (error) {
            console.error("Fetching about data failed: ", error);
        }
    }

    async function fetchLevel() {
        try {
            let response = await fetch(`https://xjtu.app/u/=USERNAME=.json`, {
                "headers": {
                    "Accept-Language":"zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
                    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/117.0"
                },
                "method": "GET",
            });
            if (!response.ok) {
                throw new Error(`HTTP error! status: ${response.status}`);
            }
            return await response.json();
        } catch (error) {
            console.error("Fetching about data failed: ", error);
        }
    }

    function updateStatsElements() {
        // Define the target values for each stat
        const targetValues = {
            'days-visited': need_days_visited,
            'posts-read': Math.min(parseInt(parseInt(posts_30_days) / 4), 20000),
            'topics-entered': need_topics_read,
            'likes-given > a': need_likes_given,
            'likes-received': need_likes_received,
            'post-count > a': need_posts_read
        };

        // Update each stat element with the required target value for Level 3
        Object.keys(targetValues).forEach(stat => {
            const selector = `li.stats-${stat} > div > span > span`;
            elmGetter.get(selector).then(div => {
                const currentVal = div.getAttribute("title") || div.textContent;
                const targetVal = targetValues[stat];
                div.innerHTML = `${currentVal.replace(/,/g, '')} / ${targetVal}`;
                div.style.color = parseInt(currentVal.replace(/,/g, '')) >= parseInt(targetVal) ? "green" : "red";
            }).catch(error => {
                console.error(`Error updating ${stat}: `, error);
            });
        });
    }

    const need_days_visited = 50;
    const need_topics_reply = 10;
    const need_topics_read = 500;
    const need_topics_read_alltime = 200;
    const need_posts_read = 10;
    const need_posts_read_alltime = 500;
    const need_likes_given = 30;
    const need_likes_received = 20;

    let posts_30_days;

    // Initial data fetch and stats update
    fetchAboutData().then(data => {
        if (data) {
            posts_30_days = data.about.stats.posts_30_days;
            updateStatsElements();
        }
    });
    fetchLevel().then(data=>{
        if (data) {
            elmGetter.get("div.user-profile-names__primary").then(div => {
                div.innerHTML= div.textContent+"用户等级:"+data.user.trust_level;
            });
        }
    });

    // Update stats when the URL changes
    if (window.onurlchange === null) {
        window.addEventListener('urlchange', (info) => {
            if (info.url.match(/^https:\/\/xjtu\.men\/u\/[^\/]+\/summary/)) {
                updateStatsElements();
            }
        });
    }
})();
  1. 然后访问 https://xjtu.app/my/summary 即可

  2. 效果如下:

这个功能需求在 Discourse 开发者论坛上提到过,不过没人开发
linux.do 上面很多捣鼓电脑的人 (geek?),他们不懂、也不管什么插件不插件,直接写油猴脚本满足需求。

为什么他们这么关注 Trust Level 呢?
据我在该站潜水时候的不充分观察,linux.do提供的额外的福利服务跟用户等级有关
甚至有人研究挂机自动刷网站以提高等级。 :a_grinning_face_with_sweat:

1 Like

古德古德

好用好用