Files
pokerfreak/lobby/cdp.mjs
T
mmintelandClaude Sonnet 5.5 d5ac7a3c46 Mitschriebe aufgeraeumt: 62 -> 30 Markdown-Dateien, Einzelfakten uebernommen
Zusammengefuehrt: SONDERFAELLE -> SPECIALFAELLE; MODI-KETTE, SPIELARTEN -> MODI;
CLIENT-CODE, GEFUNDE-GELD-TAGS, FENSTER-KATALOG -> CLIENT-LUECKEN;
FENSTER-und-EINGABE, MESSUNG-eingabe, GERUEST -> EINGABE-WARUM; KACHELN-AX -> TISCHKANAL;
MENSCHLICH -> UNUNTERSCHEIDBAR; TURNIER-ANMELDUNG-LIVE, Buehnen-Vorfall -> TURNIERE;
GELD-SIMULATION, RUHM -> GELD; RAKE-gemessen -> RAUMWAHRHEITEN; SFS2X-Runde und
Ausfall 31.10. -> ANGRIFFSFLaeCHE; EINVERSTAENDNIS -> BETRUG-UND-REGELN;
acht VORFALL-* -> neues VORFAELLE.md. Typ-2-Sitout-Messung aus ABNAHME -> ZURUECK;
AKTION-KANAL 4/5 als erledigt markiert.
Geloescht: LUECKEN, MITTLER-IST-DER-WEG, CASINO-ANGRIFF, TRAGLAST, UMGEBUNG,
ABNAHME-2026-11-05, BLUFF, TOTER-TISCH. Verweise in Code, Specs, Docs, Plaenen und den
hof-Listen nachgezogen (nur Kommentare/Listen, keine Logik).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 23:30:24 +01:00

185 lines
8.9 KiB
JavaScript

#!/usr/bin/env node
// Steuert die Client-Oberfläche über das Debug-Port - ohne Koordinaten.
//
// node cdp.mjs --text # sichtbare Texte auflisten
// node cdp.mjs --click "Join" # Element über seinen Text klicken
// node cdp.mjs --eval "<js>" # beliebigen Ausdruck auswerten
//
// Die Seite wird über ihren Zieldaten ermittelt; geklickt wird der kleinste
// passende Knoten, damit nicht ein umschliessender Container getroffen wird.
// Dieselbe Regel wie client/umgebung.cdp_port: CDP_PORT, sonst der Klon (9402). Den Client (9333)
// erreicht es nur mit ausdruecklichem Port - der Betriebssatz (umgebung.betrieb_am_client) setzt ihn.
// Bis 6.11. nahm es ohne Angabe den Client (archiv/mitschrieb/VORFAELLE.md).
const PORT = process.env.CDP_PORT || 9402;
const args = process.argv.slice(2);
function flag(name) {
const i = args.indexOf(name);
return i < 0 ? null : (args[i + 1] ?? true);
}
async function seite() {
const liste = await (await fetch(`http://127.0.0.1:${PORT}/json/list`)).json();
return liste.find((t) => t.type === "page" && (t.url || "").includes("lobby"))
|| liste.find((t) => t.type === "page");
}
// Ein Klick, zwei Wege (hand/eingabe.py): im Klon die Ereignisse in der Seite; sonst mit der Maus
// nur die Bildschirmlage des Knopfs ("MAUS {x, y, text}") - den
// Klick macht Python. Alle Klicks dieser Datei und mcp/lobby_adapter.KLICK_ZEILE gehen hierüber.
const MAUS = process.env.EINGABE === "maus";
const VORSPANN = `window.__pfMaus = ${MAUS};
window.__pfKlick = (ziel) => {
// Was nicht im Bild steht, trifft kein Mausklick: der Reiterstreifen scrollt waagerecht
// ("horizontal-scroll-container", overflow auto), die hinteren Reiter liegen ausserhalb des
// Fensters (31.10.: "Practice Games" bei x=1344 in einem 1280 breiten Fenster - der Punkt
// lag nicht im Fenster, der Klick wurde verweigert). Darum erst ins Bild holen, dann messen.
// behavior "instant" ist Pflicht: der Streifen hat scroll-behavior smooth, sonst wird sofort
// die ALTE Lage gemessen (gemessen).
try { ziel.scrollIntoView({block: "nearest", inline: "center", behavior: "instant"}); } catch (e) { /* egal */ }
const r = ziel.getBoundingClientRect();
if (window.__pfMaus) {
const kopf = window.outerHeight - window.innerHeight;
return "MAUS " + JSON.stringify({x: window.screenX + r.x + r.width / 2,
y: window.screenY + kopf + r.y + r.height / 2,
text: (ziel.innerText || "").trim().replace(/\\s+/g, " ").slice(0, 50)});
}
const opt = { bubbles: true, cancelable: true, composed: true, button: 0,
clientX: r.x + r.width / 2, clientY: r.y + r.height / 2 };
for (const art of ["pointerdown", "mousedown", "pointerup", "mouseup", "click"]) {
ziel.dispatchEvent(art.startsWith("pointer") ? new PointerEvent(art, opt) : new MouseEvent(art, opt));
}
return null;
};`;
const SICHTBAR = `n.offsetParent !== null && (n.innerText || "").trim().length > 0`;
const KLICK = (text) => `(() => {
const wollen = ${JSON.stringify(text)}.trim().toLowerCase();
const alle = [...document.querySelectorAll('button, a, [role="button"], span, div, li')]
.filter((n) => ${SICHTBAR});
const genau = alle.filter((n) => (n.innerText || "").trim().toLowerCase() === wollen)
.sort((a, b) => {
const istKnopf = (n) => (n.tagName === 'BUTTON' ||
n.getAttribute('role') === 'button') ? 0 : 1;
if (istKnopf(a) !== istKnopf(b)) return istKnopf(a) - istKnopf(b);
const ra = a.getBoundingClientRect(), rb = b.getBoundingClientRect();
return ra.width * ra.height - rb.width * rb.height;
});
const teil = alle.filter((n) => (n.innerText || "").trim().toLowerCase().startsWith(wollen))
.sort((a, b) => {
const istKnopf = (n) => (n.tagName === 'BUTTON' ||
n.getAttribute('role') === 'button') ? 0 : 1;
if (istKnopf(a) !== istKnopf(b)) return istKnopf(a) - istKnopf(b);
const ra = a.getBoundingClientRect(), rb = b.getBoundingClientRect();
return ra.width * ra.height - rb.width * rb.height;
});
const ziel = genau[0] || teil[0];
if (!ziel) return "nichts gefunden fuer: " + wollen;
const r = ziel.getBoundingClientRect();
{ const maus = window.__pfKlick(ziel); if (maus) return maus; }
return "geklickt: " + (ziel.innerText || "").trim().replace(/\\s+/g, " ").slice(0, 50)
+ " [" + Math.round(r.width) + "x" + Math.round(r.height) + "]";
})()`;
const TEXTE = `(() => {
const knoten = [...document.querySelectorAll('button, a, [role="button"], span, div, th, td')]
.filter((n) => ${SICHTBAR} && n.children.length === 0);
const gesehen = new Set(); const aus = [];
for (const n of knoten) {
const t = (n.innerText || "").trim().replace(/\\s+/g, " ");
if (!t || t.length > 40 || gesehen.has(t)) continue;
gesehen.add(t); aus.push(t);
}
return aus.join(" | ");
})()`;
// Wie KLICK, aber der n-te Treffer (0-basiert, in Reihenfolge der Seite).
const KLICK_NTH = (text, n) => `(() => {
const wollen = ${JSON.stringify(text)}.trim().toLowerCase();
const treffer = [...document.querySelectorAll('button, a, [role="button"], span, div')]
.filter((k) => k.offsetParent !== null &&
(k.innerText || "").trim().toLowerCase() === wollen);
if (!treffer.length) return "nichts gefunden: " + wollen;
const ziel = treffer[Math.min(${Number(n) || 0}, treffer.length - 1)];
const r = ziel.getBoundingClientRect();
{ const maus = window.__pfKlick(ziel); if (maus) return maus; }
const zeile = (ziel.closest("tr, li, [class*=row], [class*=Row]") || ziel).innerText || "";
return "geklickt #" + ${Number(n) || 0} + " von " + treffer.length + ": "
+ zeile.replace(/\\s+/g, " ").slice(0, 60);
})()`;
// Klickt einen Knopf INNERHALB der Zeile, die einen Text enthält.
const KLICK_IN = (zeilenText, knopfText) => `(() => {
const zeile = ${JSON.stringify(zeilenText)}.trim().toLowerCase();
const knopf = ${JSON.stringify(knopfText)}.trim().toLowerCase();
const sichtbar = (n) => n.offsetParent !== null;
const flaeche = (n) => { const r = n.getBoundingClientRect(); return r.width * r.height; };
const treffer = [...document.querySelectorAll("*")]
.filter((n) => sichtbar(n) && (n.innerText || "").toLowerCase().includes(zeile))
.sort((a, b) => flaeche(a) - flaeche(b));
for (const z of treffer) {
const knoepfe = [...z.querySelectorAll('button, a, [role="button"], span, div')]
.filter((n) => sichtbar(n) && (n.innerText || "").trim().toLowerCase() === knopf)
.sort((a, b) => {
const istKnopf = (n) => (n.tagName === 'BUTTON' ||
n.getAttribute('role') === 'button') ? 0 : 1;
if (istKnopf(a) !== istKnopf(b)) return istKnopf(a) - istKnopf(b);
return flaeche(a) - flaeche(b);
});
if (!knoepfe.length) continue;
const ziel = knoepfe[0];
const r = ziel.getBoundingClientRect();
{ const maus = window.__pfKlick(ziel); if (maus) return maus; }
return "geklickt in Zeile '" + ${JSON.stringify(zeilenText)} + "': "
+ (ziel.innerText || "").trim().slice(0, 30);
}
return "kein Knopf '" + knopf + "' in der Zeile gefunden";
})()`;
async function main() {
const t = await seite();
if (!t) { console.log("keine Seite am Debug-Port"); process.exit(1); }
const ws = new WebSocket(t.webSocketDebuggerUrl);
await new Promise((ok, bad) => { ws.onopen = ok; ws.onerror = bad; });
let nr = 0; const wartend = new Map();
ws.onmessage = (e) => {
const m = JSON.parse(e.data);
if (m.id && wartend.has(m.id)) { wartend.get(m.id)(m); wartend.delete(m.id); }
};
const senden = (method, params = {}) => new Promise((res) => {
const i = ++nr; wartend.set(i, res); ws.send(JSON.stringify({ id: i, method, params }));
});
await senden("Runtime.enable");
const werten = async (expr) => {
const r = await senden("Runtime.evaluate",
{ expression: VORSPANN + "\n" + expr, returnByValue: true, awaitPromise: true });
if (r.result?.exceptionDetails) return "Fehler: " + JSON.stringify(r.result.exceptionDetails).slice(0, 300);
return r.result?.result?.value;
};
const klick = flag("--click");
if (klick) { console.log(await werten(KLICK(klick))); ws.close(); return; }
if (args.includes("--click-in")) {
const i = args.indexOf("--click-in");
console.log(await werten(KLICK_IN(args[i + 1], args[i + 2] || "Join")));
ws.close();
return;
}
if (args.includes("--click-nth")) {
const i = args.indexOf("--click-nth");
console.log(await werten(KLICK_NTH(args[i + 1], args[i + 2])));
ws.close();
return;
}
const js = args.includes("--eval") ? args[args.indexOf("--eval") + 1] : null;
if (js) { console.log(await werten(js)); ws.close(); return; }
console.log("Titel:", await werten("document.title"));
console.log("Adresse:", await werten("location.href"));
console.log("Texte:", await werten(TEXTE));
ws.close();
}
main().catch((e) => { console.error("Fehler:", e.message); process.exit(1); });