diff --git a/main.js b/main.js index a2fd7db..e2ed0a7 100644 --- a/main.js +++ b/main.js @@ -199,7 +199,11 @@ async function loadHistory() {
-
${test.url}
+
+ + ${test.url} + +
${date} • ${test.isMobile ? '📱 Mobile' : '💻 Desktop'}
@@ -223,12 +227,38 @@ async function loadHistory() { // Setup comparison functionality setupComparisonControls(); + + // Setup click handlers for history URLs + document.querySelectorAll('.history-url-link').forEach(link => { + link.addEventListener('click', async (e) => { + e.preventDefault(); + const testId = e.target.dataset.testId; + await loadTestById(testId); + }); + }); } catch (error) { console.error('Failed to load history', error); } } +// Load and display a test by ID +async function loadTestById(testId) { + try { + const response = await fetch(`/reports/${testId}.json`); + if (!response.ok) throw new Error('Test not found'); + + const data = await response.json(); + displayResults(data); + + // Scroll to results + document.getElementById('results-area').scrollIntoView({ behavior: 'smooth' }); + } catch (error) { + console.error('Failed to load test:', error); + alert('Could not load test results. The test may have been deleted.'); + } +} + function setupComparisonControls() { const checkboxes = document.querySelectorAll('.compare-checkbox'); const controls = document.getElementById('comparison-controls');