From 80a8b19fd552a55bc5bbd0460aaa5834fdbe67ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Wed, 1 Jan 2020 13:30:57 -0500 Subject: [YouTube to Invidious] reorganize code --- scripts-greasemonkey/youtube_to_invidious.user.js | 145 ++++++++++++---------- 1 file changed, 76 insertions(+), 69 deletions(-) diff --git a/scripts-greasemonkey/youtube_to_invidious.user.js b/scripts-greasemonkey/youtube_to_invidious.user.js index 12e3df2..b807431 100644 --- a/scripts-greasemonkey/youtube_to_invidious.user.js +++ b/scripts-greasemonkey/youtube_to_invidious.user.js @@ -34,46 +34,24 @@ let c=1; //set to 0 to disable DASH playback (beta feature) [default 1] let d=1; //set to 0 to disable Invidious proxy [default 1] let e=1; //set to 0 to disable bypass of url shorteners [default 1] -let ytdomains=new RegExp(/http(s|)\:\/\/(m[.]|i[.]|www[.]|img[.]|)(youtu(|be|be-nocookie)|.*ytimg)[.](com|be)\/.*/); +let ytdomains=new RegExp(/http(s|):\/\/(m[.]|i[.]|www[.]|img[.]|)(youtu(|be|be-nocookie)|.*ytimg)[.](com|be)\/.*/); let shorteners=new RegExp(/^http(s|):\/\/(bit.ly|goo.gl|tinyurl.com|t.co|ow.ly|is.gd|buff.ly|deck.ly|su.pr|lnk.co|fur.ly|moourl.com|)\/.*/); let params=new RegExp(/^(autoplay|channel|v|playlist|list)$/); let current=window.location.href.match(ytdomains)===null; let frames,thumbs,links,skip; -if(current){ - frames=Array.prototype.slice.call(document.getElementsByTagName('iframe')).filter(ytel); - thumbs=Array.prototype.slice.call(document.getElementsByTagName('img')).filter(ytel); - if(b==1)links=Array.prototype.slice.call(document.getElementsByTagName('a')).filter(ythref); - if(frames.length>0)embed(); - if(thumbs.length>0)thumb(); - if(links.length>0)link(); - statuscheck(); -}else{ - let title=Array.prototype.slice.call(document.getElementsByTagName('h1')); - addbtn(); +function statuscheck(){ + // Console Feedback + console.log("%cUSERSCRIPT | " + GM_info.script.name + " " + GM_info.script.version + " | successfully initialized", consoleCSS); } -let observer=new MutationObserver(function(mutations){ - mutations.forEach(function(mutation){ - if(current){ - frames=Array.prototype.slice.call(mutation.target.getElementsByTagName('iframe')).filter(ytel); - thumbs=Array.prototype.slice.call(mutation.target.getElementsByTagName('img')).filter(ytel); - if(frames.length>0)embed(); - if(thumbs.length>0)thumb(); - if(b==1){ - links=Array.prototype.slice.call(mutation.target.getElementsByTagName('a')).filter(ythref); - if(links.length>0)link(); - } - }else{ - skip=Array.prototype.slice.call(mutation.target.getElementsByClassName('skipinv')); - if(skip<1){ - title=Array.prototype.slice.call(mutation.target.getElementsByTagName('h1')); - addbtn(); - } - } - }); -}); -observer.observe(document.body,{childList:true,subtree:true}); +function link(){ + for(let i=0;i'; - btn.href='javascript:void(0)'; - btn.onclick=function(){redir();}; - btn.className='skipinv'; - title[i].parentNode.appendChild(btn); - } -} - -function redir(){ - let url=new URL(window.location.href); - url.hostname=instance; - location.href=url; -} - function unshorten(long,short){ frames=Array.prototype.slice.call(document.getElementsByTagName('iframe')); for(let k=0;k'; + btn.href='javascript:void(0)'; + btn.onclick=function(){redir();}; + btn.className='skipinv'; + title[i].parentNode.appendChild(btn); + } +} + +if(current){ + frames=Array.prototype.slice.call(document.getElementsByTagName('iframe')).filter(ytel); + thumbs=Array.prototype.slice.call(document.getElementsByTagName('img')).filter(ytel); + if(b==1)links=Array.prototype.slice.call(document.getElementsByTagName('a')).filter(ythref); + if(frames.length>0){ + embed(); + } + if(thumbs.length>0)thumb(); + if(links.length>0)link(); + statuscheck(); +}else{ + let title=Array.prototype.slice.call(document.getElementsByTagName('h1')); + addbtn(); +} + +let observer=new MutationObserver(function(mutations){ + mutations.forEach(function(mutation){ + if(current){ + frames=Array.prototype.slice.call(mutation.target.getElementsByTagName('iframe')).filter(ytel); + thumbs=Array.prototype.slice.call(mutation.target.getElementsByTagName('img')).filter(ytel); + if(frames.length>0){ + embed(); + } + if(thumbs.length>0){ + thumb(); + } + if(b==1){ + links=Array.prototype.slice.call(mutation.target.getElementsByTagName('a')).filter(ythref); + if(links.length>0)link(); + } + }else{ + skip=Array.prototype.slice.call(mutation.target.getElementsByClassName('skipinv')); + if(skip<1){ + title=Array.prototype.slice.call(mutation.target.getElementsByTagName('h1')); + addbtn(); + } + } + }); +}); + +observer.observe(document.body,{childList:true,subtree:true}); -- cgit v1.2.3