Instructions to use botezx/flagtldr with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Grok
How to use botezx/flagtldr with Grok:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download scripts/e2e/unreleased.mjs from botezx/flagtldr: direct link, hf CLI and curl.
- Browser
- Download file 10.5 kB
-
https://huggingface.co/botezx/flagtldr/resolve/main/scripts/e2e/unreleased.mjs
- Command line
-
hf download hf://botezx/flagtldr/scripts/e2e/unreleased.mjs
-
curl -L -o unreleased.mjs https://huggingface.co/botezx/flagtldr/resolve/main/scripts/e2e/unreleased.mjs
10.5 kB
| // unreleased (after 0.4.3) e2e on the mock: | |
| // 1) run timer in the progress overlay: live "m:ss", "oczekiwany czas: brak danych" with no history, | |
| // "oczekiwany czas ~m:ss" after successful runs; panel header "Gotowe w m:ss"; only durations stored; | |
| // options "Wyczyść statystyki czasu" clears them | |
| // 2) expanded OCENA / BRAKUJE render Grok's markdown (sub-headings, bold, nested lists, mention links), light + dark | |
| // screenshots docs/screenshots/unreleased-*.png | |
| // node unreleased.mjs <chrome> | |
| import puppeteer from "puppeteer-core"; | |
| import path from "node:path"; | |
| import { fileURLToPath } from "node:url"; | |
| import { setTimeout as sleep } from "node:timers/promises"; | |
| const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); | |
| const EXT = process.env.EXT_DIR || path.join(ROOT, "extension"); | |
| const SHOTS = path.join(ROOT, "docs", "screenshots"); | |
| const CHROME = process.env.CHROME || process.argv[2]; | |
| const log = (...a) => console.log("[unreleased-e2e]", ...a); | |
| const assert = (c, m) => { if (!c) throw new Error("ASSERT: " + m); }; | |
| const browser = await puppeteer.launch({ | |
| executablePath: CHROME, headless: true, | |
| args: [`--disable-extensions-except=${EXT}`, `--load-extension=${EXT}`, | |
| "--host-resolver-rules=MAP x.com 127.0.0.1:8443", "--ignore-certificate-errors", "--no-sandbox", "--window-size=1280,900", "--lang=pl"], | |
| defaultViewport: { width: 1280, height: 900 }, | |
| }); | |
| try { | |
| const sw = await browser.waitForTarget((t) => t.type() === "service_worker" && t.url().endsWith("service-worker.js"), { timeout: 15000 }); | |
| const extId = new URL(sw.url()).host; | |
| const opt = await browser.newPage(); | |
| await opt.goto(`chrome-extension://${extId}/src/options/options.html`); | |
| await opt.waitForFunction(() => document.getElementById("systemPrompt").value.length > 0); | |
| const set = (o) => opt.evaluate(async (oo) => { const { settings } = await chrome.storage.local.get("settings"); await chrome.storage.local.set({ settings: { ...settings, ...oo } }); }, o); | |
| const sw$ = (m) => opt.evaluate((mm) => chrome.runtime.sendMessage(mm), m); | |
| await set({ provider: "grok-auto", grokContext: "iframe", grokMode: "fast", geoEnabled: false, summaryExpandDetails: false }); | |
| await sw$({ type: "timingClear" }); | |
| const x = await browser.newPage(); | |
| const errors = []; x.on("pageerror", (e) => errors.push(String(e))); | |
| const overlay = () => x.evaluate(() => { const r = document.getElementById("xa-overlay-host")?.shadowRoot; if (!r) return null; | |
| return { el: r.querySelector(".tm .el").textContent, ex: r.querySelector(".tm .ex").textContent, over: r.querySelector(".tm").classList.contains("over"), fill: parseFloat(r.querySelector(".fill").style.width) }; }); | |
| async function run(url, id, flags = "", { during } = {}) { | |
| await x.goto(url, { waitUntil: "networkidle0" }); | |
| await x.evaluate((f) => localStorage.setItem("mockGrokFlags", f), flags); | |
| await x.waitForFunction((i) => [...document.querySelectorAll("article")].some((a) => a.querySelector(`a[href$="/status/${i}"]`) && a.querySelector(".xa-summary-btn")), { timeout: 15000 }, id); | |
| await x.evaluate((i) => [...document.querySelectorAll("article")].find((a) => a.querySelector(`a[href$="/status/${i}"]`)).querySelector(".xa-summary-btn").click(), id); | |
| await x.waitForFunction(() => document.getElementById("xa-overlay-host")?.shadowRoot.querySelector(".tm .ex"), { timeout: 10000 }); | |
| const seen = []; | |
| let ready = false; | |
| while (!ready) { | |
| const o = await overlay(); if (o) seen.push(o); | |
| if (during) await during(o, seen); | |
| ready = await x.evaluate(() => !!document.querySelector(".xa-result-host")?.shadowRoot.querySelector(".body[data-render]")); | |
| if (!ready) await sleep(300); | |
| assert(seen.length < 400, "timeout"); | |
| } | |
| await sleep(1200); | |
| const r = await x.evaluate(() => { const r = document.querySelector(".xa-result-host").shadowRoot, d = r.querySelector(".dur"); | |
| return { dur: d && !d.hidden ? d.textContent : null, meta: r.querySelector(".meta").textContent }; }); | |
| return { seen, ...r }; | |
| } | |
| const POST = "https://x.com/teza_autor/status/300?conv=branch"; | |
| // 1) first run: no history | |
| const r1 = await run(POST, "300", "slow=3000", { | |
| during: async (o, seen) => { if (o && seen.length === 6) await (await x.evaluateHandle(() => document.getElementById("xa-overlay-host").shadowRoot.querySelector(".sheet"))).screenshot({ path: path.join(SHOTS, "unreleased-progress-timer-first-run.png") }); }, | |
| }); | |
| const ex1 = [...new Set(r1.seen.map((o) => o.ex))]; | |
| log("run 1 overlay:", r1.seen.map((o) => o.el).filter((v, i, a) => a.indexOf(v) === i).join(" "), "|", ex1.join(" / "), "| panel:", r1.dur); | |
| assert(ex1.includes("oczekiwany czas: brak danych"), "no history -> brak danych"); | |
| assert(r1.seen.some((o) => /^0:0[1-9]$/.test(o.el)), "elapsed ticks"); | |
| assert(/^Gotowe w 0:\d\d$/.test(r1.dur || ""), "panel: Gotowe w"); | |
| assert(!/^Gotowe/.test(r1.meta), "meta line unchanged"); | |
| const fills = r1.seen.map((o) => o.fill); | |
| assert(fills.every((f, i) => !i || f >= fills[i - 1]), "bar never goes back: " + fills.join(",")); | |
| let t = await sw$({ type: "timingGet", mode: "fast", ctx: "iframe" }); | |
| assert(t.runs === 1 && t.estimate?.basis === "all" && t.estimate.n === 1, "one run recorded: " + JSON.stringify(t)); | |
| const raw = await opt.evaluate(() => chrome.storage.local.get("summaryTiming")); | |
| const keys = [...new Set(raw.summaryTiming.runs.flatMap((r) => Object.keys(r)))].sort().join(","); | |
| assert(keys === "at,ctx,mode,ms" && !/teza|status|@|http/i.test(JSON.stringify(raw)), "stats contain durations only: " + JSON.stringify(raw)); | |
| // 2) second run (+ screenshot mid-run with the expected time) | |
| const r2 = await run(POST, "300", "slow=3000", { | |
| during: async (o, seen) => { if (o && seen.length === 6) await (await x.evaluateHandle(() => document.getElementById("xa-overlay-host").shadowRoot.querySelector(".sheet"))).screenshot({ path: path.join(SHOTS, "unreleased-progress-timer.png") }); }, | |
| }); | |
| const ex2 = [...new Set(r2.seen.map((o) => o.ex))]; | |
| log("run 2 overlay:", ex2.join(" / "), "| fill", r2.seen.map((o) => Math.round(o.fill)).join(","), "| panel:", r2.dur); | |
| assert(ex2.some((e) => /^oczekiwany czas ~0:\d\d$/.test(e)), "estimate shown on run 2"); | |
| assert(r2.seen.every((o) => o.fill <= 95 || o === r2.seen.at(-1)), "capped at 95 % before done"); | |
| t = await sw$({ type: "timingGet", mode: "fast", ctx: "iframe" }); | |
| assert(t.runs === 2 && t.estimate.basis === "mode+ctx", "bucket mode+ctx after 2 runs: " + JSON.stringify(t)); | |
| // 3) "dłużej niż zwykle": a much slower run against the 2-run median | |
| const r3 = await run(POST, "300", "slow=16000"); | |
| log("run 3 (slow):", [...new Set(r3.seen.map((o) => o.ex))].join(" / ")); | |
| assert(r3.seen.some((o) => o.over && /^dłużej niż zwykle \(zwykle ~0:\d\d\)$/.test(o.ex)), "over-time label"); | |
| // 4) options: state text + clear button | |
| await opt.bringToFront(); await opt.reload(); await opt.waitForFunction(() => /przebieg/.test(document.getElementById("timingState")?.textContent || ""), { polling: 200 }); | |
| const st = await opt.evaluate(() => document.getElementById("timingState").textContent); | |
| log("options:", st); | |
| await opt.screenshot({ path: path.join(SHOTS, "unreleased-options-timing.png"), clip: await opt.evaluate(() => { const r = document.getElementById("timingClear").closest("section,fieldset,.card,div").getBoundingClientRect(); return { x: 0, y: Math.max(0, r.top + scrollY - 120), width: 900, height: Math.min(420, r.height + 240) }; }) }); | |
| await opt.evaluate(() => document.getElementById("timingClear").click()); | |
| await opt.waitForFunction(() => /brak/i.test(document.getElementById("timingState").textContent), { polling: 200 }); | |
| t = await sw$({ type: "timingGet", mode: "fast", ctx: "iframe" }); | |
| assert(t.runs === 0 && !t.estimate, "cleared"); | |
| await x.bringToFront(); | |
| // 5) expanded OCENA with Grok's formatting, light + dark | |
| for (const theme of ["light", "dark"]) { | |
| await run(`${POST}&virtual=1&theme=${theme}`, "300", "richocena"); // ?theme only applies to the X-like ?virtual layout (the plain mock is always dark) | |
| await x.evaluate(() => { const r = document.querySelector(".xa-result-host").shadowRoot; r.querySelectorAll("details.xs-more").forEach((d) => { d.open = d.dataset.section !== "noise"; }); }); | |
| const o = await x.evaluate(() => { const r = document.querySelector(".xa-result-host").shadowRoot, b = r.querySelector('details[data-section="assessment"] .xs-more-b'); | |
| const cs = (sel) => { const e = b.querySelector(sel); return e && getComputedStyle(e); }; | |
| return { heads: [...b.querySelectorAll("h3,h4,h5,h6")].map((h) => h.textContent), olItems: b.querySelector(":scope > ol")?.children.length, | |
| nested: b.querySelectorAll("ol > li > ul > li").length, strong: b.querySelectorAll("strong").length, | |
| mentions: [...b.querySelectorAll("a.mention")].map((a) => a.href), raw: /\*\*|###/.test(b.innerHTML), | |
| olPad: cs("ol")?.paddingLeft, pMargin: cs("p ~ p")?.marginTop, color: cs("p")?.color, h: cs("h5,h6,h4")?.fontSize, | |
| missing: r.querySelectorAll('details[data-section="missing"] li').length }; }); | |
| log(theme, "OCENA:", JSON.stringify(o)); | |
| assert(o.heads.includes("Siła argumentów") && o.heads.includes("Wniosek"), "sub-headings inside OCENA"); | |
| assert(o.olItems === 3 && o.nested === 2 && o.strong >= 5 && !o.raw, "lists / bold rendered"); | |
| assert(o.mentions.includes("https://x.com/ekonomistka") && o.mentions.includes("https://x.com/ekonom_pl"), "mentions -> profiles"); | |
| assert(o.olPad === "20px" && o.pMargin === "5px" && o.h === "13px", "styled"); | |
| assert(o.missing === 3, "BRAKUJE list"); | |
| assert(theme === "light" ? o.color === "rgb(15, 20, 25)" : o.color === "rgb(231, 233, 234)", "theme text colour: " + o.color); | |
| await x.evaluate(() => { const r = document.querySelector(".xa-result-host").shadowRoot; r.querySelector('details[data-section="assessment"]').scrollIntoView({ block: "start" }); }); | |
| await sleep(300); | |
| await (await x.$(".xa-result-host")).screenshot({ path: path.join(SHOTS, `unreleased-ocena-expanded-${theme}.png`) }); | |
| await set({}); | |
| } | |
| log("screenshots: unreleased-progress-timer(-first-run).png, unreleased-options-timing.png, unreleased-ocena-expanded-{light,dark}.png"); | |
| await x.evaluate(() => localStorage.setItem("mockGrokFlags", "")); | |
| assert(errors.length === 0, "page errors: " + errors.join("; ")); | |
| log("OK"); | |
| } finally { await browser.close(); } | |