【泥潭含水指数】来看看您到底有多水💦

// ==UserScript==
// @name         来看看您水多吗
// @namespace    泥潭含水量计算
// @version
// @description  快点干燥起来吧
// @author       nulluser
// @match        https://www.uscardforum.com/*
// @icon
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    // 创建一个显示牌的HTML元素
    var displayPanel = document.createElement('div');
    displayPanel.id = 'percentageDisplay';
    displayPanel.style.cssText = `
        position: fixed;
        bottom: 10px;
        right: 10px;
        width: 150px;
        height: 100px;
        background-color: rgba(0, 0, 0, 0.7);
        color: white;
        border-radius: 10px;
        text-align: center;
        line-height: 100px;
        font-size: 24px;
        font-weight: bold;
        z-index: 9999;
    `;

    // 创建一个更新按钮的HTML元素
    var updateButton = document.createElement('button');
    updateButton.id = 'updateButton';
    updateButton.textContent = '更新泥潭含水量';
    updateButton.style.cssText = `
        position: fixed;
        bottom: 120px;
        right: 10px;
        width: 150px;
        height: 30px;
        background-color: #007bff;
        color: white;
        border: none;
        border-radius: 5px;
        font-size: 15px;
        cursor: pointer;
    `;

    // 更新百分比值
    function updatePercentage() {
        let bad_ids = [11, 16, 34, 17, 18, 19, 29, 36, 35, 22, 26, 25];
        const bad_score = [];
        const good_score = [];
        // 定义要获取的URL数组
        const urls = [
            'https://www.uscardforum.com/latest.json?order=created',
            'https://www.uscardforum.com/new.json',
            'https://www.uscardforum.com/top.json?period=daily'
        ];

        // 使用Promise.all并发获取所有URL的数据
        Promise.all(urls.map(url => fetch(url).then(response => response.json())))
            .then(dataArray => {
                // 所有请求都成功后,这里将会收到一个包含所有JSON数据的数组
                // 数组中的元素顺序与urls数组中的URL顺序相同

                // 将数据合并或处理
                const combinedData = {
                    latest: dataArray[0].topic_list.topics, // 假设第一个URL返回的是最新的数据
                    new: dataArray[1].topic_list.topics,    // 假设第二个URL返回的是新的数据
                    top: dataArray[2].topic_list.topics     // 假设第三个URL返回的是每日热门数据
                };

                // 定义一个函数来处理每个主题的分数
                const processTopic = (topic) => {
                    const score = topic.posts_count + topic.like_count + topic.reply_count;
                    if (bad_ids.includes(topic.category_id)) {
                        bad_score.push(score);
                    } else {
                        good_score.push(score);
                    }
                };

                // 遍历每个主题列表并处理
                combinedData.latest.forEach(processTopic);
                combinedData.new.forEach(processTopic);
                combinedData.top.forEach(processTopic);

                // 计算bad_score和good_score的总和
                const bad_total = bad_score.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
                const good_total = good_score.reduce((accumulator, currentValue) => accumulator + currentValue, 0);

                // 打印结果
                const percentage = (bad_total / (bad_total + good_total)) * 100;
                console.log(`当前论坛含水量: ${percentage.toFixed(2)}%`);
                displayPanel.textContent = `${percentage.toFixed(2)}%`;

            })
            .catch(error => {
                // 处理任何在请求过程中发生的错误
                console.error('Error fetching data:', error);
            });

    }

    // 初始化显示牌和按钮
    function initializeDisplay() {
        document.body.appendChild(displayPanel);
        document.body.appendChild(updateButton);

        updatePercentage();

        updateButton.addEventListener('click', updatePercentage);
    }

    // 等待页面加载完成后再初始化显示牌
    window.addEventListener('load', initializeDisplay);
})();

)

【说明】
含水量10%以下,说明论坛近期干货满满;
含水量10%-20%,说明论坛近期干湿较为平衡;
含水量20%-30%,说明论坛近期稍微有点潮湿;
含水量30%-35%,说明论坛近期水分过于充足,需要注意了;
含水量数据超过35%,需要控制大水漫灌了。

【效果图】

【安装】

在浏览器拓展市场安装 篡改猴 插件(我是用的Violentmonkey ) 点:heavy_plus_sign:新建
把代码复制粘贴到插件里 保存
刷新 页面就可以看到右下方多了一个小框子

全谭参与 看看谁是泥潭水王!

备注:代码转自友站,感谢原作者

1 个赞

代码打开好像是空的?

1 个赞

代码已升仙,无即是有,有即是无,人人心中皆代码

1 个赞

战雷吧吧主三国中郎将名言: 你最近水量有点大 :yaoming:

1 个赞

@aqua

1 个赞

嗯哪,出了点小状况,更新好了tieba27

1 个赞

不学cs,不会用 :cry:

2 个赞

Screenshot 2024-07-15 120450

2 个赞

没有教程怎么跑上面的小程序吗?

  • 在浏览器拓展市场安装 篡改猴 插件(我是用的Violentmonkey ) 点:heavy_plus_sign:新建
  • 把代码复制粘贴到插件里 保存
  • 刷新 页面就可以看到右下方多了一个小框子
1 个赞

image

image

1 个赞

水王还没有出现(暂时)

有没有泥潭姚明指数,让大家看看谁是真正的姚明仙人 :yaoming:

应该可以抓取到数据,但我不会写啊,坐等泥潭大佬来写一个 :joy:

建议加到主楼,帮助像我这样的cs小白 :rofl:

我也是小白,不是学代码的 :joy:
已更新啦

1 个赞
const score = topic.posts_count + topic.like_count + topic.reply_count;

这个定义合理吗?

代码单词都认识,注释汉字也认识。
就是不知道啥意思。

粪哥,波塞冬。
image
嚓,刚注意图里这男人和水老师名字一个辈分。

1 个赞

你直接好人做到底,跑一轮,直接列出前20名,后20名吧 (up to mid July )

5 个赞