// === Frambe v1.3.0 - Vintage Polaroid Pile === (function () { 'use strict'; var config = {}, assets = [], currentIndex = -1, slideshowTimer = null; var overlayVisible = true, overlayTimeout = null, selectedSource = null, selectedAlbumId = null; var selectedPersonId = null, isRunning = false, refreshTimer = null, urlDriven = false; var pileHistory = [], PILE_SIZE = 5, currentVideoPlaying = false; var $setupScreen = document.getElementById('setup-screen'), $slideshowScreen = document.getElementById('slideshow-screen'); var $connectionStatus = document.getElementById('connection-status'), $setupContent = document.getElementById('setup-content'); var $setupError = document.getElementById('setup-error'), $errorDetail = document.getElementById('error-detail'); var $albumsList = document.getElementById('albums-list'), $btnStart = document.getElementById('btn-start'); var $bgBlur = document.getElementById('bg-blur'), $mainFrame = document.getElementById('main-frame'); var $mainPhoto = document.getElementById('main-photo'), $mainVideo = document.getElementById('main-video'); var $clock = document.getElementById('clock'), $dateDisplay = document.getElementById('date-display'); var $exifInfo = document.getElementById('exif-info'), $progressFill = document.getElementById('progress-fill'); var $overlay = document.getElementById('overlay'), $btnSettings = document.getElementById('btn-settings'); var $progressBar = document.getElementById('progress-bar'); var pilePositions = [ { x: -18, y: -12, rot: -11, scale: 0.85 }, { x: 22, y: -8, rot: 7, scale: 0.80 }, { x: -14, y: 15, rot: 14, scale: 0.78 }, { x: 20, y: 12, rot: -9, scale: 0.82 }, { x: -5, y: -20, rot: 4, scale: 0.75 } ]; function getUrlParams() { var p={},s=window.location.search.substring(1);if(!s)return p;var pairs=s.split('&');for(var i=0;i';html+=thu?'':'
📁
';html+='
'+escapeHtml(a.albumName)+'
'+a.assetCount+' items
';}$albumsList.innerHTML=html;}catch(e){$albumsList.innerHTML='

Failed to load albums

';} } window.selectSource = function(src){selectedSource=src;selectedAlbumId=null;selectedPersonId=null;document.getElementById('btn-all-photos').classList.toggle('selected',src==='random');document.getElementById('btn-favorites').classList.toggle('selected',src==='favorites');var items=document.querySelectorAll('.album-item');for(var i=0;i0)console.log('[Frambe] Refresh added '+added+' new asset(s)');}catch(e){console.warn('[Frambe] Refresh failed: '+e.message);}}, (config.refreshInterval||300)*1000); } async function doStartSlideshow() { if (!selectedSource) return; $btnStart.disabled = true; $btnStart.innerHTML = ' Loading…'; try { await loadAssets(); if (!assets.length) { $btnStart.textContent = 'No photos found'; setTimeout(function(){$btnStart.textContent='▶ Start Slideshow';$btnStart.disabled=false;},2000); return; } $setupScreen.style.display = 'none'; $slideshowScreen.style.display = 'block'; document.body.classList.remove('setup-mode'); isRunning = true; if (!config.showClock) $clock.style.display = 'none'; if (!config.showDate) $dateDisplay.style.display = 'none'; if (!config.showExif) $exifInfo.style.display = 'none'; if (!config.showProgress) $progressBar.style.display = 'none'; if (!config.backgroundBlur) $bgBlur.style.display = 'none'; updateClock(); setInterval(updateClock, 1000); currentIndex = -1; pileHistory = []; showNextAsset(); scheduleOverlayHide(); startRefreshTimer(); } catch (err) { console.error('[Frambe] Start failed: '+err.message); $btnStart.textContent='Error: '+err.message; setTimeout(function(){$btnStart.textContent='▶ Start Slideshow';$btnStart.disabled=false;},3000); } } window.startSlideshow = function () { doStartSlideshow(); }; window.exitSlideshow = function () { if (urlDriven) { window.location.href = window.location.pathname; return; } isRunning=false;clearTimeout(slideshowTimer);if(refreshTimer)clearInterval(refreshTimer);stopVideo(); $slideshowScreen.style.display='none';$setupScreen.style.display='flex';document.body.classList.add('setup-mode'); $btnStart.textContent='▶ Start Slideshow';$btnStart.disabled=false; $bgBlur.style.backgroundImage='';$bgBlur.classList.remove('visible');$mainFrame.classList.remove('visible');clearPile(); }; function showNextAsset() { currentIndex++;if(currentIndex>=assets.length){if(config.shuffle)shuffleArray(assets);currentIndex=0;}showAsset(currentIndex); } function showPrevAsset() { currentIndex--;if(currentIndex<0)currentIndex=assets.length-1;showAsset(currentIndex); } function showAsset(index) { if (!assets[index]) return; clearTimeout(slideshowTimer); stopVideo(); var asset = assets[index], isVideo = asset.type === 'VIDEO'; var thumbUrl = '/api/assets/' + asset.id + '/thumbnail?size=preview'; console.log('[Frambe] Showing ' + (isVideo ? 'VIDEO' : 'PHOTO') + ': ' + (asset.originalFileName || asset.id)); if (pileHistory.length > 0 || currentIndex > 0) { var pi = currentIndex - 1; if (pi < 0) pi = assets.length - 1; if (assets[pi]) addToPile(assets[pi]); } $mainFrame.classList.remove('visible'); var img = new Image(); img.onload = function () { setTimeout(function () { displayAsset(asset, thumbUrl, isVideo); }, 400); }; img.onerror = function () { setTimeout(showNextAsset, 500); }; img.src = thumbUrl; var ni = index + 1; if (ni >= assets.length) ni = 0; if (assets[ni]) { var pre = new Image(); pre.src = '/api/assets/' + assets[ni].id + '/thumbnail?size=preview'; } } function displayAsset(asset, thumbUrl, isVideo) { if (config.backgroundBlur) { $bgBlur.style.backgroundImage = 'url(' + thumbUrl + ')'; $bgBlur.classList.add('visible'); } if (isVideo) { $mainFrame.classList.remove('polaroid'); $mainFrame.classList.add('filmstrip'); $mainPhoto.style.display = 'none'; $mainVideo.style.display = 'block'; $mainVideo.src = '/api/assets/' + asset.id + '/video'; $mainVideo.poster = thumbUrl; $mainVideo.load(); $mainVideo.play().then(function(){ currentVideoPlaying=true; console.log('[Frambe] Video playing'); }).catch(function(e){ console.warn('[Frambe] Video autoplay failed: '+e.message); }); $mainVideo.onended = function () { console.log('[Frambe] Video ended'); currentVideoPlaying=false; showNextAsset(); }; var maxDur = Math.max((config.slideshowInterval||30)*3, 120)*1000; slideshowTimer = setTimeout(function(){ if(currentVideoPlaying){console.log('[Frambe] Video timeout');showNextAsset();} }, maxDur); } else { $mainFrame.classList.remove('filmstrip'); $mainFrame.classList.add('polaroid'); $mainVideo.style.display = 'none'; $mainPhoto.style.display = 'block'; $mainPhoto.src = thumbUrl; slideshowTimer = setTimeout(showNextAsset, (config.slideshowInterval||30)*1000); } requestAnimationFrame(function () { $mainFrame.classList.add('visible'); }); updateExifInfo(asset); startProgress(isVideo ? null : (config.slideshowInterval||30)*1000); } function stopVideo() { if(currentVideoPlaying||$mainVideo.src){try{$mainVideo.pause();}catch(e){}$mainVideo.removeAttribute('src');$mainVideo.load();$mainVideo.onended=null;currentVideoPlaying=false;} } function addToPile(asset) { pileHistory.push(asset.id); if (pileHistory.length > PILE_SIZE) pileHistory.shift(); for (var i = 0; i < PILE_SIZE; i++) { var $pile = document.getElementById('pile-' + i), $inner = $pile.querySelector('.pile-inner'); var histIdx = pileHistory.length - 1 - i; if (histIdx >= 0 && pileHistory[histIdx]) { var aid = pileHistory[histIdx], pos = pilePositions[i]; $inner.style.cssText = 'width:100%;height:100%;background-color:#f5f0e8;padding:4% 4% 14% 4%;box-shadow:0 2px 15px rgba(0,0,0,0.4),0 0 1px rgba(0,0,0,0.2);border-radius:2px;'; $inner.innerHTML = '
'; $pile.style.transform = 'translate(calc(-50% + '+pos.x+'vmin), calc(-50% + '+pos.y+'vmin)) rotate('+pos.rot+'deg) scale('+pos.scale+')'; $pile.style.opacity = 0.35 - (i * 0.04); $pile.classList.add('visible'); } else { $pile.classList.remove('visible'); } } } function clearPile() { pileHistory=[];for(var i=0;i0;i--){var j=Math.floor(Math.random()*(i+1));var t=a[i];a[i]=a[j];a[j]=t;}} function padZero(n){return n<10?'0'+n:''+n;} function formatDate(d){var m=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];return d.getDate()+' '+m[d.getMonth()]+' '+d.getFullYear();} function escapeHtml(s){var d=document.createElement('div');d.appendChild(document.createTextNode(s));return d.innerHTML;} async function requestWakeLock(){try{if('wakeLock' in navigator)await navigator.wakeLock.request('screen');}catch(e){}} document.addEventListener('visibilitychange',function(){if(document.visibilityState==='visible'&&isRunning)requestWakeLock();}); function preventSleep(){try{var v=document.createElement('video');v.setAttribute('playsinline','');v.setAttribute('muted','');v.setAttribute('loop','');v.style.cssText='position:absolute;width:1px;height:1px;opacity:0.01';v.src='data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAAAAhtZGF0AAAA1m1vb3YAAABsbXZoZAAAAAAAAAAAAAAAAAAAA+gAAAAAAAEAAAEAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAYdHJhawAAAFx0a2hkAAAAAwAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAJBtZGlhAAAAIG1kaGQAAAAAAAAAAAAAAAAAADIAAAAAAAAhhdmMxAAAAAAAAAAAAAAAAAAAAAAAA';document.body.appendChild(v);v.play().catch(function(){});}catch(e){}} init();requestWakeLock();preventSleep(); })();