/* Pre-generated silent thinking clips. Only a pending chat owns this player. */ (function(){ 'use strict'; const stage=document.querySelector('#stage'); if(!stage||document.documentElement.classList.contains('content-reader'))return; const base=new URL('../',document.currentScript.src).pathname; const ids=['glance','reflect','chin']; const scene=document.createElement('div');scene.className='thinking-scene'; scene.setAttribute('aria-hidden','true');stage.prepend(scene); let active=false,epoch=0,cursor=-1,current=null,shown=null,blocked=false,pageActive=true; let failed=new Set(); const allowed=()=>active&&pageActive&&!document.hidden&&!stage.classList.contains('has-news-broadcast'); const valid=v=>active&&v===current&&v.thinkingEpoch===epoch; function status(value){scene.dataset.state=value;} function hide(){ if(stage.classList.contains('thinking-scene-visible')){ window.IdleBackground?.resetAnchor(); stage.classList.remove('thinking-scene-visible'); } } function dispose(v){ if(!v)return;clearTimeout(v.thinkingTimer); if(document.fullscreenElement===v)document.exitFullscreen?.().catch(()=>{}); if(v.webkitDisplayingFullscreen)v.webkitExitFullscreen?.(); v.pause();v.removeAttribute('src');v.load();v.remove(); } function arm(v){ clearTimeout(v.thinkingTimer); if(valid(v)&&allowed())v.thinkingTimer=setTimeout(()=>fail(v),12000); } function fail(v){ if(!valid(v))return; failed.add(v.dataset.clip);status('fallback'); if(failed.size===ids.length){ current=null;hide();dispose(v);if(shown!==v)dispose(shown);shown=null;return; } next(); } function play(v){ if(!valid(v)||!allowed()||blocked||v.thinkingPlaying)return; if(v.paused||v.ended){ v.thinkingPlaying=true;arm(v); Promise.resolve(v.play()).then(()=>{ if(!valid(v)||!allowed()||blocked)v.pause(); }).catch(error=>{ if(!valid(v)||!allowed()||error.name==='AbortError')return; if(error.name==='NotAllowedError'){blocked=true;clearTimeout(v.thinkingTimer);hide();status('blocked');} else fail(v); }).finally(()=>{v.thinkingPlaying=false;}); } } function next(){ if(!active)return; const previous=current;current=null; if(previous&&previous!==shown)dispose(previous); if(shown){shown.pause();clearTimeout(shown.thinkingTimer);} let id; for(let n=0;n{ if(!valid(v)||!allowed()||blocked){v.pause();return;} clearTimeout(v.thinkingTimer); if(shown&&shown!==v)dispose(shown); shown=v;v.classList.add('is-active');stage.classList.add('thinking-scene-visible');status('playing'); }); v.addEventListener('ended',()=>{if(valid(v)&&allowed())next();}); v.addEventListener('waiting',()=>{if(valid(v)&&allowed())arm(v);}); v.addEventListener('stalled',()=>{if(valid(v)&&allowed())arm(v);}); v.addEventListener('error',()=>fail(v)); v.addEventListener('fullscreenchange',()=>{v.controls=document.fullscreenElement===v;}); v.addEventListener('webkitbeginfullscreen',()=>{v.controls=true;}); v.addEventListener('webkitendfullscreen',()=>{v.controls=false;}); v.src=base+'static/assets/zhiwei-thinking-20261024-v1/'+id+'.mp4'; scene.append(v);status('loading');play(v); } function sync(){ if(!active)return; if(!allowed()){ if(current){clearTimeout(current.thinkingTimer);current.pause();} if(shown&&shown!==current)shown.pause(); hide();status('suspended');return; } if(blocked){status('blocked');return;} if(current){if(current.ended)next();else play(current);} } function stop(){ active=false;epoch++;blocked=false;hide(); const old=current;current=null;dispose(old);if(shown!==old)dispose(shown);shown=null; status('idle'); } function start(){ stop();active=true;failed=new Set();next(); } new MutationObserver(sync).observe(stage,{attributes:true,attributeFilter:['class']}); document.addEventListener('visibilitychange',sync); window.addEventListener('pagehide',()=>{pageActive=false;sync();}); window.addEventListener('pageshow',()=>{pageActive=true;sync();}); function recover(){if(active&&blocked){blocked=false;sync();}} document.addEventListener('pointerdown',recover,{passive:true}); document.addEventListener('keydown',recover); window.addEventListener('online',()=>{if(active){blocked=false;failed.clear();if(!current)next();else sync();}}); window.ThinkingBackground={start,stop,getVideo:()=>stage.classList.contains('thinking-scene-visible')?shown:null}; status('idle'); })();