diff --git a/assets/js/result.js b/assets/js/result.js
new file mode 100644
index 0000000..5ee37bd
--- /dev/null
+++ b/assets/js/result.js
@@ -0,0 +1,324 @@
+(function() {
+
+ function getSessionId() {
+ // Get session_id from URL query parameter
+ const urlParams = new URLSearchParams(window.location.search);
+ let sessionId = urlParams.get('session_id');
+
+ if (!sessionId) {
+ // No session_id in URL, check localStorage
+ try {
+ const submissionData = localStorage.getItem('submission_data');
+
+ if (submissionData) {
+ const data = JSON.parse(submissionData);
+
+ if (data.entries && data.entries.length > 0) {
+ // Sort entries by timestamp (newest first) and get the latest
+ const sortedEntries = data.entries.sort((a, b) => {
+ return new Date(b.timestamp) - new Date(a.timestamp);
+ });
+
+ const latestEntry = sortedEntries[0];
+ sessionId = latestEntry.session_id;
+ console.log(`Loading session from localStorage: ${sessionId} from ${latestEntry.timestamp}`);
+ }
+ }
+ } catch (error) {
+ console.error(`Error reading from localStorage: ${error}`);
+ }
+
+ // If still no session_id, redirect to home
+ if (!sessionId) {
+ window.location.href = '/';
+ return null;
+ }
+ }
+
+ return sessionId;
+ }
+
+ const API_BASE_URL = 'https://valentinesong.oliver.digital/back';
+ let videoPlayer = null;
+ let resultData = null;
+
+ async function loadResults() {
+ try {
+ const response = await fetch(`${API_BASE_URL}/api/results/${sessionId}`);
+
+ if (!response.ok) {
+ if (response.status === 404) {
+ showError('Song not found. Please create a new one.');
+ return;
+ }
+ throw new Error('Failed to load results');
+ }
+
+ resultData = await response.json();
+
+ if (resultData.success && resultData.status === 'success') {
+ showSuccess(resultData);
+ } else {
+ showFailure(resultData);
+ }
+ } catch (error) {
+ console.error('Error loading results:', error);
+ showError('Failed to load your song. Please try again.');
+ }
+ }
+
+ function escapeHtml(text) {
+ const div = document.createElement('div');
+ div.textContent = text;
+ return div.innerHTML;
+ }
+
+ function showSuccess(data) {
+ // Update page title
+ const titleEl = document.querySelector('.title1');
+ if (titleEl) {
+ titleEl.textContent = `${data.pet_name}'s Love Song`;
+ }
+
+ // Replace rotating record with video player
+ /*const recordContainer = document.querySelector('.record-container');
+ if (recordContainer && data.video_url) {
+ recordContainer.innerHTML = `
+
+ `;
+ videoPlayer = document.getElementById('video-player');
+ }*/
+
+ // Replace rotating record with image
+ const recordContainer = document.querySelector('.record-container');
+ if (recordContainer && data.record_image_url) {
+ document.getElementById("pet-record").src = data.record_image_url;
+ }
+
+ // Update lyrics
+ const lyricsEl = document.querySelector('.song-lyrics');
+ if (lyricsEl && data.lyrics) {
+ // Format lyrics with line breaks
+ lyricsEl.innerHTML = escapeHtml(data.lyrics).replace(/\n/g, '
');
+ }
+
+ // Render lyrics
+ renderLyrics(data.lyrics, lyricsEl);
+
+ // Setup auto-scroll functionality
+ //setupAutoScroll(videoPlayer, lyricsEl);
+
+ // Hide play/pause controls (video has its own controls)
+ const songControl = document.querySelector('.song-control');
+ if (songControl) {
+ songControl.style.display = 'none';
+ }
+
+ // Setup download button
+ const downloadBtn = document.querySelector('.download-song-btn');
+ if (downloadBtn && data.video_url) {
+ downloadBtn.href = data.video_url;
+ downloadBtn.download = `${data.pet_name}-love-song.mp4`;
+ }
+
+ // Setup copy URL button
+ const copyBtn = document.querySelector('.copy-btn');
+ if (copyBtn) {
+ copyBtn.addEventListener('click', () => {
+ navigator.clipboard.writeText(window.location.href).then(() => {
+ const originalText = copyBtn.textContent;
+ copyBtn.textContent = 'Copied!';
+ setTimeout(() => {
+ copyBtn.textContent = originalText;
+ }, 2000);
+ }).catch(() => {
+ // Fallback for older browsers
+ const textArea = document.createElement('textarea');
+ textArea.value = window.location.href;
+ document.body.appendChild(textArea);
+ textArea.select();
+ document.execCommand('copy');
+ document.body.removeChild(textArea);
+ copyBtn.textContent = 'Copied!';
+ setTimeout(() => {
+ copyBtn.textContent = 'Copy URL';
+ }, 2000);
+ });
+ });
+ }
+
+ // Setup share buttons
+ setupShareButtons(data);
+ }
+
+ function showFailure(data) {
+ const bodyContainer = document.querySelector('.body-container');
+ if (bodyContainer) {
+ bodyContainer.innerHTML = `
+