Pixel sites real online

makes online of pixel sites real

当前为 2025-05-05 提交的版本,查看 最新版本

// ==UserScript==
// @name         Pixel sites real online
// @namespace    https://pixuniverse.fun/
// @version      1.3
// @license      MIT
// @description  makes online of pixel sites real
// @author       small bee
// @match        *://*.fun/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';
    async function updateOnlineCount() {
        const res = await fetch('/api/shards', { credentials: 'same-origin' });
        if (!res.ok) return;
        const data = await res.json();
        let sum = 0;
        data.forEach(item => {
            if (Array.isArray(item) && item[1]) {
                Object.entries(item[1]).forEach(([k, v]) => {
                    if (k !== 'total' && typeof v === 'number') sum += v;
                });
            }
        });
        const span = document.querySelector('.onlinebox span[title="Total Online Users"]');
        if (!span) return;
        let textNode = Array.from(span.childNodes).find(n => n.nodeType === Node.TEXT_NODE);
        if (!textNode) {
            textNode = document.createTextNode('');
            span.insertBefore(textNode, span.firstChild);
        }
        textNode.textContent = sum;
    }
    updateOnlineCount();
    setInterval(updateOnlineCount, 15000);
})();