[youtube_to_invidious.user.js] change var to let

This commit is contained in:
Jesús 2019-10-12 19:32:28 -05:00
parent e35971bb8e
commit f6d46c96e3
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766

View File

@ -20,23 +20,23 @@
/* jshint esversion: 6 */ /* jshint esversion: 6 */
// set you favorite Invidious instance! (https://github.com/omarroth/invidious/wiki/Invidious-Instances) // set you favorite Invidious instance! (https://github.com/omarroth/invidious/wiki/Invidious-Instances)
var instance = 'invidio.us'; let instance = 'invidio.us';
// Console Style - Debug // Console Style - Debug
var consoleCSS = 'background: #000; color: #00FF00; padding: 0px 7px; border: 1px solid #00FF00; line-height: 16px;'; let consoleCSS = 'background: #000; color: #00FF00; padding: 0px 7px; border: 1px solid #00FF00; line-height: 16px;';
// change script options, default values recommended // change script options, default values recommended
var a=1; //set to 0 to force autoplay off, set to 1 to keep embed's value [default 1] let a=1; //set to 0 to force autoplay off, set to 1 to keep embed's value [default 1]
var b=1; //set to 0 to not replace all youtube links to Invidious [default 1] let b=1; //set to 0 to not replace all youtube links to Invidious [default 1]
var c=1; //set to 0 to disable DASH playback (beta feature) [default 1] let c=1; //set to 0 to disable DASH playback (beta feature) [default 1]
var d=1; //set to 0 to disable Invidious proxy [default 1] let d=1; //set to 0 to disable Invidious proxy [default 1]
var e=1; //set to 0 to disable bypass of url shorteners [default 1] let e=1; //set to 0 to disable bypass of url shorteners [default 1]
var 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)\/.*/);
var 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 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|)\/.*/);
var params=new RegExp(/^(autoplay|channel|v|playlist|list)$/); let params=new RegExp(/^(autoplay|channel|v|playlist|list)$/);
var current=window.location.href.match(ytdomains)===null; let current=window.location.href.match(ytdomains)===null;
var frames,thumbs,links,skip; let frames,thumbs,links,skip;
if(current){ if(current){
frames=Array.prototype.slice.call(document.getElementsByTagName('iframe')).filter(ytel); frames=Array.prototype.slice.call(document.getElementsByTagName('iframe')).filter(ytel);
@ -47,11 +47,11 @@ if(current){
if(links.length>0)link(); if(links.length>0)link();
statuscheck(); statuscheck();
}else{ }else{
var title=Array.prototype.slice.call(document.getElementsByTagName('h1')); let title=Array.prototype.slice.call(document.getElementsByTagName('h1'));
addbtn(); addbtn();
} }
var observer=new MutationObserver(function(mutations){ let observer=new MutationObserver(function(mutations){
mutations.forEach(function(mutation){ mutations.forEach(function(mutation){
if(current){ if(current){
frames=Array.prototype.slice.call(mutation.target.getElementsByTagName('iframe')).filter(ytel); frames=Array.prototype.slice.call(mutation.target.getElementsByTagName('iframe')).filter(ytel);
@ -74,19 +74,19 @@ var observer=new MutationObserver(function(mutations){
observer.observe(document.body,{childList:true,subtree:true}); observer.observe(document.body,{childList:true,subtree:true});
function embed(){ function embed(){
for(var i=0;i<frames.length;i++){ for(let i=0;i<frames.length;i++){
frames[i].style.backgroundColor='rgba(35,35,35,1)'; frames[i].style.backgroundColor='rgba(35,35,35,1)';
frames[i].style.backgroundRepeat='no-repeat'; frames[i].style.backgroundRepeat='no-repeat';
frames[i].style.backgroundPosition='center center'; frames[i].style.backgroundPosition='center center';
frames[i].style.backgroundSize='auto'; frames[i].style.backgroundSize='auto';
for(var j=0;j<frames[i].attributes.length;j++) { for(let j=0;j<frames[i].attributes.length;j++) {
if(frames[i].attributes[j].value.match(ytdomains)){ if(frames[i].attributes[j].value.match(ytdomains)){
var url=new URL(frames[i].attributes[j].value); let url=new URL(frames[i].attributes[j].value);
if(!url.hostname.match(/youtube/)){ if(!url.hostname.match(/youtube/)){
url=new URL(decodeURIComponent(url.href).match(ytdomains)[0]); url=new URL(decodeURIComponent(url.href).match(ytdomains)[0]);
url.searchParams.set('autoplay',0); url.searchParams.set('autoplay',0);
} }
for(var key of url.searchParams.keys()){ for(let key of url.searchParams.keys()){
if(!(key.match(params)))url.searchParams.delete(key); if(!(key.match(params)))url.searchParams.delete(key);
} }
url.hostname=instance; url.hostname=instance;
@ -104,24 +104,24 @@ function embed(){
} }
function thumb(){ function thumb(){
for(var i=0;i<thumbs.length;i++){ for(let i=0;i<thumbs.length;i++){
var url=new URL(thumbs[i].src.match(ytdomains)[0]); let url=new URL(thumbs[i].src.match(ytdomains)[0]);
url.hostname=instance; url.hostname=instance;
thumbs[i].src=url; thumbs[i].src=url;
} }
} }
function link(){ function link(){
for(var i=0;i<links.length;i++){ for(let i=0;i<links.length;i++){
var url=new URL(links[i].href.match(ytdomains)[0]); let url=new URL(links[i].href.match(ytdomains)[0]);
url.hostname=instance; url.hostname=instance;
links[i].href=url; links[i].href=url;
} }
} }
function addbtn(){ function addbtn(){
for(var i=0;i<title.length;i++){ for(let i=0;i<title.length;i++){
var btn=document.createElement('a'); let btn=document.createElement('a');
btn.innerHTML='<h2>Watch on '+instance+'</h2>'; btn.innerHTML='<h2>Watch on '+instance+'</h2>';
btn.href='javascript:void(0)'; btn.href='javascript:void(0)';
btn.onclick=function(){redir();}; btn.onclick=function(){redir();};
@ -131,15 +131,15 @@ function addbtn(){
} }
function redir(){ function redir(){
var url=new URL(window.location.href); let url=new URL(window.location.href);
url.hostname=instance; url.hostname=instance;
location.href=url; location.href=url;
} }
function unshorten(long,short){ function unshorten(long,short){
frames=Array.prototype.slice.call(document.getElementsByTagName('iframe')); frames=Array.prototype.slice.call(document.getElementsByTagName('iframe'));
for(var k=0;k<frames.length;k++){ for(let k=0;k<frames.length;k++){
for(var l=0;l<frames[k].attributes.length;l++) { for(let l=0;l<frames[k].attributes.length;l++) {
if(frames[k].attributes[l].value==long){ if(frames[k].attributes[l].value==long){
frames[k].attributes[l].value=short; frames[k].attributes[l].value=short;
frames=[frames[k]]; frames=[frames[k]];
@ -151,15 +151,15 @@ function unshorten(long,short){
} }
function ytel(el){ function ytel(el){
for(var i=0;i<el.attributes.length;i++){ for(let i=0;i<el.attributes.length;i++){
var val=el.attributes[i].value; let val=el.attributes[i].value;
if(val.substring(0,2)=='//')val='https:'+val; if(val.substring(0,2)=='//')val='https:'+val;
try{val=decodeURIComponent(val);}catch(e){} try{val=decodeURIComponent(val);}catch(e){}
if(val.match(shorteners)&&e==1){ if(val.match(shorteners)&&e==1){
var long=el.attributes[i].value=val; let long=el.attributes[i].value=val;
GM_xmlhttpRequest({ GM_xmlhttpRequest({
method:'GET',url:long,onload:function(response){ method:'GET',url:long,onload:function(response){
var short=response.finalUrl; let short=response.finalUrl;
if(short.match(ytdomains))unshorten(long,short); if(short.match(ytdomains))unshorten(long,short);
} }
}); });