oxedyne/daimond/dev/shot_railbound.mjs
2.1 KiB, 1 run
created by r2519314175:185, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | // shot_railbound.mjs — the Admin drawer, bounded. The rail with the drawer open |
| 2 | // at three window heights, for the eye: the drawer's own head is on screen and |
| 3 | // the rail's head is above it, at every one. |
| 4 | import { open } from './harness.mjs'; |
| 5 | import { writeFileSync, mkdirSync } from 'node:fs'; |
| 6 | const sleep = ms => new Promise(r => setTimeout(r, ms)); |
| 7 | mkdirSync('shots', { recursive: true }); |
| 8 | const s = await open({ signIn: true, connect: true, name: 'railbound' }); |
| 9 | const { page: p } = s; |
| 10 | await p.route('**/*.{woff,woff2,ttf,otf}', r => r.abort()); |
| 11 | await p.evaluate(() => { try { window.DaimondAdmin.closeModal(); } catch (e) {} const m = document.getElementById('settings-modal'); if (m) m.style.display = 'none'; }); |
| 12 | await p.addStyleTag({ content: '*,*::before,*::after{transition:none!important;animation:none!important}' }); |
| 13 | const cdp = await s.browser.newCDPSession(p); |
| 14 | const shot = async (name, sel, scale = 1.5) => { |
| 15 | try { |
| 16 | const clip = await p.evaluate((q) => { |
| 17 | const e = document.querySelector(q); if (!e) return null; |
| 18 | const r = e.getBoundingClientRect(); |
| 19 | return { x: Math.max(0, Math.round(r.x) - 4), y: Math.max(0, Math.round(r.y) - 4), width: Math.round(r.width) + 8, height: Math.round(r.height) + 8 }; |
| 20 | }, sel); |
| 21 | if (!clip) return; |
| 22 | const { data } = await cdp.send('Page.captureScreenshot', { format: 'png', clip: { ...clip, scale } }); |
| 23 | writeFileSync('shots/' + name + '.png', Buffer.from(data, 'base64')); |
| 24 | console.log('shot shots/' + name + '.png'); |
| 25 | } catch (e) { console.log('SKIP ' + name + ' — ' + e.message.split('\n')[0]); } |
| 26 | }; |
| 27 | for (const vh of [700, 900, 1100]) { |
| 28 | await p.setViewportSize({ width: 1440, height: vh }); |
| 29 | await sleep(500); |
| 30 | await p.evaluate(() => { const b = document.getElementById('settings-btn'); if (b && !document.getElementById('admin').classList.contains('admin-open')) b.click(); }); |
| 31 | await sleep(500); |
| 32 | await shot('railbound-' + vh, '.panel.rail'); |
| 33 | await p.evaluate(() => { try { DaimondAdmin.close(); } catch (e) {} }); |
| 34 | await sleep(250); |
| 35 | } |
| 36 | await p.setViewportSize({ width: 1440, height: 900 }); |
| 37 | await sleep(500); |
| 38 | await shot('railbound-strip', '#admin-status', 3); |
| 39 | await s.close(); |
| 40 | console.log('done'); |