您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
在最近评测上增加在线人数文本, 观察游戏的实际热度
当前为
// ==UserScript== // @name 显示Steam在线人数 // @description 在最近评测上增加在线人数文本, 观察游戏的实际热度 // @version 1.0 // @author cweijan // @namespace cweijan/steam_online_players // @license MIT // @run-at document-start // @grant GM_xmlhttpRequest // @include *store.steampowered.com/app/* // ==/UserScript== function makeElement(htmlString) { var div = document.createElement('div'); div.innerHTML = htmlString.trim(); return div.firstChild; } let onlineTextNode; let initText = GM_xmlhttpRequest ? '数据加载中' : '无网络权限!' const appId = location.href.match(/app\/(\d+)/)?.[1]; function fillText(msg) { if (onlineTextNode) onlineTextNode.textContent = msg else initText = msg } if (GM_xmlhttpRequest) { GM_xmlhttpRequest({ method: "GET", url: `https://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1/?appid=${appId}`, onload(response) { try { const playerCount = JSON.parse(response.responseText).response.player_count; fillText(playerCount) } catch (error) { fillText(`解析API返回值失败:${response.responseText}`) } }, onerror(response) { console.log(response) fillText("请求失败") } }) } const observer = new MutationObserver(mutationList => { for (var mutation of mutationList) { for (var node of mutation.addedNodes) { if (!node.querySelectorAll) continue; if (node.getAttribute("id") == 'userReviews') { const html = `<div class="user_reviews_summary_row"> <div class="subtitle column">在线人数:</div> <div class="summary column"> <span id="onlinePlayers" style="color: #5ac985;">${initText}</span> </div> </div>` node.insertBefore(makeElement(html), node.firstChild) onlineTextNode = document.getElementById('onlinePlayers') } } } }); observer.observe(document, { childList: true, subtree: true });