peertube-plugin-youth-schedule
Version:
PeerTube plugin: youth protection schedule (configurable HH:mm slots and end time)
9 lines (8 loc) • 2.26 kB
JavaScript
async function f({registerVideoField:l,registerHook:t}){let i=await fetch("/plugins/youth-schedule/router/config").then(n=>n.json()).catch(()=>({slots:["20:00","22:00","23:00"]}));m(l,i);let e=document.createElement("style");e.textContent=`
/* \u0421\u0442\u0438\u043B\u0438 \u0434\u043B\u044F \u043D\u0435\u0430\u043A\u0442\u0438\u0432\u043D\u043E\u0433\u043E \u0441\u0435\u043B\u0435\u043A\u0442\u0430 */
select[name="youthOpenMinutes"]:disabled {
opacity: 0.5 !important;
cursor: not-allowed !important;
background-color: #f5f5f5 !important;
}
`,document.head.appendChild(e);function s(n){let r=Array.from(document.querySelectorAll("label"));for(let u of r){let c=(u.textContent||"").trim();if(c&&c.includes(n)){let o=u.closest("peertube-form-group, .form-group, fieldset")||u.parentElement;if(!o)continue;let a=o.querySelector("input, select, textarea");if(a)return a}}return null}t({target:"action:video-edit.init",handler:()=>{let n=()=>{let o=document.querySelector('[name="youthSensitive"]'),a=document.querySelector('[name="youthOpenMinutes"]');if(o||(o=s("Jugendschutz")),a||(a=s("Sendezeit")),o&&a){let d=()=>{a.disabled=!o.checked};return d(),o.addEventListener("change",d),!0}return!1},r=0,u=30,c=()=>{r++,!n()&&r<u&&setTimeout(c,150)};setTimeout(c,200)}})}function m(l,t){for(let i of["upload","update"]){let e={type:i,tab:"main"};l({name:"youthSensitive",label:"Jugendschutz: sensibler Inhalt?",descriptionHTML:"Falls ja, wird das Zeitfeld angezeigt.",type:"input-checkbox",default:!1},e);let s=[{value:"",label:"\u2014 Keine Beschr\xE4nkung \u2014"}];(Array.isArray(t.slots)&&t.slots.length?t.slots:["20:00","22:00","23:00"]).forEach(r=>{s.push({value:String(p(r)),label:r})}),l({name:"youthOpenMinutes",label:"Sendezeit (Start, HH:mm)",descriptionHTML:"W\xE4hlen Sie die Startzeit. Liste und Endzeit sind in den Plugin-Einstellungen konfigurierbar.",type:"select",options:s},e)}}function p(l){let t=String(l).trim();if(/^\d{1,2}$/.test(t))return Math.min(23,Math.max(0,parseInt(t,10)))*60;let i=t.match(/^(\d{1,2}):(\d{1,2})$/);if(i){let s=Math.min(23,Math.max(0,parseInt(i[1],10))),n=Math.min(59,Math.max(0,parseInt(i[2],10)));return s*60+n}let e=Number(t);return Number.isFinite(e)?e:0}export{f as register};