[YouTube to Invidious] reorganize code
This commit is contained in:
parent
730ca49e53
commit
80a8b19fd5
@ -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();
|
||||
function link(){
|
||||
for(let i=0;i<links.length;i++){
|
||||
let url=new URL(links[i].href.match(ytdomains)[0]);
|
||||
url.hostname=instance;
|
||||
links[i].href=url;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
observer.observe(document.body,{childList:true,subtree:true});
|
||||
|
||||
function embed(){
|
||||
for(let i=0;i<frames.length;i++){
|
||||
@ -105,39 +83,6 @@ function embed(){
|
||||
}
|
||||
}
|
||||
|
||||
function thumb(){
|
||||
for(let i=0;i<thumbs.length;i++){
|
||||
let url=new URL(thumbs[i].src.match(ytdomains)[0]);
|
||||
url.hostname=instance;
|
||||
thumbs[i].src=url;
|
||||
}
|
||||
}
|
||||
|
||||
function link(){
|
||||
for(let i=0;i<links.length;i++){
|
||||
let url=new URL(links[i].href.match(ytdomains)[0]);
|
||||
url.hostname=instance;
|
||||
links[i].href=url;
|
||||
}
|
||||
}
|
||||
|
||||
function addbtn(){
|
||||
for(let i=0;i<title.length;i++){
|
||||
let btn=document.createElement('a');
|
||||
btn.innerHTML='<h2>Watch on '+instance+'</h2>';
|
||||
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<frames.length;k++){
|
||||
@ -177,7 +122,69 @@ function ythref(el){
|
||||
return(decodeURIComponent(el.href).match(ytdomains));
|
||||
}
|
||||
|
||||
function statuscheck(){
|
||||
// Console Feedback
|
||||
console.log("%cUSERSCRIPT | " + GM_info.script.name + " " + GM_info.script.version + " | successfully initialized", consoleCSS);
|
||||
function thumb(){
|
||||
for(let i=0;i<thumbs.length;i++){
|
||||
let url=new URL(thumbs[i].src.match(ytdomains)[0]);
|
||||
url.hostname=instance;
|
||||
thumbs[i].src=url;
|
||||
}
|
||||
}
|
||||
|
||||
function redir(){
|
||||
let url=new URL(window.location.href);
|
||||
url.hostname=instance;
|
||||
location.href=url;
|
||||
}
|
||||
|
||||
function addbtn(){
|
||||
for(let i=0;i<title.length;i++){
|
||||
let btn=document.createElement('a');
|
||||
btn.innerHTML='<h2>Watch on '+instance+'</h2>';
|
||||
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});
|
||||
|
Loading…
x
Reference in New Issue
Block a user