From 8590ab055611f9a9af8ed415c3f6f5cbbd609f40 Mon Sep 17 00:00:00 2001 From: aedes Date: Wed, 22 Apr 2026 02:53:58 +0300 Subject: [PATCH] feat: chat in gap between Q1 and Q2, output directly under input --- scripts/mirror.js | 106 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 13 deletions(-) diff --git a/scripts/mirror.js b/scripts/mirror.js index f217857..ea682cf 100644 --- a/scripts/mirror.js +++ b/scripts/mirror.js @@ -121,37 +121,117 @@ async function main() { console.log(`[mirror] networkidle reached. extra settle…`); await page.waitForTimeout(4000); - // Pixel-perfect full-page screenshot + // Measure question block positions (document coords, CSS pixels) + const quePositions = await page.$$eval('.que', els => + els.map(el => { + const r = el.getBoundingClientRect(); + return { top: r.top + window.scrollY, bottom: r.top + window.scrollY + r.height }; + }) + ); + const pageHeight = await page.evaluate(() => document.documentElement.scrollHeight); + const pageWidth = await page.evaluate(() => document.documentElement.scrollWidth); + console.log(`[mirror] page ${pageWidth}x${pageHeight} CSS px | questions:`, quePositions); + fs.mkdirSync(OUT, { recursive: true }); const pngPath = path.join(OUT, 'page.png'); await page.screenshot({ path: pngPath, fullPage: true, type: 'png' }); - const pngSize = fs.statSync(pngPath).size; - console.log(`[mirror] screenshot: ${pngPath} (${pngSize} bytes)`); + console.log(`[mirror] screenshot: ${pngPath} (${fs.statSync(pngPath).size} bytes)`); - // Compute actual page width for the wrapper (so image scales to its captured size) - const pageWidth = await page.evaluate(() => document.documentElement.scrollWidth); + // Decide gap position — mid-point between question 1 and question 2 + let chatTop = Math.round(pageHeight / 3); + if (quePositions.length >= 2) { + chatTop = Math.round((quePositions[0].bottom + quePositions[1].top) / 2 - 30); + } + + const pageTitle = (await page.title()).replace(/[<>]/g, ''); const wrapperHtml = ` -${await page.title()} +${pageTitle} -
-${CHAT_OVERLAY} +
+ +
+ +
+
+
+ `; fs.writeFileSync(path.join(OUT, 'index.html'), wrapperHtml, 'utf8'); - console.log(`[mirror] wrote ${path.join(OUT, 'index.html')}`); + console.log(`[mirror] wrote ${path.join(OUT, 'index.html')} — chat at y=${chatTop}px`); await browser.close(); console.log('[mirror] done');