[YouTube to Invidious] remove embed, function is part of Invidious Embed

This commit is contained in:
Jesús 2020-01-01 13:42:10 -05:00
parent 80a8b19fd5
commit c459c65a4d
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766

View File

@ -2,7 +2,7 @@
// @name YouTube to Invidious
// @author OdinBrood, Jesús E.
// @namespace InvidiousRedirect
// @description Scan page for Youtube embeds and urls and replace with Invidious.
// @description Scan page for Youtube urls and replace with Invidious.
// @homepageURL https://libregit.org/heckyel/book/src/branch/master/scripts-greasemonkey
// @include *
// @exclude /^http(s|)://(www[.]|)invidio[.]us/.*$/
@ -35,10 +35,9 @@ 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 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;
let thumbs,links,skip;
function statuscheck(){
// Console Feedback
@ -53,64 +52,11 @@ function link(){
}
}
function embed(){
for(let i=0;i<frames.length;i++){
frames[i].style.backgroundColor='rgba(35,35,35,1)';
frames[i].style.backgroundRepeat='no-repeat';
frames[i].style.backgroundPosition='center center';
frames[i].style.backgroundSize='auto';
for(let j=0;j<frames[i].attributes.length;j++) {
if(frames[i].attributes[j].value.match(ytdomains)){
let url=new URL(frames[i].attributes[j].value);
if(!url.hostname.match(/youtube/)){
url=new URL(decodeURIComponent(url.href).match(ytdomains)[0]);
url.searchParams.set('autoplay',0);
}
for(let key of url.searchParams.keys()){
if(!(key.match(params)))url.searchParams.delete(key);
}
url.hostname=instance;
if(a==1){
if(!url.searchParams.has('autoplay')||url.searchParams.get('autoplay')==='')url.searchParams.set('autoplay',0);
}else{
url.searchParams.set('autoplay',0);
}
if(c==1)url.searchParams.set('quality','dash');
if(d==1)url.searchParams.set('local',true);
frames[i].setAttribute(frames[i].attributes[j].name,url);
}
}
}
}
function unshorten(long,short){
frames=Array.prototype.slice.call(document.getElementsByTagName('iframe'));
for(let k=0;k<frames.length;k++){
for(let l=0;l<frames[k].attributes.length;l++) {
if(frames[k].attributes[l].value==long){
frames[k].attributes[l].value=short;
frames=[frames[k]];
embed();
return;
}
}
}
}
function ytel(el){
for(let i=0;i<el.attributes.length;i++){
let val=el.attributes[i].value;
if(val.substring(0,2)=='//')val='https:'+val;
try{val=decodeURIComponent(val);}catch(e){}
if(val.match(shorteners)&&e==1){
let long=el.attributes[i].value=val;
GM_xmlhttpRequest({
method:'GET',url:long,onload:function(response){
let short=response.finalUrl;
if(short.match(ytdomains))unshorten(long,short);
}
});
}
if(val.match(ytdomains)){
el.attributes[i].value=val;
return true;
@ -148,12 +94,8 @@ function addbtn(){
}
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();
@ -165,11 +107,7 @@ if(current){
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();
}