diff --git a/scripts/script.js b/scripts/script.js new file mode 100644 index 0000000..0fb90e8 --- /dev/null +++ b/scripts/script.js @@ -0,0 +1,1435 @@ +/*****YTPRO******* +Author: Prateek Chaubey +Version: 3.4.44 +URI: https://github.com/prateek-chaubey/ +*/ + + +//DEBUG +/*var debug=false; +var Android={ +pipvid:()=>{}, +gohome:()=>{}, +getInfo:()=>{}, +oplink:()=>{}, +downvid:()=>{} +}; +if(window.eruda == null){ +//ERUDA +window.location.href=`javascript:(function () { var script = document.createElement('script'); script.src="//cdn.jsdelivr.net/npm/eruda"; document.body.appendChild(script); script.onload = function () { eruda.init() } })();`; +} +/**/ + + +/*Few Stupid Inits*/ +var YTProVer="3.4"; +if(ytproNCode == undefined && ytproDecipher == undefined){ +var ytproNCode=[]; +var ytproDecipher=[]; +} +var ytoldV=""; +var isF=false; //what is this about? +var isAP=false; // oh it's for bg play +var isM=false; // no idea !! +var sTime=[]; + +if(localStorage.getItem("autoSpn") == null || localStorage.getItem("fitS") == null){ +localStorage.setItem("autoSpn","true"); +localStorage.setItem("fitS","true"); +localStorage.setItem("fzoom","false"); +} +if(localStorage.getItem("fzoom") == "true"){ +document.getElementsByName("viewport")[0].setAttribute("content",""); +} + + + +if(window.location.pathname.indexOf("shorts") > -1){ +ytoldV=window.location.pathname; +} +else{ +ytoldV=(new URLSearchParams(window.location.search)).get('v') ; +} + +/*Cleans the URL for various functions of the YTPRO*/ +function ytproGetURL(o,p){ +try{ +var url=o; + +if(p == "sig"){ +var sig=(new URLSearchParams(o)).get('s'); +url=(new URLSearchParams(o)).get('url'); +sig=eval(ytproDecipher[1]+ytproDecipher[0]+"('"+decodeURIComponent(sig)+"');"); +url=decodeURIComponent(url); +} +const components = new URL(decodeURIComponent(url)); +const n = components.searchParams.get('n'); +var nc=eval(ytproNCode[1]+ytproNCode[0]+"('"+n+"');"); +components.searchParams.set('n',nc); +if(p == "sig"){ +return components.toString()+"&sig="+sig; +} +else{ +return components.toString(); +} +}catch{} +} + + +/*Dark and Light Mode*/ +var c="#000"; +var d="#f2f2f2"; +var dislikes="..."; + +if(document.cookie.indexOf("PREF") < 0 || document.cookie.indexOf("f6=") < 0){ +document.cookie.replace( +/(?<=^|;).+?(?=\=|;|$)/g, +name => location.hostname +.split(/\.(?=[^\.]+\.)/) +.reduceRight((acc, val, i, arr) => i ? arr[i]='.'+val+acc : (arr[i]='', arr), '') +.map(domain => document.cookie=`${name}=;max-age=0;path=/;domain=${domain}`) +); +document.cookie="PREF=f6=400&f7=100;"; +window.location.href=window.location.href; +} +if(document.cookie.indexOf("f6=400") > -1){ +c ="#fff";d="rgba(255,255,255,0.1)"; +}else{ +c="#000";d="rgba(0,0,0,0.1)"; +} +var downBtn=``; + + + + + +/*Utils for Deciphers*/ +var utils={ +between:(haystack, left, right) => { +let pos; +if (left instanceof RegExp) { +const match = haystack.match(left); +if (!match) { return ''; } +pos = match.index + match[0].length; +} else { +pos = haystack.indexOf(left); +if (pos === -1) { return ''; } +pos += left.length; +} +haystack = haystack.slice(pos); +pos = haystack.indexOf(right); +if (pos === -1) { return ''; } +haystack = haystack.slice(0, pos); +return haystack; +}, +cutAfterJSON :( mixedJson )=> { +let open, close; +if (mixedJson[0] === '[') { +open = '['; +close = ']'; +} else if (mixedJson[0] === '{') { +open = '{'; +close = '}'; +} +if (!open) { +throw new Error(`Can't cut unsupported JSON (need to begin with [ or { ) but got: ${mixedJson[0]}`); +} +let isString = false; +let isEscaped = false; +let counter = 0; +let i; +for (i = 0; i < mixedJson.length; i++) { +if (mixedJson[i] === '"' && !isEscaped) { +isString = !isString; +continue; +} +isEscaped = mixedJson[i] === '\\' && !isEscaped; +if (isString) continue; +if (mixedJson[i] === open) { +counter++; +} else if (mixedJson[i] === close) { +counter--; +} +if (counter === 0) { +return mixedJson.substr(0, i + 1); +} +} +throw Error("Can't cut unsupported JSON (no matching closing bracket found)"); +}, +cutAfterJS: (mixedJson) => { +let open, close; +const ESCAPING_SEQUENZES = [ +// Strings +{ start: '"', end: '"' }, +{ start: "'", end: "'" }, +{ start: '`', end: '`' }, +// RegeEx +{ start: '/', end: '/', startPrefix: /(^|[[{:;,/])\s?$/ }, +]; +///*}*/ lol + + +if (mixedJson[0] === '[') { +open = '['; +close = ']'; +} else if (mixedJson[0] === '{') { +open = '{'; +close = '}'; +} +if (!open) { +throw new Error(`Can't cut unsupported JSON (need to begin with [ or { ) but got: ${mixedJson[0]}`); +} +let isEscapedObject = null; +let isEscaped = false; +let counter = 0; +let i; +for (i = 0; i < mixedJson.length; i++) { +if (!isEscaped && isEscapedObject !== null && mixedJson[i] === isEscapedObject.end) { +isEscapedObject = null; +continue; +} else if (!isEscaped && isEscapedObject === null) { +for (const escaped of ESCAPING_SEQUENZES) { +if (mixedJson[i] !== escaped.start) continue; +if (!escaped.startPrefix || mixedJson.substring(i - 10, i).match(escaped.startPrefix)) { +isEscapedObject = escaped; +break; +} +} +if (isEscapedObject !== null) { +continue; +} +} +isEscaped = mixedJson[i] === '\\' && !isEscaped; +if (isEscapedObject !== null) continue; +if (mixedJson[i] === open) { +counter++; +} else if (mixedJson[i] === close) { +counter--; +} +if (counter === 0) { +return mixedJson.substring(0, i + 1); +} +} +throw Error("Can't cut unsupported JSON (no matching closing bracket found)"); +} +} + + + +/*Decipher Code , Credits:NODE-YTDL-CORE*/ +var extractFunctions = (body)=> { +const functions = []; +const extractManipulations = caller => { +const functionName = utils.between(caller, `a=a.split("");`, `.`); +if (!functionName) return ''; +const functionStart = `var ${functionName}={`; +const ndx = body.indexOf(functionStart); +if (ndx < 0) return ''; +const subBody = body.slice(ndx + functionStart.length - 1); +return `var ${functionName}=${utils.cutAfterJSON(subBody)}`; +}; +const extractDecipher = () => { +const functionName = utils.between(body, `a.set("alr","yes");c&&(c=`, `(decodeURIC`); +if (functionName && functionName.length) { +const functionStart = `${functionName}=function(a)`; +const ndx = body.indexOf(functionStart); +if (ndx >= 0) { +const subBody = body.slice(ndx + functionStart.length); +let functionBody = `var ${functionStart}${utils.cutAfterJSON(subBody)}`; +functionBody = `${extractManipulations(functionBody)};${functionBody};`; + +ytproDecipher[0]=functionName; +ytproDecipher[1]=functionBody; +} +} +}; +/*This thing made me cry for 2 days*/ +const extractNCode = () => { +//let functionName = utils.between(body, `&&(b=a.get("n"))&&(b=`, `(b)`); + +let functionName = utils.between(body, `&&(b=a.get("n"))&&(b=`, `(b)`) || utils.between(body, `&&(b=String.fromCharCode(110),c=a.get(b))&&(c=`, `(c)`); + +if (functionName.includes('[')) functionName = utils.between(body, `var ${functionName.split('[')[0]}=[`, `]`); +if (functionName && functionName.length) { +const functionStart = `${functionName}=function(a)`; +const ndx = body.indexOf(functionStart); +if (ndx >= 0) { +const subBody = body.slice(ndx + functionStart.length); +const functionBody = `var ${functionStart}${utils.cutAfterJS(subBody)};`; +ytproNCode[0]=functionName; +ytproNCode[1]=functionBody; + + + +} +} +}; + +extractNCode(); +extractDecipher(); +}; + + + +function insertAfter(referenceNode, newNode) {try{referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);}catch{}} + +/*Add Settings Tab*/ +setInterval(()=>{ +if(document.getElementById("setDiv") == null){ +var setDiv=document.createElement("div"); +setDiv.setAttribute("style",` +height:30px;width:30px; +z-index:9999999999; +font-size:22px; +text-align:center;line-height:35px; +`); +setDiv.setAttribute("id","setDiv"); +var svg=document.createElement("div"); +svg.innerHTML=` +`; +setDiv.appendChild(svg); +insertAfter(document.getElementsByTagName("ytm-home-logo")[0],setDiv); + +if(document.getElementById("hSett") != null){ +document.getElementById("hSett").addEventListener("click", +function(ev){ +window.location.hash="settings"; +}); +} +} + + +},50); + + + +/*Fetches da base.js*/ +var scripts = document.getElementsByTagName('script'); +for(var i=0;i 0){ +fetch(scripts[i].src).then((res) => res.text()).then((r) => extractFunctions(r)); +} +} + +/*Dislikes To Locale, Credits: Return YT Dislikes*/ +function getDislikesInLocale(num){ +var nn=num; +if (num < 1000){ +nn = num; +} +else{ +const int = Math.floor(Math.log10(num) - 2); +const decimal = int + (int % 3 ? 1 : 0); +const value = Math.floor(num / 10 ** decimal); +nn= value * 10 ** decimal; +} +let userLocales; +if (document.documentElement.lang) { +userLocales = document.documentElement.lang; +} else if (navigator.language) { +userLocales = navigator.language; +} else { +try { +userLocales = new URL( +Array.from(document.querySelectorAll("head > link[rel='search']")) +?.find((n) => n?.getAttribute("href")?.includes("?locale=")) +?.getAttribute("href") +)?.searchParams?.get("locale"); +} catch { +userLocales = "en"; +} +} +return Intl.NumberFormat(userLocales, { +notation: "compact", +compactDisplay: "short", +}).format(nn); +} + + + +/*Skips the bad part :)*/ +function skipSponsor(){ +var sDiv=document.createElement("div"); +sDiv.setAttribute("style",`height:3px;pointer-events:none;width:100%;background:transparent;position:fixed;z-index:99999999;`) +sDiv.setAttribute("id","sDiv"); +var dur=document.getElementsByClassName('video-stream')[0].duration; + +for(var x in sTime){ +var s1=document.createElement("div"); +var s2=sTime[x]; +s1.setAttribute("style",`height:3px;width:${(100/dur) * (s2[1]-s2[0])}%;background:#0f8;position:fixed;z-index:99999999;left:${(100/dur) * s2[0]}%;`) +sDiv.appendChild(s1); +} +if(document.getElementById("sDiv") == null){ +if(document.getElementsByClassName('YtmChapteredProgressBarHost')[0] != null){ +document.getElementsByClassName('YtmChapteredProgressBarHost')[0].appendChild(sDiv); +}else{ +try{document.getElementsByClassName('YtmProgressBarProgressBarLine')[0].appendChild(sDiv);}catch{} +} +} +} + + + + + +/*Fetch The Dislikes*/ +async function fDislikes(){ +var vID=""; +var Url=new URL(window.location.href); +if(Url.pathname.indexOf("shorts") > -1){ +vID=Url.pathname.substr(8,Url.pathname.length); +} +else if(Url.pathname.indexOf("watch") > -1){ +vID=Url.searchParams.get("v"); +} + + +fetch("https://returnyoutubedislikeapi.com/votes?videoId="+vID) +.then(response => { +return response.json(); +}).then(jsonObject => { +if('dislikes' in jsonObject){ +dislikes=getDislikesInLocale(parseInt(jsonObject.dislikes)); +} +}).catch(error => {}); + +} +fDislikes(); + + +if(window.location.pathname.indexOf("watch") > -1){ + +/*Check For Sponsorships*/ +fetch("https://sponsor.ajay.app/api/skipSegments?videoID="+(new URLSearchParams(window.location.search)).get('v')) +.then(response => { +return response.json(); +}).then(jsonObject => { +for(var x in jsonObject){ +var time=jsonObject[x].segment; +sTime.push(time); +} +}).catch(error => {}); + + + + +/*Skip the Sponsor*/ +document.getElementsByClassName('video-stream')[0].ontimeupdate=()=>{ +var cur=document.getElementsByClassName('video-stream')[0].currentTime; +for(var x in sTime){ +var s2=sTime[x]; +if(Math.floor(cur) == Math.floor(s2[0])){ +if(localStorage.getItem("autoSpn") == "true"){ +document.getElementsByClassName('video-stream')[0].currentTime=s2[1]; +addSkipper(s2[0]); +} +} +} +}; + + +setInterval(skipSponsor,50); + + +} + + + + +if((window.location.pathname.indexOf("watch") > -1) || (window.location.pathname.indexOf("shorts") > -1)){ +var unV=setInterval(() => { +/*Set Orientation*/ + +var v=document.getElementsByClassName('video-stream')[0].getBoundingClientRect(); +if(v.height > v.width){ +Android.fullScreen(true); +} +else{ +Android.fullScreen(false); +} + +/*Unmute The Video*/ + +document.getElementsByClassName('video-stream')[0].muted=false; +if(!document.getElementsByClassName('video-stream')[0].muted){ +clearInterval(unV); +} + +}, 5); + +} + + +/*Add Skip Sponsor Element*/ +function addSkipper(sT){ +var sSDiv=document.createElement("div"); +sSDiv.setAttribute("style",` +height:50px;${(screen.width > screen.height) ? "width:50%;" : "width:80%;"}overflow:auto;background:rgba(130,130,130,.3); +backdrop-filter:blur(6px); +position:absolute;bottom:40px; +line-height:50px; +left:calc(15% / 2 );padding-left:10px;padding-right:10px; +z-index:99999999999999;text-align:center;border-radius:25px; +color:white;text-align:center; +`); +sSDiv.innerHTML=`Skipped Sponsor + + + + + + + + +`; +document.getElementById("player-control-container").appendChild(sSDiv); +setTimeout(()=>{sSDiv.remove();},5000); +} + + +/*Funtion to set Element Styles*/ +function sty(e,v){ +var s={ +display:"flex", +alignItems:"center", +justifyContent:"center", +fontWeight:"550", +height:"65%", +width:"80px", +borderRadius:"20px", +background:d, +fontSize:"12px", +marginRight:"5px", +textAlign:"center" +}; +for(x in s){ +e.style[x]=s[x]; +} +} + +/*The settings tab*/ +async function ytproSettings(){ +var ytpSet=document.createElement("div"); +var ytpSetI=document.createElement("div"); +ytpSet.setAttribute("id","settingsprodiv"); +ytpSetI.setAttribute("id","ssprodivI"); +ytpSet.setAttribute("style",` +height:100%;width:100%;position:fixed;top:0;left:0; +display:flex;justify-content:center; +background:rgba(0,0,0,0.4); +z-index:9999; +`); +ytpSet.addEventListener("click", +function(ev){ +if(!(ev.target == ytpSetI || ytpSetI.contains(ev.target))){ +history.back(); +} +}); + +ytpSetI.setAttribute("style",` +height:65%;width:85%;overflow:auto;background:#0f0f0f; +position:absolute;bottom:20px; +z-index:99999999999999;padding:20px;text-align:center;border-radius:25px;color:white;text-align:center; +`); + +ytpSetI.innerHTML=``; +ytpSetI.innerHTML+=`YT PRO Settings +v${YTProVer} +

+
+
+
+ +
+
+
Autoskip Sponsors
+
+
Auto FitScreen
+
+
Force Zoom
+
+
Hide Shorts
+
+
Made with +♥ by Prateek Chaubey
+

+
Disclaimer: This is an unofficial OSS Youtube Mod , all the logos and brand names are property of Google LLC.
+You can get the source code at https://github.com/prateek-chaubey/YTPRO +

+Report Bugs +
`; + +document.body.appendChild(ytpSet); +ytpSet.appendChild(ytpSetI); + +} + +function searchUrl(x,e){ +if(e.keyCode === 13 || e === "Enter"){ +window.location.href=x.value; +} +} + +function checkUpdates(){ +if(parseFloat(Android.getInfo()) < parseFloat(YTProVer) ){ +updateModel(); +}else{ +alert("Your app is up to date"); +} + +fetch('https://cdn.jsdelivr.net/npm/ytpro', {cache: 'reload'}); +fetch('https://cdn.jsdelivr.net/npm/ytpro/bgplay.js', {cache: 'reload'}); +} + + +/*Set Configration*/ +function sttCnf(x,z,y){ + +/*Way to complex to understand*/ + +if(typeof y == "string"){ + +if(localStorage.getItem(y) != "true"){ +if(z == 1){ +return 'background:rgba(255,255,255,.7);left:-6px;' +}else{ +return 'background:rgba(255,255,255,.1)'; +} +}else{ +if(z == 1){ +return 'background:rgba(255,50,50,1);left:auto;right:-6px;' +}else{ +return 'background:rgba(255,50,50,.5)'; +} +} +} +if(localStorage.getItem(z) == "true"){ +localStorage.setItem(z,"false"); +x.style.background="rgba(255,255,255,.1)"; +x.children[0].style.left="-6px"; +x.children[0].style.background="rgba(255,255,255,.7)"; +} +else{ +localStorage.setItem(z,"true"); +x.style.background="rgba(255,50,50,.5)"; +x.children[0].style.left="auto"; +x.children[0].style.right="-6px"; +x.children[0].style.background="rgba(255,50,50,7)"; +} + +if(localStorage.getItem("fzoom") == "false"){ +document.getElementsByName("viewport")[0].setAttribute("content","width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,"); +}else{ +document.getElementsByName("viewport")[0].setAttribute("content",""); +} + +} + + +/*Format File Size*/ +function formatFileSize(x){ +var s=parseInt(x); +let ss = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'] +for (var i=0; s > 1024; i++) s /= 1024; +return ` | ${s.toFixed(1)} ${ss[i]}`; +} + +/*Video Downloader*/ +async function ytproDownVid(){ +var ytproDown=document.createElement("div"); +var ytproDownDiv=document.createElement("div"); +ytproDownDiv.setAttribute("id","downytprodiv"); +ytproDown.setAttribute("id","outerdownytprodiv"); +ytproDown.setAttribute("style",` +height:100%;width:100%;position:fixed;top:0;left:0; +display:flex;justify-content:center; +background:rgba(0,0,0,0.4); +z-index:99999999999999; +`); +ytproDown.addEventListener("click", +function(ev){ +if(ev.target != ytproDownDiv ){ +history.back(); +} +}); + +ytproDownDiv.setAttribute("style",` +height:50%;width:85%;overflow:auto;background:#0f0f0f; +position:absolute;bottom:20px; +z-index:99999999999999;padding:20px;text-align:center;border-radius:25px;color:white;text-align:center; +`); + +document.body.appendChild(ytproDown); +ytproDown.appendChild(ytproDownDiv); + +var id=""; + +if(window.location.pathname.indexOf("shorts") > -1){ +id=window.location.pathname.substr(8,window.location.pathname.length); +} +else{ +id=new URLSearchParams(window.location.search).get("v"); +} + + + +ytproDownDiv.innerHTML="Loading..."; + +var info=await fetch("https://youtube-downloader.deno.dev/video?id="+id); +info=await info.json(); + +var thumb=info.video.thumbnail?.thumbnails; +var vids=info.stream.formats; +var avids=info.stream.adaptiveFormats; +var cap=info.captions?.playerCaptionsTracklistRenderer?.captionTracks; +var t=info.video.title.replaceAll("|","").replaceAll("\\","").replaceAll("?","").replaceAll("*","").replaceAll("<","").replaceAll("/","").replaceAll(":","").replaceAll('"',"").replaceAll(">",""); +ytproDownDiv.innerHTML=""; + + + +ytproDownDiv.innerHTML+="Select Avilaible Formats