mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-11-30 18:42:49 +08:00
1 line
11 KiB
Plaintext
1 line
11 KiB
Plaintext
{"manifest":{"apiVersion":1,"id":"community.watch-together","name":"Watch Together / 一起观看","version":"1.0.0","author":"Huddle-Up-Forge","license":"AGPL-3.0-only","description":"A shared video player with synchronized playback, pause and seeking. / 同步播放、暂停与跳转的视频播放器。","scopes":["server","instance"],"permissions":["room.read","room.write"]},"html":"<main>\n <header><h1 id=\"title\">Watch Together</h1><span id=\"members\"></span></header>\n <p id=\"lead\"></p>\n <form id=\"source\"><label><span id=\"url-label\">Video URL</span><input id=\"url\" type=\"url\" maxlength=\"2048\" placeholder=\"https://…/video.mp4\" required></label><button id=\"load\" type=\"button\">Load</button></form>\n <video id=\"video\" playsinline preload=\"metadata\"></video>\n <div class=\"controls\"><button id=\"play\" type=\"button\">▶</button><button id=\"pause\" type=\"button\">Ⅱ</button><button id=\"unlock\" type=\"button\">Enable playback</button><button id=\"fullscreen\" type=\"button\">⛶</button><label class=\"volume\">♫ <input id=\"volume\" type=\"range\" min=\"0\" max=\"1\" step=\".05\" value=\".7\" aria-label=\"Volume\"></label></div>\n <label class=\"seek\"><span id=\"time\">0:00 / 0:00</span><input id=\"seek\" type=\"range\" min=\"0\" max=\"1\" step=\".1\" value=\"0\" aria-label=\"Seek\"></label>\n <p id=\"status\" role=\"status\"></p>\n <p id=\"note\" class=\"note\"></p>\n</main>\n","script":"/* Uses only the public plugin API. Nothing here imports WebSpeak internals. */\n(async () => {\n const api = window.webspeak, context = await api.ready;\n const $ = id => document.getElementById(id), video = $('video');\n const language = context.language, zh = language === 'zh';\n const texts = {\n zh: ['一起观看','所有参与者共享播放、暂停和进度;音量仅影响自己。','视频直链','载入视频','允许播放','请使用浏览器支持的 MP4 / WebM 视频直链。不会把视频经过 WebSpeak 服务器转发。','浏览器阻止自动播放,请点击“允许播放”。','视频无法加载,请检查地址、格式与 HTTPS。','有人同时操作,已获取最新进度,请重试。'],\n en: ['Watch Together','Playback, pause and seeking are shared; volume is local.','Direct video URL','Load video','Enable playback','Use a browser-compatible MP4 / WebM URL. Video is fetched directly, never relayed by WebSpeak.','Autoplay was blocked. Click Enable playback.','Video could not load. Check URL, format and HTTPS.','Another participant changed playback. Refreshed; please try again.'],\n de: ['Gemeinsam ansehen','Wiedergabe, Pause und Position sind gemeinsam; Lautstärke ist lokal.','Direkte Video-URL','Video laden','Wiedergabe erlauben','Browserkompatible MP4-/WebM-URL verwenden. Video wird direkt geladen.','Autoplay blockiert. Wiedergabe erlauben anklicken.','Video nicht ladbar. URL, Format und HTTPS prüfen.','Gleichzeitige Änderung. Aktualisiert; erneut versuchen.'],\n ru: ['Смотреть вместе','Воспроизведение, пауза и позиция общие; громкость локальная.','Прямая ссылка на видео','Загрузить видео','Разрешить воспроизведение','Используйте прямую ссылку MP4 / WebM. Видео загружается напрямую.','Автовоспроизведение заблокировано. Нажмите Разрешить воспроизведение.','Не удалось загрузить видео. Проверьте адрес, формат и HTTPS.','Другой участник изменил состояние. Обновлено; повторите.'],\n ja: ['一緒に見る','再生・停止・位置を共有します。音量は自分の端末のみです。','動画の直接 URL','動画を読み込む','再生を許可','ブラウザー対応の MP4 / WebM URL を使用します。動画は直接取得されます。','自動再生がブロックされました。「再生を許可」を押してください。','動画を読み込めません。URL・形式・HTTPS を確認してください。','他の参加者が操作しました。最新状態で再試行してください。'],\n };\n const t = texts[language] || texts.en;\n ['title','lead','url-label','load','unlock','note'].forEach((id,i) => $(id).textContent=t[i]);\n $('play').ariaLabel=zh?'同步播放':'Play for everyone'; $('pause').ariaLabel=zh?'同步暂停':'Pause for everyone';\n $('fullscreen').ariaLabel=zh?'全屏':'Fullscreen';\n let snapshot=context.snapshot, offset=snapshot.serverTime-Date.now(), source='', busy=false, seeking=false, playingAttempt=false;\n video.volume=.7;\n function validState(value) {\n if(!value || typeof value.url!=='string' || value.url.length>2048 || typeof value.playing!=='boolean' || !Number.isFinite(value.position) || value.position<0 || value.position>604800 || !Number.isFinite(value.updatedAt)) return null;\n try {const u=new URL(value.url);if(!['http:','https:'].includes(u.protocol)||u.username||u.password)return null;}catch{return null;}\n return value;\n }\n function targetPosition(state) {return Math.max(0,Math.min(604800,state.position+(state.playing?Math.max(0,(Date.now()+offset-state.updatedAt)/1000):0)));}\n function status(message='') {$('status').textContent=message;}\n async function apply() {\n const state=validState(snapshot.state); if(!state)return;\n if(source!==state.url){source=state.url;video.src=source;$('url').value=source;video.load();}\n const desired=targetPosition(state);\n if(Number.isFinite(video.duration)&&video.duration>0&&desired>=video.duration){video.pause();video.playbackRate=1;return;}\n if(video.readyState>=1 && !seeking){const diff=desired-video.currentTime;\n if(Math.abs(diff)>(state.playing?.7:.04))video.currentTime=Math.min(desired,Number.isFinite(video.duration)?video.duration:desired);\n video.playbackRate=state.playing&&Math.abs(diff)>.15&&Math.abs(diff)<=.7?(diff>0?1.03:.97):1;\n }\n if(state.playing&&video.paused&&!playingAttempt){playingAttempt=true;try{await video.play();status();}catch{status(t[6]);}finally{playingAttempt=false;}}\n else if(!state.playing&&!video.paused)video.pause();\n }\n function receive(next) {if(next.roomId!==snapshot.roomId || next.revision<snapshot.revision)return;snapshot=next;offset=next.serverTime-Date.now();$('members').textContent=(zh?'参与者:':'Participants: ')+next.participants.length;void apply();}\n async function update(patch) {\n if(busy)return;busy=true;\n try {\n const state=validState(snapshot.state), next={url:state?.url||source,position:state?targetPosition(state):0,playing:state?.playing||false,updatedAt:Date.now()+offset,...patch};\n if(!validState(next))throw new Error(t[7]);\n receive(await api.room.update(snapshot.revision,next)); status();\n } catch(error){if(error.message==='PLUGIN_REVISION_CONFLICT'){receive(await api.room.snapshot());status(t[8]);}else status(error.message);}\n finally{busy=false;}\n }\n const load=()=>{if($('url').checkValidity())void update({url:$('url').value.trim(),position:0,playing:false});else $('url').reportValidity();};\n $('load').addEventListener('click',load);\n $('source').addEventListener('submit',event=>event.preventDefault());\n $('url').addEventListener('keydown',event=>{if(event.key==='Enter'){event.preventDefault();load();}});\n $('play').addEventListener('click',()=>{void video.play().catch(()=>status(t[6]));void update({playing:true});});\n $('pause').addEventListener('click',()=>void update({playing:false,position:video.currentTime}));\n $('unlock').addEventListener('click',()=>{void video.play().then(()=>{if(!snapshot.state?.playing)video.pause();status();}).catch(()=>status(t[6]));});\n $('fullscreen').addEventListener('click',()=>void video.requestFullscreen?.().catch(()=>undefined));\n $('volume').addEventListener('input',()=>video.volume=Number($('volume').value));\n $('seek').addEventListener('input',()=>{seeking=true;});\n $('seek').addEventListener('change',()=>{seeking=false;void update({position:Number($('seek').value)});});\n video.addEventListener('loadedmetadata',()=>void apply()); video.addEventListener('error',()=>status(t[7]));\n video.addEventListener('ended',()=>{video.playbackRate=1;});\n const time=value=>`${Math.floor(value/60)}:${Math.floor(value%60).toString().padStart(2,'0')}`;\n const timer=setInterval(()=>{void apply();const duration=Number.isFinite(video.duration)?video.duration:0;$('seek').max=String(duration||1);if(!seeking)$('seek').value=String(video.currentTime);$('time').textContent=`${time(video.currentTime)} / ${time(duration)}`;},1000);\n const unsubscribe=api.room.subscribe(receive);receive(snapshot);\n addEventListener('pagehide',()=>{clearInterval(timer);unsubscribe();video.pause();video.removeAttribute('src');video.load();},{once:true});\n})();\n","styles":{"light":"body{background:#f2f7f6;color:#183c38}main{max-width:850px;margin:auto}header{display:flex;gap:16px;align-items:center;justify-content:space-between}h1{font-size:22px;margin:0}p{line-height:1.5}form{display:flex;gap:10px;margin:16px 0;align-items:end}label{display:grid;gap:6px;flex:1;min-width:0}input[type=url]{width:100%;padding:10px;border:1px solid #83aaa4;border-radius:8px;background:#fff;color:#183c38;font:inherit}button{padding:10px 15px;border:1px solid #739e96;border-radius:8px;background:#e0f1eb;color:#174d41;font:inherit;cursor:pointer}button:disabled{opacity:.5}video{display:block;width:100%;max-height:50vh;min-height:180px;background:#101719;border-radius:12px}.controls{display:flex;flex-wrap:wrap;gap:8px;align-items:center;margin:12px 0}.volume{display:flex;align-items:center;max-width:150px}.volume input{min-width:0;width:100%}.seek{display:grid;grid-template-columns:100px 1fr;align-items:center}.seek input{width:100%}.note,#members{font-size:13px;opacity:.75}#status{min-height:1.5em;color:#a33c24}input[type=range]{accent-color:#168575}@media(max-width:500px){form{flex-wrap:wrap}form label{flex-basis:100%}.seek{grid-template-columns:1fr}}\n","dark":"body{background:#20242b;color:#e9eeee}main{max-width:850px;margin:auto}header{display:flex;gap:16px;align-items:center;justify-content:space-between}h1{font-size:22px;margin:0}p{line-height:1.5}form{display:flex;gap:10px;margin:16px 0;align-items:end}label{display:grid;gap:6px;flex:1;min-width:0}input[type=url]{width:100%;padding:10px;border:1px solid #58676b;border-radius:8px;background:#303840;color:#e9eeee;font:inherit}button{padding:10px 15px;border:1px solid #588579;border-radius:8px;background:#254c43;color:#dcfff4;font:inherit;cursor:pointer}button:disabled{opacity:.5}video{display:block;width:100%;max-height:50vh;min-height:180px;background:#080c0e;border-radius:12px}.controls{display:flex;flex-wrap:wrap;gap:8px;align-items:center;margin:12px 0}.volume{display:flex;align-items:center;max-width:150px}.volume input{min-width:0;width:100%}.seek{display:grid;grid-template-columns:100px 1fr;align-items:center}.seek input{width:100%}.note,#members{font-size:13px;opacity:.75}#status{min-height:1.5em;color:#ffaf91}input[type=range]{accent-color:#7cdbc2}@media(max-width:500px){form{flex-wrap:wrap}form label{flex-basis:100%}.seek{grid-template-columns:1fr}}\n"}} |