// Whiteboard tab: source URL (owner-gated, see api_frames.py's // api_whiteboard_source), preview, and take control. window.FRAME_API is // set by the template. const whiteboardForm = document.getElementById('whiteboard-source-form'); if (whiteboardForm) { whiteboardForm.addEventListener('submit', async (e) => { e.preventDefault(); const url = document.getElementById('whiteboard-url-input').value.trim(); if (!url) return; try { const resp = await fetch(`${window.FRAME_API}/whiteboard-source`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url }), }); if (!resp.ok) throw new Error(await apiError(resp)); showStatus(true, 'Saved. Reload to see the updated source.'); loadWhiteboardPreview(); } catch (e) { showStatus(false, e.message); } }); } const whiteboardClearBtn = document.getElementById('whiteboard-source-clear'); if (whiteboardClearBtn) { whiteboardClearBtn.addEventListener('click', async () => { try { const resp = await fetch(`${window.FRAME_API}/whiteboard-source`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: null }), }); if (!resp.ok) throw new Error(await apiError(resp)); showStatus(true, 'Cleared. Reload to see the change.'); loadWhiteboardPreview(); } catch (e) { showStatus(false, e.message); } }); } function loadWhiteboardPreview(force) { const forceParam = force ? '&force=1' : ''; document.getElementById('whiteboard-preview').src = `${window.FRAME_API}/preview/whiteboard?_=${Date.now()}${forceParam}`; } // Loading the tab shows whatever's already cached (cheap, no refetch); // the button is the one place that means "no really, go check now" -- // bypasses the fetch throttle server-side (see api_frames.py's `force`). document.getElementById('whiteboard-preview-refresh').addEventListener('click', () => loadWhiteboardPreview(true)); loadWhiteboardPreview(false); // --- file picker (Browse...) --- const browseToggle = document.getElementById('whiteboard-browse-toggle'); if (browseToggle) { const browsePanel = document.getElementById('whiteboard-browser'); const browseList = document.getElementById('whiteboard-browse-list'); const browseCurrent = document.getElementById('whiteboard-browse-current'); const browseUp = document.getElementById('whiteboard-browse-up'); const browseError = document.getElementById('whiteboard-browse-error'); const urlInput = document.getElementById('whiteboard-url-input'); let opened = false; async function browseTo(url) { browseError.style.display = 'none'; browseList.innerHTML = '