-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathindex.html
More file actions
150 lines (135 loc) · 4.61 KB
/
index.html
File metadata and controls
150 lines (135 loc) · 4.61 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Demo Time Screenshot API Test</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background: #1a1a1a;
color: #ffffff;
}
.container {
background: #2a2a2a;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}
button {
background: #007acc;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
margin: 10px 0;
}
button:hover {
background: #005aa3;
}
button:disabled {
background: #666;
cursor: not-allowed;
}
img {
max-width: 100%;
border-radius: 4px;
margin-top: 20px;
box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}
.status {
margin: 10px 0;
padding: 10px;
border-radius: 4px;
}
.status.loading {
background: #333;
color: #ffff00;
}
.status.success {
background: #1a4d1a;
color: #90ee90;
}
.status.error {
background: #4d1a1a;
color: #ff6b6b;
}
.info {
background: #333;
padding: 15px;
border-radius: 4px;
margin-bottom: 20px;
}
.info h2 {
margin-top: 0;
color: #007acc;
}
</style>
</head>
<body>
<div class="container">
<div class="info">
<h2>Demo Time Screenshot API Test</h2>
<p>This page tests the <code>http://localhost:3710/api/screenshot</code> API endpoint.</p>
<p>The API should return a base64-encoded image of the current Demo Time state.</p>
</div>
<button id="captureBtn" onclick="captureScreenshot()">Capture Screenshot</button>
<div id="status" class="status" style="display: none;"></div>
<div id="imageContainer" style="display: none;">
<h3>Screenshot Result:</h3>
<img id="screenshotImg" alt="Demo Time Screenshot" />
</div>
</div>
<script>
async function captureScreenshot() {
const button = document.getElementById('captureBtn');
const status = document.getElementById('status');
const imageContainer = document.getElementById('imageContainer');
const img = document.getElementById('screenshotImg');
// Disable button and show loading
button.disabled = true;
button.textContent = 'Capturing...';
status.style.display = 'block';
status.className = 'status loading';
status.textContent = 'Capturing screenshot...';
imageContainer.style.display = 'none';
try {
const response = await fetch('http://localhost:3710/api/screenshot');
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const base64Data = await response.text();
// Set the image source with the base64 data
img.src = base64Data;
// Show success status
status.className = 'status success';
status.textContent = 'Screenshot captured successfully!';
imageContainer.style.display = 'block';
} catch (error) {
console.error('Screenshot capture failed:', error);
status.className = 'status error';
status.textContent = `Error: ${error.message}`;
} finally {
// Re-enable button
button.disabled = false;
button.textContent = 'Capture Screenshot';
}
}
// Auto-hide status after 5 seconds on success
document.addEventListener('click', function(e) {
if (e.target.id === 'captureBtn') return;
const status = document.getElementById('status');
if (status.classList.contains('success')) {
setTimeout(() => {
status.style.display = 'none';
}, 5000);
}
});
</script>
</body>
</html>