-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexperimental.html
More file actions
419 lines (390 loc) · 16.9 KB
/
experimental.html
File metadata and controls
419 lines (390 loc) · 16.9 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World - Experimental</title>
<style>
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.container {
text-align: center;
color: white;
padding: 2rem;
max-width: 800px;
}
h1 {
font-size: 3rem;
margin: 0;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
p {
font-size: 1.2rem;
margin-top: 1rem;
opacity: 0.9;
}
.controls {
margin-top: 1rem;
display: flex;
gap: 1rem;
justify-content: center;
}
button {
background: rgba(255, 255, 255, 0.2);
color: white;
border: 2px solid rgba(255, 255, 255, 0.3);
padding: 0.5rem 1.5rem;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
font-weight: bold;
transition: all 0.3s;
}
button:hover {
background: rgba(255, 255, 255, 0.3);
border-color: rgba(255, 255, 255, 0.5);
}
button:active {
transform: scale(0.95);
}
#components {
margin-top: 2rem;
background: rgba(255, 255, 255, 0.1);
padding: 1.5rem;
border-radius: 10px;
backdrop-filter: blur(10px);
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
font-family: 'Courier New', monospace;
font-size: 0.9rem;
}
th {
background: rgba(255, 255, 255, 0.2);
padding: 0.75rem;
text-align: left;
font-weight: bold;
color: #ffd700;
border-bottom: 2px solid rgba(255, 255, 255, 0.3);
}
td {
padding: 0.75rem;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
word-break: break-all;
}
tr:hover {
background: rgba(255, 255, 255, 0.05);
}
.status {
text-align: center;
font-size: 1.2rem;
}
.match {
color: #00ff00;
}
.no-match {
color: #ff0000;
}
.loading {
font-style: italic;
opacity: 0.7;
}
.details-row {
background: rgba(255, 255, 255, 0.15);
}
.details-cell {
padding: 1rem;
}
.details-content {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
}
.details-section {
background: rgba(0, 0, 0, 0.2);
padding: 0.75rem;
border-radius: 5px;
}
.details-section h4 {
margin: 0 0 0.5rem 0;
color: #ffd700;
font-size: 0.9rem;
}
.details-section pre {
margin: 0;
font-size: 0.75rem;
max-height: 300px;
overflow-y: auto;
white-space: pre-wrap;
word-break: break-all;
}
.copy-details-btn {
background: rgba(255, 215, 0, 0.3);
color: white;
border: 1px solid rgba(255, 215, 0, 0.5);
padding: 0.3rem 0.6rem;
border-radius: 3px;
cursor: pointer;
font-size: 0.75rem;
margin-top: 0.5rem;
}
.copy-details-btn:hover {
background: rgba(255, 215, 0, 0.5);
}
.toggle-details {
cursor: pointer;
color: #ffd700;
text-decoration: underline;
font-size: 0.85rem;
margin-left: 0.5rem;
}
</style>
<script src="thumbmark.umd.js"></script>
</head>
<body>
<div class="container">
<h1>Thumbmark Experimental</h1>
<p>Experimental Components Hash Values</p>
<div class="controls">
<button id="copyBtn">Copy to Clipboard</button>
<button id="pasteBtn">Paste from Clipboard</button>
</div>
<div id="components">
<div class="loading">Loading experimental components...</div>
</div>
</div>
<div style="position: absolute; left: -9999px; top: 0;">
<iframe id="testIframe" src="about:blank" style="width: 300px; height: 300px; border: none;"></iframe>
</div>
<script>
// Initialize Thumbmark
const thumbmark = new ThumbmarkJS.Thumbmark({experimental: true, performance: true});
// Get the experimental components
thumbmark.get().then(result => {
const componentsDiv = document.getElementById('components');
componentsDiv.innerHTML = '';
// Get previous values from sessionStorage
const previousData = sessionStorage.getItem('thumbmark_experimental');
const previous = previousData ? JSON.parse(previousData) : null;
// Get clipboard values from sessionStorage
const clipboardData = sessionStorage.getItem('thumbmark_clipboard');
const clipboard = clipboardData ? JSON.parse(clipboardData) : null;
// Display as a comparison table
if (result.experimental) {
// Create table
const table = document.createElement('table');
// Create header
const thead = document.createElement('thead');
thead.innerHTML = `
<tr>
<th>Component</th>
<th>Main Window Hash</th>
<th>Time</th>
<th>IFrame Hash</th>
<th>Match</th>
<th>Previous Hash</th>
<th>Match</th>
<th>Clipboard Hash</th>
<th>Match</th>
</tr>
`;
table.appendChild(thead);
// Get iframe data from sessionStorage
const iframeData = sessionStorage.getItem('thumbmark_iframe');
const iframe = iframeData ? JSON.parse(iframeData) : null;
console.log('Retrieved iframe data from sessionStorage:', iframe);
// Create body
const tbody = document.createElement('tbody');
for (const [componentName, componentData] of Object.entries(result.experimental)) {
const currentHash = componentData.hash;
const timing = result.elapsed && result.elapsed[componentName] ? `${Math.round(result.elapsed[componentName])}ms` : 'N/A';
const iframeHash = (iframe && iframe[componentName] && iframe[componentName].hash) ? iframe[componentName].hash : 'N/A';
console.log(`Component: ${componentName}, iframe data:`, iframe?.[componentName], 'hash:', iframeHash);
const previousHash = previous && previous[componentName] ? previous[componentName].hash : 'N/A';
const clipboardHash = clipboard && clipboard[componentName] ? clipboard[componentName].hash : 'N/A';
// Compare with iframe
let iframeStatusIcon = '';
let iframeStatusClass = '';
if (iframeHash === 'N/A') {
iframeStatusIcon = '-';
iframeStatusClass = '';
} else if (currentHash === iframeHash) {
iframeStatusIcon = '✓';
iframeStatusClass = 'match';
} else {
iframeStatusIcon = '✗';
iframeStatusClass = 'no-match';
}
// Compare with previous
let prevStatusIcon = '';
let prevStatusClass = '';
if (previousHash === 'N/A') {
prevStatusIcon = '-';
prevStatusClass = '';
} else if (currentHash === previousHash) {
prevStatusIcon = '✓';
prevStatusClass = 'match';
} else {
prevStatusIcon = '✗';
prevStatusClass = 'no-match';
}
// Compare with clipboard
let clipStatusIcon = '';
let clipStatusClass = '';
if (clipboardHash === 'N/A') {
clipStatusIcon = '-';
clipStatusClass = '';
} else if (currentHash === clipboardHash) {
clipStatusIcon = '✓';
clipStatusClass = 'match';
} else {
clipStatusIcon = '✗';
clipStatusClass = 'no-match';
}
const row = document.createElement('tr');
row.innerHTML = `
<td><strong>${componentName}</strong><span class="toggle-details" data-component="${componentName}">show details</span></td>
<td>${currentHash}</td>
<td>${timing}</td>
<td>${iframeHash}</td>
<td class="status ${iframeStatusClass}">${iframeStatusIcon}</td>
<td>${previousHash}</td>
<td class="status ${prevStatusClass}">${prevStatusIcon}</td>
<td>${clipboardHash}</td>
<td class="status ${clipStatusClass}">${clipStatusIcon}</td>
`;
tbody.appendChild(row);
// Create details row (hidden by default)
const detailsRow = document.createElement('tr');
detailsRow.className = 'details-row';
detailsRow.style.display = 'none';
detailsRow.dataset.component = componentName;
const mainDetails = componentData.details || {};
const iframeDetails = (iframe && iframe[componentName] && iframe[componentName].details) ? iframe[componentName].details : null;
detailsRow.innerHTML = `
<td colspan="9" class="details-cell">
<div class="details-content">
<div class="details-section">
<h4>Main Window Details</h4>
<pre>${JSON.stringify(mainDetails, null, 2)}</pre>
<button class="copy-details-btn" data-details='${JSON.stringify(mainDetails)}'>Copy Main Details</button>
</div>
<div class="details-section">
<h4>IFrame Details</h4>
<pre>${iframeDetails ? JSON.stringify(iframeDetails, null, 2) : 'N/A'}</pre>
${iframeDetails ? `<button class="copy-details-btn" data-details='${JSON.stringify(iframeDetails)}'>Copy IFrame Details</button>` : ''}
</div>
</div>
</td>
`;
tbody.appendChild(detailsRow);
}
table.appendChild(tbody);
componentsDiv.appendChild(table);
// Add event listeners for toggle details
document.querySelectorAll('.toggle-details').forEach(toggle => {
toggle.addEventListener('click', function() {
const componentName = this.dataset.component;
const detailsRow = document.querySelector(`tr.details-row[data-component="${componentName}"]`);
if (detailsRow.style.display === 'none') {
detailsRow.style.display = 'table-row';
this.textContent = 'hide details';
} else {
detailsRow.style.display = 'none';
this.textContent = 'show details';
}
});
});
// Add event listeners for copy details buttons
document.querySelectorAll('.copy-details-btn').forEach(btn => {
btn.addEventListener('click', async function() {
const details = this.dataset.details;
try {
await navigator.clipboard.writeText(details);
const originalText = this.textContent;
this.textContent = 'Copied!';
setTimeout(() => {
this.textContent = originalText;
}, 2000);
} catch (err) {
alert('Failed to copy: ' + err.message);
}
});
});
// Store current values in sessionStorage for next page load
sessionStorage.setItem('thumbmark_experimental', JSON.stringify(result.experimental));
// Store current data for clipboard functionality
window.currentExperimentalData = result.experimental;
} else {
componentsDiv.innerHTML = '<div class="loading">No experimental components found</div>';
}
}).catch(error => {
const componentsDiv = document.getElementById('components');
componentsDiv.innerHTML = `<div class="loading">Error: ${error.message}</div>`;
});
// Copy to clipboard functionality
document.getElementById('copyBtn').addEventListener('click', async () => {
if (window.currentExperimentalData) {
try {
await navigator.clipboard.writeText(JSON.stringify(window.currentExperimentalData));
alert('Experimental data copied to clipboard!');
} catch (err) {
alert('Failed to copy to clipboard: ' + err.message);
}
} else {
alert('No data available to copy yet. Please wait for the page to load.');
}
});
// Paste from clipboard functionality
document.getElementById('pasteBtn').addEventListener('click', async () => {
try {
const text = await navigator.clipboard.readText();
const pastedData = JSON.parse(text);
// Store in sessionStorage
sessionStorage.setItem('thumbmark_clipboard', JSON.stringify(pastedData));
// Reload the page to show the comparison
location.reload();
} catch (err) {
alert('Failed to paste from clipboard. Make sure you have valid JSON data copied: ' + err.message);
}
});
// Listen for iframe experimental results
window.addEventListener('message', function(event) {
if (event.data.type === 'experimental-results') {
console.log('Parent received experimental data:', event.data.experimental);
const newData = JSON.stringify(event.data.experimental);
console.log('Stringified data:', newData);
const existingData = sessionStorage.getItem('thumbmark_iframe');
// Only reload if data has changed or doesn't exist
if (existingData !== newData) {
sessionStorage.setItem('thumbmark_iframe', newData);
console.log('Stored in sessionStorage:', sessionStorage.getItem('thumbmark_iframe'));
// Set flag to prevent loading iframe again after reload
sessionStorage.setItem('thumbmark_iframe_loaded', 'true');
// Reload to show the comparison
location.reload();
}
}
});
// Load iframe after page loads
window.addEventListener('DOMContentLoaded', () => {
const iframeLoadedFlag = sessionStorage.getItem('thumbmark_iframe_loaded');
// Only load iframe if we haven't loaded it before in this session
if (!iframeLoadedFlag) {
const iframe = document.getElementById('testIframe');
iframe.src = 'experimental-iframe2.html';
}
});
</script>
</body>
</html>