'use strict' const fs = require('fs') const path = require('path') let _cachedPayload = null let _updateCb = null let _ctx = null let _timer = null let _lastGame = '' let _stateFile = null function stateRead(key, fallback = '') { try { const data = JSON.parse(fs.readFileSync(_stateFile, 'utf-8')) return data[key] ?? fallback } catch { return fallback } } function stateWrite(key, value) { try { let data = {} try { data = JSON.parse(fs.readFileSync(_stateFile, 'utf-8')) } catch {} data[key] = value fs.writeFileSync(_stateFile, JSON.stringify(data, null, 2), 'utf-8') } catch {} } async function fetchSteamGame(steamUrl) { if (!steamUrl || !steamUrl.trim()) return null try { const url = steamUrl.trim().replace(/\/$/, '') + '/' const ctrl = new AbortController() const tid = setTimeout(() => ctrl.abort(), 10_000) try { const res = await fetch(url, { signal: ctrl.signal, headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Gecko/20100101 Firefox/120.0', }, }) if (!res.ok) return null const html = await res.text() const inGame = html.match( /class="profile_in_game_name"[^>]*>\s*([^<]+?)\s*