d-11 mit Nutzertext (Canvas, Zeichenabfang und künstliche Uhr), Image-Label cb.hash mit Veraltet-Prüfung, lokaler Webserver und Im Browser öffnen
All checks were successful
release / deb (push) Successful in 4m2s
release / arch (push) Successful in 5m37s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 15:15:12 +01:00
parent af07911d22
commit f44ba7681c
18 changed files with 1220 additions and 147 deletions

View File

@ -16,6 +16,70 @@ OUT = "/checks/out"
PAGE = "/work/index.html"
ALLOWED_SCHEMES = ("file:", "data:", "blob:", "about:")
# Fängt Zeichenaufrufe auf Canvas ab (Kreise, Texte), damit man Positionen aus dem Bild nicht raten muss.
# `window.__cb.div` > 1 lässt nur jedes n-te Animationsbild an die Seite durch (geringere Bildrate).
CANVAS_HOOK = r"""
(() => {
const S = (window.__cb = { frame: 0, arcs: [], rings: [], texts: [], div: 1, k: 0 });
const P = CanvasRenderingContext2D.prototype;
const ids = new WeakMap();
// Index unter den Canvas-Elementen der Seite. Canvas ohne Platz im Dokument (Zwischenpuffer) ergibt -1.
const cidx = (c) => [...document.querySelectorAll('canvas')].indexOf(c);
const T = (ctx, x, y) => { const m = ctx.getTransform(); return [m.a * x + m.c * y + m.e, m.b * x + m.d * y + m.f]; };
const K = (ctx) => { const m = ctx.getTransform(); return Math.sqrt(Math.abs(m.a * m.d - m.b * m.c)); };
let pending = [];
const keep = () => { S.arcs = S.arcs.filter((a) => a.f >= S.frame - 2); };
const nextFrame = () => { S.frame++; keep(); };
const rec = (ctx, x, y, r, full) => {
const [X, Y] = T(ctx, x, y);
const e = { f: S.frame, x: X, y: Y, r: r * K(ctx), c: cidx(ctx.canvas), cw: ctx.canvas.width, ch: ctx.canvas.height, full };
S.arcs.push(e); pending.push(e);
};
const bp = P.beginPath; P.beginPath = function () { pending = []; return bp.apply(this, arguments); };
const oarc = P.arc;
P.arc = function (x, y, r, a0, a1) {
try { rec(this, x, y, r, Math.abs((a1 || 0) - (a0 || 0)) >= 2 * Math.PI - 0.02); } catch (e) {}
return oarc.apply(this, arguments);
};
const oell = P.ellipse;
P.ellipse = function (x, y, rx, ry, rot, a0, a1) {
try { rec(this, x, y, (rx + ry) / 2, Math.abs((a1 || 0) - (a0 || 0)) >= 2 * Math.PI - 0.02); } catch (e) {}
return oell.apply(this, arguments);
};
const ofill = P.fill;
P.fill = function () { try { for (const e of pending) { e.filled = true; e.fillStyle = String(this.fillStyle); } } catch (e) {} return ofill.apply(this, arguments); };
const ostroke = P.stroke;
P.stroke = function () {
try {
for (const e of pending) {
e.stroked = true;
if (e.full && e.r > 15) {
const key = Math.round(e.x) + "," + Math.round(e.y) + "," + Math.round(e.r * 2) / 2;
if (!S.rings.some((q) => q.key === key)) S.rings.push({ key, x: e.x, y: e.y, r: e.r, c: e.c });
}
}
} catch (e) {}
return ostroke.apply(this, arguments);
};
for (const name of ["fillText", "strokeText"]) {
const o = P[name];
P[name] = function (text) { try { S.texts.push(String(text)); if (S.texts.length > 400) S.texts.shift(); } catch (e) {} return o.apply(this, arguments); };
}
const full = (ctx, w, h) => w >= ctx.canvas.width * 0.9 && h >= ctx.canvas.height * 0.9;
const ocr = P.clearRect; P.clearRect = function (x, y, w, h) { try { if (full(this, w, h)) nextFrame(); } catch (e) {} return ocr.apply(this, arguments); };
const ofr = P.fillRect; P.fillRect = function (x, y, w, h) { try { if (full(this, w, h)) nextFrame(); } catch (e) {} return ofr.apply(this, arguments); };
const raf = window.requestAnimationFrame.bind(window);
window.requestAnimationFrame = (cb) => {
const wrapped = (t) => {
if (S.div > 1 && (S.k++ % S.div) !== 0) { raf(wrapped); return; }
nextFrame();
cb(t);
};
return raf(wrapped);
};
})();
"""
class Checklist:
"""Sammelt Prüfpunkte mit Gewicht. Der Score ist der Anteil der bestandenen Gewichte."""
@ -56,8 +120,9 @@ class Checklist:
class Session:
"""Chromium mit der Seite des Modells. Netzwerk- und Konsolenfehler werden mitgeschrieben."""
def __init__(self, path=PAGE, width=1280, height=800):
def __init__(self, path=PAGE, width=1280, height=800, clock=False):
self.path = path
self.use_clock = clock
self.size = {"width": width, "height": height}
self.errors = []
self.blocked = []
@ -72,6 +137,10 @@ class Session:
self.context.set_default_navigation_timeout(15000)
self.context.route("**/*", self._route)
self.page = self.context.new_page()
if self.use_clock:
# Zuerst die Uhr, dann der Hook: Er umhüllt die Animationsschleife der Uhr.
self.page.clock.install(time=0)
self.page.add_init_script(CANVAS_HOOK)
self.page.on("pageerror", lambda e: self.errors.append(f"pageerror: {e}"))
self.page.on(
"console", lambda m: self.errors.append(f"console: {m.text}") if m.type == "error" else None
@ -113,6 +182,10 @@ class Session:
return None
return (box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
def tick(self, ms):
"""Lässt `ms` Millisekunden der Seitenzeit vergehen (nur mit clock=True), in Schritten von 16 ms."""
self.page.clock.run_for(int(ms))
def wait(self, seconds):
self.page.wait_for_timeout(int(seconds * 1000))