-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscreenshot.js
More file actions
182 lines (153 loc) · 5.94 KB
/
screenshot.js
File metadata and controls
182 lines (153 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
const { chromium } = require('playwright');
const path = require('path');
const fs = require('fs');
const screenshotDir = '/Users/maxwatermolen/source/skyspy/docs/screenshots';
async function recordView(name, setupFn, actionFn, durationMs = 5000) {
console.log(`Recording: ${name}...`);
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({
viewport: { width: 1400, height: 900 },
recordVideo: {
dir: screenshotDir,
size: { width: 1400, height: 900 }
}
});
const page = await context.newPage();
try {
await page.goto('http://localhost:3000', { waitUntil: 'networkidle', timeout: 60000 });
await page.waitForTimeout(3000);
if (setupFn) await setupFn(page);
if (actionFn) await actionFn(page);
await page.waitForTimeout(durationMs);
} catch (e) {
console.log(`Error in ${name}:`, e.message);
}
await page.close();
const video = page.video();
if (video) {
const videoPath = await video.path();
const newPath = path.join(screenshotDir, `${name}.webm`);
fs.renameSync(videoPath, newPath);
console.log(`Saved: ${newPath}`);
}
await context.close();
await browser.close();
}
async function enableAllLayers(page) {
await page.click('button:has(.lucide-layers)');
await page.waitForTimeout(500);
const checkboxes = await page.locator('.overlay-menu input[type="checkbox"]').all();
for (const cb of checkboxes) {
if (!(await cb.isChecked())) {
await cb.click();
await page.waitForTimeout(100);
}
}
await page.waitForTimeout(300);
await page.keyboard.press('Escape');
await page.waitForTimeout(500);
}
async function clickCanvasAt(page, xPercent, yPercent) {
const canvas = await page.locator('canvas').first();
const box = await canvas.boundingBox();
if (box) {
await page.mouse.click(box.x + box.width * xPercent, box.y + box.height * yPercent);
await page.waitForTimeout(1500);
}
}
async function main() {
console.log('Recording screenshots...\n');
// 1. Map view with all layers
await recordView('map-view', enableAllLayers, null, 6000);
// 2. Aircraft detail - click near center where planes cluster
await recordView('aircraft-detail', enableAllLayers, async (page) => {
// Try multiple positions to find an aircraft
await clickCanvasAt(page, 0.5, 0.55);
// If no panel appeared, try another spot
const panel = await page.locator('.target-details, .aircraft-popup').first();
if (!(await panel.isVisible({ timeout: 1000 }).catch(() => false))) {
await clickCanvasAt(page, 0.45, 0.5);
}
}, 6000);
// 3. Safety banner
await recordView('safety-banner', enableAllLayers, null, 5000);
// 4. PIREP popup - PIREPs appear as diamonds, click around map edges
await recordView('pirep-popup', enableAllLayers, async (page) => {
// PIREPs are weather reports, often in various locations
// Try several clicks to find one
await clickCanvasAt(page, 0.25, 0.3);
let popup = await page.locator('.pirep-popup').first();
if (!(await popup.isVisible({ timeout: 500 }).catch(() => false))) {
await clickCanvasAt(page, 0.7, 0.35);
}
if (!(await popup.isVisible({ timeout: 500 }).catch(() => false))) {
await clickCanvasAt(page, 0.4, 0.25);
}
if (!(await popup.isVisible({ timeout: 500 }).catch(() => false))) {
await clickCanvasAt(page, 0.6, 0.65);
}
}, 5000);
// 5. NavAid popup - NavAids are typically at fixed positions
await recordView('navaid-popup', enableAllLayers, async (page) => {
// Try clicking at various positions to find a navaid
await clickCanvasAt(page, 0.15, 0.5);
let popup = await page.locator('.navaid-popup').first();
if (!(await popup.isVisible({ timeout: 500 }).catch(() => false))) {
await clickCanvasAt(page, 0.8, 0.4);
}
if (!(await popup.isVisible({ timeout: 500 }).catch(() => false))) {
await clickCanvasAt(page, 0.3, 0.7);
}
if (!(await popup.isVisible({ timeout: 500 }).catch(() => false))) {
await clickCanvasAt(page, 0.65, 0.6);
}
}, 5000);
// 6. Stats view
await recordView('stats-view', null, async (page) => {
await page.click('button:has-text("Statistics")');
}, 5000);
// 7. History view
await recordView('history-view', null, async (page) => {
await page.click('button:has-text("History")');
}, 5000);
// 8. Alerts view
await recordView('alerts-view', null, async (page) => {
await page.click('button:has-text("Alerts")');
}, 5000);
// 9. CRT Mode
await recordView('crt-mode', async (page) => {
await page.click('button:has(.lucide-settings)');
await page.waitForTimeout(500);
await page.selectOption('select', 'crt');
await page.click('button.btn-primary');
await page.waitForTimeout(1000);
}, null, 6000);
// 10. Settings
await recordView('settings', null, async (page) => {
await page.click('button:has(.lucide-settings)');
}, 4000);
console.log('\nConverting to GIF...');
// Convert WebM to GIF
const { execSync } = require('child_process');
const files = ['map-view', 'aircraft-detail', 'safety-banner', 'crt-mode', 'alerts-view', 'settings'];
const staticFiles = ['pirep-popup', 'navaid-popup', 'stats-view', 'history-view'];
for (const f of files) {
try {
console.log(`Converting ${f} to GIF...`);
execSync(`ffmpeg -y -i "${screenshotDir}/${f}.webm" -vf "fps=10,scale=800:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 "${screenshotDir}/${f}.gif"`, { stdio: 'pipe' });
} catch (e) {
console.log(`Error converting ${f}:`, e.message);
}
}
// Static screenshots (PNG) for these
for (const f of staticFiles) {
try {
console.log(`Converting ${f} to PNG...`);
execSync(`ffmpeg -y -i "${screenshotDir}/${f}.webm" -frames:v 1 "${screenshotDir}/${f}.png"`, { stdio: 'pipe' });
} catch (e) {
console.log(`Error converting ${f}:`, e.message);
}
}
console.log('\nAll done!');
}
main().catch(console.error);