UNPKG

peertube-plugin-youth-schedule

Version:

PeerTube plugin: youth protection schedule (configurable HH:mm slots and end time)

14 lines (13 loc) 4.05 kB
var l={decided:!1,allowed:!0,open:null,end:null};async function y({registerHook:d}){let s=await fetch("/plugins/youth-schedule/router/config").then(e=>e.json()).catch(()=>({timeSource:"server",endTime:"06:00"})),u=()=>{let e=new Date;return e.getHours()*60+e.getMinutes()};async function r(e){try{let t=new URLSearchParams;s.timeSource==="user"&&t.set("clientMinutes",String(u()));let i=`/plugins/youth-schedule/router/video/${e}/youth-allowed?${t}`,o=await fetch(i);return o.ok?await o.json():{allowed:!0}}catch(t){return{allowed:!0}}}function a(){let e=["#plugin-selector-player-container","#videojs-wrapper","#video-wrapper","#player"];for(let o of e){let n=document.querySelector(o);if(n)return console.log("[YouthSchedule] player root via selector:",o),n}let t=document.querySelector(".video-js.vjs-peertube-skin")||document.querySelector('[id^="vjs_video_"]');if(t)return console.log("[YouthSchedule] player root via videojs container"),t.closest("#videojs-wrapper, #video-wrapper")||t;let i=document.querySelector("video.vjs-tech")||document.querySelector("video");if(i){let o=i.closest("#videojs-wrapper, #video-wrapper, .video-js")||i.parentElement;if(o)return console.log("[YouthSchedule] player root via video parent"),o}return console.warn("[YouthSchedule] player root not found; please share DOM around <video>."),null}if(!document.getElementById("youth-schedule-style")){let e=document.createElement("style");e.id="youth-schedule-style",e.textContent=` .youth-schedule-init-hidden { visibility: hidden !important; } .youth-schedule-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.75); display: flex; align-items: center; justify-content: center; z-index: 2147483647; padding: 16px; text-align: center; } .youth-schedule-overlay .msg { max-width: 720px; color: #fff; font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, 'Helvetica Neue', Arial, sans-serif; } .youth-schedule-overlay .msg .title { font-size: 1.1rem; margin-bottom: 8px; } .youth-schedule-overlay .msg .subtitle { font-size: .95rem; opacity: .9; } .youth-schedule-block-video video, .youth-schedule-block-video .video-js { pointer-events: none !important; } `,document.head.appendChild(e)}function c(e,t,i){if(!e)return;let o=getComputedStyle(e).position;(o==="static"||!o)&&(e.style.position="relative"),e.classList.add("youth-schedule-block-video");let n=e.querySelector(".youth-schedule-overlay");n||(n=document.createElement("div"),n.className="youth-schedule-overlay",n.innerHTML=` <div class="msg"> <div class="title">Dieses Video ist aus Jugendschutzgr\xFCnden derzeit nicht verf\xFCgbar.</div> <div class="subtitle">Freigabe von ${t||"\u2014"} bis ${i}.</div> </div> `,e.appendChild(n))}d({target:"action:video-watch.init",handler:async e=>{try{let t=a();t&&t.classList.add("youth-schedule-init-hidden");let i=e&&e.video&&e.video.uuid;if(!i){t&&t.classList.remove("youth-schedule-init-hidden");return}let o=await r(i);if(l={decided:!0,allowed:!!o.allowed,open:o.openLabel||null,end:o.endLabel||s.endTime||"06:00"},console.log("[YouthSchedule:init] decision",l),t&&t.classList.remove("youth-schedule-init-hidden"),!l.allowed){c(t,l.open,l.end);let n=t==null?void 0:t.querySelector("video");try{n&&n.pause&&n.pause()}catch(h){}}}catch(t){console.warn("[YouthSchedule:init] error",t)}}}),d({target:"filter:internal.video-watch.player.build-options.result",handler:e=>{try{l.decided&&l.allowed===!1&&(e.controls=!1,e.responsive=!1,e.fluid=!1,e.autoplay=!1,e.userActions||(e.userActions={}),e.userActions.hotkeys=!1)}catch(t){}return e}}),d({target:"action:video-watch.player.loaded",handler:async({video:e})=>{try{if(!l.decided){let o=await r(e.uuid);l={decided:!0,allowed:!!o.allowed,open:o.openLabel||null,end:o.endLabel||s.endTime||"06:00"},console.log("[YouthSchedule:loaded] decision",l)}if(l.allowed)return;let t=a();if(!t)return;let i=t.querySelector("video");try{i&&i.pause&&i.pause()}catch(o){}c(t,l.open,l.end)}catch(t){}}})}export{y as register};