// Video Spin (2026-11-22): the third view on the Links screen. One short link that rotates through video pages on Social Tube. // It is a spin link underneath (rotator.js, kind 'video'): pause, weights and removal go through the spin-link routes; creating one, // adding videos and the play counts go through /api/my/videospins (server.js), which checks every video with Video App Income. (function () { 'use strict'; if (!window.CR || !document.getElementById('vsWs')) return; const $ = id => document.getElementById(id); const esc = CR.esc, fmt = CR.fmt, api = CR.api, toast = CR.toast; let D = null, SPINS = [], SEL = null, HOST = '', PLAYS = {}, BUSY = false; let WANT = Number((/^#v([0-9]+)$/.exec(location.hash) || [])[1]) || 0; // the Video Spin named in the address when the page opened const mark = () => { if (!$('vsWs').hidden) history.replaceState(null, '', '#v' + (SEL || '')); }; const base = () => 'https://' + (HOST || location.host), linkOf = s => base() + '/r/' + s.code; const clicks7 = s => s.hits7 || 0; const zoneCode = s => ''; const state = s => s.paused ? { cls: 'warn', t: 'PAUSED' } : !s.destinations.some(d => d.active) ? { cls: 'bad', t: 'NO LIVE VIDEO' } : { cls: 'ok', t: 'LIVE' }; // ── view switch: this script only owns the Video Spins view; banner-spin.js keeps switching the other two ── function show(on) { $('vsWs').hidden = !on; const vb = $('vsNewBtn'); if (vb) vb.hidden = !on; if (on) { $('ws').hidden = true; $('bsWs').hidden = true; const nb = $('newBtn'), bn = $('bsNewBtn'); if (nb) nb.hidden = true; if (bn) bn.hidden = true; } } $('vsw').querySelectorAll('button').forEach(b => b.addEventListener('click', () => { const on = b.dataset.v === 'videos'; show(on); if (on) load(true); })); (function addBtn(n) { const nb = $('newBtn'); if (!nb) { if (n < 50) setTimeout(() => addBtn(n + 1), 200); return; } const b = document.createElement('button'); b.className = 'btn pri'; b.id = 'vsNewBtn'; b.type = 'button'; b.hidden = $('vsWs').hidden; b.textContent = '+ New Video Spin'; nb.parentNode.appendChild(b); b.addEventListener('click', () => { SEL = null; render(); const i = $('vsNewName'); if (i) i.focus(); }); })(0); async function load(keep) { try { D = await CR.get('/api/my/videospins'); } catch (e) { toast(e.message, true); return; } SPINS = (D.spins || []).slice().sort((a, b) => clicks7(b) - clicks7(a) || b.created - a.created); const hs = D.hosts || []; if (!HOST || !hs.includes(HOST)) HOST = hs[0] || location.host; if (!keep || !SPINS.some(s => s.id === SEL)) SEL = null; if (WANT) { if (SPINS.some(s => s.id === WANT)) SEL = WANT; WANT = 0; } mark(); setTimeout(mark, 1500); // the spin-link list reloads in the background and may set its own address; keep ours while this view is open render(); if (SEL) loadPlays(); } async function loadPlays() { const id = SEL; try { const r = await CR.get('/api/my/videospins/' + id + '/plays'); if (id === SEL) { PLAYS = r.plays || {}; renderDetail(); } } catch (e) {} } function render() { renderList(); renderDetail(); } function renderList() { const L = D.limits || { spins: 0, videos: 0 }, t = D.tier || { label: '' }; $('vsCount').textContent = SPINS.length + ' Video Spin' + (SPINS.length === 1 ? '' : 's'); $('vsTier').innerHTML = L.spins ? esc(t.label) + ' tier: ' + L.spins + ' Video Spins, ' + L.videos + ' videos in each.' : 'Video Spins start at the Starter tier (any package of your own): 2 Video Spins with 5 videos in each.'; $('vsItems').innerHTML = SPINS.length ? SPINS.map(s => { const h = state(s); return '
One short link that plays a different video page each time it is opened. Pick videos you made on Video App Income, or add any member\'s video by its Social Tube link. Share the one link; the videos take turns. People who go on to make their own video are credited to you.
' + '' + esc(D.vaiError) + '
' : '') + (!D.on ? 'Video Spins are not switched on yet.
' : can ? '' : '' + (L.spins ? 'You have all ' + L.spins + ' Video Spins your tier holds. Remove one to make another.' : 'Video Spins start at the Starter tier (any package of your own).') + '
') + '' + fmt(s.hits || 0) + ' clicks in all, ' + fmt(s.hits7 || 0) + ' in the last 7 days' + (s.conversions ? ', ' + s.conversions + ' conversion' + (s.conversions === 1 ? '' : 's') : '') + '. Each open goes to one of the videos below.
' + 'Paste this code into any page. Each page view plays a different video from this spin, with that video\'s own button. Page views are not counted as clicks; plays and button taps show under each video.
No videos yet. Add some below; the link starts working with the first one.
') + '' + esc(D.vaiError) + '
' : !D.member ? 'No Video App Income account was found for your email address. Make your first video at videoappincome.com (it is free), then come back.
' : !room ? 'This Video Spin is full for your tier.
' : mine.length ? '' + ((D.videos || []).length ? 'All of your videos are already in this spin.' : 'You have no videos on Social Tube yet. Make one on Video App Income and it appears here.') + '
') + 'Open the video on socialtube.club and paste its address. Its owner gets the views; people who go on to join are credited to you.
' + (room ? '' : 'This Video Spin is full for your tier.
') + '