| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- """Recon the 996box home page: exact game cards, their hrefs/gameIds, and
- which one is 玖扬复古176 (gameId 206923) vs the imposter that got launched
- last time. Never guess by text alone — match by gameId in href/data attrs.
- """
- import asyncio
- import json
- import sys
- import httpx
- import websockets
- async def main():
- async with httpx.AsyncClient(timeout=5) as c:
- r = await c.get("http://127.0.0.1:9222/json/list")
- home = next((t for t in r.json() if "homePage" in t.get("url", "")), None)
- if not home:
- print("no home page target")
- return 1
- async with websockets.connect(home["webSocketDebuggerUrl"], max_size=10**7) as ws:
- mid = 0
- async def ev(expr):
- nonlocal mid
- mid += 1
- await ws.send(json.dumps({"id": mid, "method": "Runtime.evaluate",
- "params": {"expression": expr, "returnByValue": True}}))
- while True:
- m = json.loads(await ws.recv())
- if m.get("id") == mid:
- return m.get("result", {}).get("result", {}).get("value")
- # 1. all elements carrying a gameId anywhere (href, data-*, class context)
- info = await ev(r"""
- (function() {
- const out = [];
- const all = document.querySelectorAll('a, [data-id], [data-gameid], [class*=game]');
- const seen = new Set();
- for (const el of all) {
- if (!el.offsetParent) continue;
- const href = el.getAttribute('href') || '';
- const did = el.getAttribute('data-id') || el.getAttribute('data-gameid') || '';
- let gid = '';
- const m = href.match(/gameId[=/](\d+)/) || (did.match(/^\d+$/) ? [null, did] : null);
- if (m) gid = m[1];
- const rect = el.getBoundingClientRect();
- const text = (el.innerText || '').trim();
- const label = text.split('\n').filter(l => l.trim()).slice(0, 2).join(' | ').slice(0, 50);
- const key = gid + '|' + label;
- if (seen.has(key)) continue;
- seen.add(key);
- if (gid || label.includes('复古') || label.includes('玖扬')) {
- out.push({gid, label, x: Math.round(rect.x + rect.width/2), y: Math.round(rect.y + rect.height/2),
- href: href.slice(0, 70)});
- }
- if (out.length >= 20) break;
- }
- return JSON.stringify(out);
- })()
- """)
- print("=== elements with gameId / 复古 / 玖扬 ===")
- try:
- for g in json.loads(info or "[]"):
- mark = " <<< TARGET" if g["gid"] == "206923" else ""
- print(f" gid={g['gid'] or '----':<7} '{g['label']}' @({g['x']},{g['y']}) {g['href'][:50]}{mark}")
- except Exception as e:
- print("parse err:", e)
- print((info or "")[:600])
- # 2. search input current state + where game suggestions render
- sr = await ev(r"""
- (function() {
- const inp = document.querySelector('input[placeholder]');
- if (!inp) return null;
- const r = inp.getBoundingClientRect();
- return JSON.stringify({ph: inp.placeholder, val: inp.value, x: Math.round(r.x + r.width/2), y: Math.round(r.y + r.height/2)});
- })()
- """)
- print(f"\nsearch input: {sr}")
- # 3. What is the CURRENT highlighted/recommended game (the one with 启动)?
- cur = await ev(r"""
- (function() {
- const btns = [];
- for (const b of document.querySelectorAll('button, [class*=btn]')) {
- const t = (b.innerText || '').trim();
- if (/^(启动|开始游戏)$/.test(t) && b.offsetParent) {
- const r = b.getBoundingClientRect();
- // climb up to find the enclosing card's title
- let card = b.closest('[class*=game], [class*=card], [class*=item], li, div');
- let title = '';
- for (let i = 0; i < 6 && card; i++) {
- const h = card.querySelector('[class*=name], [class*=title], h3, h4, .title');
- if (h) { title = (h.innerText || '').trim().slice(0, 40); break; }
- card = card.parentElement;
- }
- btns.push({text: t, x: Math.round(r.x + r.width/2), y: Math.round(r.y + r.height/2), cardTitle: title});
- }
- }
- return JSON.stringify(btns.slice(0, 8));
- })()
- """)
- print(f"\n启动 buttons + their card titles:")
- try:
- for b in json.loads(cur or "[]"):
- print(f" '{b['text']}' @({b['x']},{b['y']}) card='{b['cardTitle']}'")
- except Exception:
- print((cur or "")[:400])
- return 0
- sys.exit(asyncio.run(main()))
|