// ==UserScript== // @name 4chan - YouTube Playlist // @description Wraps all YouTube videos inside a thread into a playlist // @namespace 4chan-yt-playlist // @version 2.4.9 // @include https://boards.4chan.org/*/thread/* // @include https://warosu.org/*/thread/* // @run-at document-start // @grant GM_setValue // @grant GM_getValue // ==/UserScript== const e=new class{constructor(){this.initFinished=!1,this.fourchan="boards.4chan.org"===location.hostname,this.warosu="warosu.org"===location.hostname,this.native=!0,this.fixedNav=!1,this.classicNav=!1,this.autohideNav=!1,this.fourchanX=!1;const e=location.pathname.slice(1).split("/thread/");this.board=e[0],this.thread=e[1],this.warosu&&(this.initFinished=!0),document.addEventListener("4chanMainInit",(()=>{this.native=!unsafeWindow.Config.disableAll,this.fixedNav=unsafeWindow.Config.dropDownNav,this.classicNav=unsafeWindow.Config.classicNav,this.autohideNav=unsafeWindow.Config.autoHideNav,this.initFinished=!0})),document.addEventListener("4chanXInitFinished",(()=>{this.fourchanX=!0}))}get fixedHeader(){return!!this.fourchanX&&document.documentElement.classList.contains("fixed")}get autohideHeader(){return!!this.fourchanX&&document.documentElement.classList.contains("autohide")}};class t{constructor(t){function a(e){if(!t.player)return;if(!e.target?.dataset.page)return;const a=e.target.dataset.page||"0";t.player.cuePlaylist(t.toPages()[parseInt(a)])}function o(){if(!t.checking&&!t.isEmpty())return t.player?t.dialog?.toggle():function(){if(t.state>0||t.player)return;if(t.state<0)return o();t.state=1;const a=document.createElement("script");function o(){const t="Unable to load YouTube Iframe API.\nPress F12 and follow the instructions in the console.";e.fourchanX||alert(t),document.dispatchEvent(new CustomEvent("CreateNotification",{detail:{type:"error",content:t}})),console.info("Unable to load YouTube Iframe API\n\n4chanX's Settings > Advanced > Javascript Whitelist\n\n https://www.youtube.com/iframe_api\n https://www.youtube.com/s/player/\n\nFilters in your AdBlock extension\n\n @@||www.youtube.com/iframe_api$script,domain=4chan.org\n @@||www.youtube.com/s/player/*$script,domain=4chan.org\n")}a.src="https://www.youtube.com/iframe_api",document.head.appendChild(a),setTimeout((()=>{t.state<1||(t.state=-1,o())}),5e3),a.onerror=()=>{o(),t.state=-1}}()}function s(a){if(t.dialog.self)switch(a.type){case"mouseup":if(!t.dialog.dragging)return;t.dialog.dragging=!1,document.removeEventListener("mousemove",n),GM_setValue((e.fourchan?"4chan":"Warosu")+" Dialog Coordinates",[t.dialog.self.style.top,t.dialog.self.style.right,t.dialog.self.style.bottom,t.dialog.self.style.left]);break;case"mousedown":if(0!==a.button)return;a.preventDefault();const o=t.dialog.self.getBoundingClientRect();if(t.dialog.snapshot.size[0]=o.width,t.dialog.snapshot.size[1]=o.height,t.dialog.snapshot.cursor[0]=a.x-o.x,t.dialog.snapshot.cursor[1]=a.y-o.y,e.fixedNav||e.fixedHeader){const a=document.getElementById(e.fourchanX?"header-bar":e.classicNav?"boardNavDesktop":"boardNavMobile");a&&(t.dialog.snapshot.topbar[0]=a.getBoundingClientRect().y||0,t.dialog.snapshot.topbar[1]=a.offsetHeight||0,t.dialog.snapshot.topbar[2]=e.fourchanX?e.fixedHeader:e.fixedNav,t.dialog.snapshot.topbar[3]=e.fourchanX?e.autohideHeader:e.autohideNav)}t.dialog.dragging=!0,document.addEventListener("mousemove",n)}}function n(e){if(!t.dialog.self)return;e.preventDefault();const a=document.documentElement.clientWidth,o=document.documentElement.clientHeight,s=e.x-t.dialog.snapshot.cursor[0],n=e.y-t.dialog.snapshot.cursor[1],i=a-t.dialog.snapshot.size[0];let r=0,l=o-t.dialog.snapshot.size[1];if(t.dialog.snapshot.topbar[2]){const[e,a,o,s]=t.dialog.snapshot.topbar;o&&!s&&(el?(t.dialog.self.style.bottom="0px",t.dialog.self.style.removeProperty("top")):(t.dialog.self.style.top=n>r?100*n/o+"%":r+"px",t.dialog.self.style.removeProperty("bottom")),s>i?(t.dialog.self.style.right="0px",t.dialog.self.style.removeProperty("left")):(t.dialog.self.style.left=s>0?100*s/a+"%":"0px",t.dialog.self.style.removeProperty("right"))}function i(e){e.forEach(((e,a)=>{if(e&&t.dialog?.self)switch(a){case 0:t.dialog.self.style.top=e;break;case 1:t.dialog.self.style.right=e;break;case 2:t.dialog.self.style.bottom=e;break;case 3:t.dialog.self.style.left=e}}))}this.dragging=!1,this.snapshot={size:[0,0],cursor:[0,0],topbar:[0,0,!1,!1]},document.addEventListener("DOMContentLoaded",(()=>{document.body.insertAdjacentHTML("beforeend",'
    ×
    ');const o=this.self?.querySelector("ul"),n=this.self?.querySelector(".reload"),r=this.self?.querySelector(".move"),l=this.self?.querySelector(".jump"),c=this.self?.querySelector(".close");switch(o.addEventListener("click",a),n.addEventListener("click",(function(e){const a=e.currentTarget?.firstElementChild;return a?.classList.add("spin"),t.reload()})),r.addEventListener("mousedown",s),l.addEventListener("click",(()=>{t.jumpTo(t.track)})),c.addEventListener("click",(()=>{this.toggle(!0)})),document.addEventListener("mouseup",s),!0){case e.fourchan:i(GM_getValue("4chan Dialog Coordinates",["10%","5%",null,null]));break;case e.warosu:i(GM_getValue("Warosu Dialog Coordinates",["10%","5%",null,null]))}})),document.addEventListener("DOMContentLoaded",(()=>{switch(!0){case e.fourchan:document.getElementById("navtopright")?.insertAdjacentHTML("afterbegin",'[Playlist] '),document.getElementById("navbotright")?.insertAdjacentHTML("afterbegin",'[Playlist] '),document.addEventListener("4chanParsingDone",(()=>{document.getElementById("settingsWindowLinkClassic")?.insertAdjacentHTML("beforebegin",'Playlist'),document.getElementById("settingsWindowLinkMobile")?.insertAdjacentHTML("beforebegin",'Playlist '),["settingsWindowLinkClassic","settingsWindowLinkMobile"].forEach((e=>{(document.getElementById(e)?.querySelector(".playlist-toggle")).onclick=o}))})),["navtopright","navbotright"].forEach((e=>{(document.getElementById(e)?.querySelector(".playlist-toggle")).onclick=o}));break;case e.warosu:const t=document.getElementById("p"+e.thread)?.querySelector("a:last-of-type");t?.nextElementSibling?.insertAdjacentHTML("beforebegin",'[Playlist]'),document.querySelector(".playlist-toggle").onclick=o}})),document.addEventListener("4chanXInitFinished",(()=>{document.getElementById("shortcut-qr")?.insertAdjacentHTML("beforebegin",'YouTube Playlist'),document.querySelector(".playlist-toggle:not(.native)").onclick=o}))}get self(){return document.getElementById("playlist-embed")}get toggleBtn(){return document.querySelector(".playlist-toggle:not(.native)")}toggle(t){if(t||!this.self?.classList.contains("hide")){if(this.self?.classList.add("hide"),!e.fourchanX)return;const t=document.getElementById("shortcut-playlist")?.firstElementChild;t?.classList.add("disabled")}else{if(this.self?.classList.remove("hide"),!e.fourchanX)return;const t=document.getElementById("shortcut-playlist")?.firstElementChild;t?.classList.remove("disabled")}}updateTabs(e){const t=this.self?.querySelector("ul");if(!t)return console.error("No