Something went wrong. Try again.
this post sux
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071/* BiDi probe #8 — dump the structure of one real feed item to design DOM text extraction. */const ws = new WebSocket("ws://localhost:9222/session");let seq = 0;const pending = new Map();const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
function send(method, params = {}, sessionId = null, timeoutMs = 25000) { const id = ++seq; const msg = { id, method, params }; if (sessionId) msg.sessionId = sessionId; ws.send(JSON.stringify(msg)); return new Promise((resolve, reject) => { const t = setTimeout(() => { pending.delete(id); reject(new Error("timeout " + method)); }, timeoutMs); pending.set(id, { resolve, reject, t }); });}await new Promise((res, rej) => { ws.onopen = res; ws.onerror = () => rej(new Error("no ws")); });ws.onmessage = (ev) => { const m = JSON.parse(ev.data); if (m.id && pending.has(m.id)) { const p = pending.get(m.id); pending.delete(m.id); clearTimeout(p.t); m.type === "success" ? p.resolve(m.result) : p.reject(new Error(JSON.stringify(m.error))); }};
const { sessionId } = await send("session.new", { capabilities: {} });const tree = await send("browsingContext.getTree", {}, sessionId);const ctx = tree.contexts.find((c) => (c.url || "").includes("bsky.app"));async function val(expression) { const r = await send("script.evaluate", { expression, target: { context: ctx.context }, awaitPromise: true, resultOwnership: "none" }, sessionId); if (!r || !r.result) return "NO-RESULT"; return "value" in r.result ? String(r.result.value) : JSON.stringify(r.result);}
console.log(await val(`(() => { const norm = (href) => { if (!href) return null; const h = href.replace(/^https?:\\/\\/[^/]+/i, "").split("?")[0].split("#")[0]; return h.match(/^\\/profile\\/[^/]+\\/post\\/[^/]+\\/?$/) ? h : null; }; const itemContainer = (anchor) => { let node = anchor.parentElement; for (let depth = 0; node && node !== document.body && depth < 12; depth++) { const parent = node.parentElement; if (parent) { const sib = parent.querySelectorAll('a[href*="/post/"]'); for (let i = 0; i < sib.length; i++) if (!node.contains(sib[i])) return node; } node = parent; } return anchor.parentElement; }; const anchor = Array.from(document.querySelectorAll('a[href*="/post/"]')).find((a) => norm(a.getAttribute("href"))); if (!anchor) return "no anchor"; const item = itemContainer(anchor); const pCount = item.querySelectorAll("p").length; const wordBreak = item.querySelectorAll("[data-word-break]").length; const imgs = Array.from(item.querySelectorAll("img")).map((i) => (i.alt || "").slice(0, 40)); // find the largest text-bearing block that is not the action bar const text = (item.innerText || "").slice(0, 400); return JSON.stringify({ itemClass: String(item.className).slice(0, 60), pCount, wordBreak, imgs: imgs.slice(0, 3), pSamples: Array.from(item.querySelectorAll("p")).slice(0, 2).map((p) => p.innerText.slice(0, 120)), textPreview: text, }, null, 1);})()`));try { await send("session.end", {}, sessionId, 5000); } catch {}ws.close();process.exit(0);