Added support for tracklists
This commit is contained in:
parent
3f43fafe60
commit
289dedc153
1 changed files with 76 additions and 37 deletions
103
MLButton.user.js
103
MLButton.user.js
|
@ -1,74 +1,113 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name MonsterLyrics button
|
// @name MonsterLyrics button
|
||||||
// @namespace https://github.com/NorbiPeti/
|
// @namespace https://github.com/NorbiPeti/
|
||||||
// @version 0.5
|
// @version 0.6
|
||||||
// @description Creates a button that searches for a lyrics video!
|
// @description Creates a button that searches for a lyrics video!
|
||||||
// @author NorbiPeti
|
// @author NorbiPeti
|
||||||
// @match https://www.youtube.com/watch*
|
// @match https://www.youtube.com/*
|
||||||
// @include http://www.youtube.com/watch*
|
// @include http://www.youtube.com/*
|
||||||
// @include https://www.twitch.tv/Monstercat*
|
// @include https://www.twitch.tv/Monstercat*
|
||||||
// @include https://live.monstercat.com/*
|
// @include https://live.monstercat.com/*
|
||||||
// @grant none
|
// @grant none
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
window.lasttitle="";
|
window.lasttitle="";
|
||||||
window.addtries=0;
|
|
||||||
window.twitchmsg="";
|
|
||||||
|
|
||||||
function Add() {
|
function AddYouTube(addtries) {
|
||||||
var title=document.getElementById("eow-title");
|
var title=document.getElementById("eow-title");
|
||||||
if(title!==null)
|
if(title!==null)
|
||||||
title=title.title;
|
title=title.title;
|
||||||
|
if(title!==null && (title.indexOf("Podcast")!=-1 || title.indexOf("Album")!=-1))
|
||||||
|
{
|
||||||
|
var text=document.getElementById("eow-description").innerText;
|
||||||
|
var regexp=/(\d{1,2}(?::\d{1,2})+) (.+) - (.+)/g;
|
||||||
|
var currenttime=document.getElementsByClassName("video-stream html5-main-video")[0].currentTime;
|
||||||
|
/*var ctime=0;
|
||||||
|
if(currenttime.length==3)
|
||||||
|
{
|
||||||
|
ctime=currenttime[0]*3600;
|
||||||
|
ctime+=currenttime[1]*60;
|
||||||
|
ctime+=currenttime[2]*1;
|
||||||
|
}
|
||||||
|
else if(currenttime.length==2)
|
||||||
|
{
|
||||||
|
ctime=currenttime[0]*60;
|
||||||
|
ctime=currenttime[1]*1;
|
||||||
|
}*/
|
||||||
|
var match = regexp.exec(text);
|
||||||
|
var lastmatch=match;
|
||||||
|
var lasttime=0;
|
||||||
|
while(match!==null)
|
||||||
|
{
|
||||||
|
var spl=match[1].split(":");
|
||||||
|
var time=0;
|
||||||
|
if(spl.length==3)
|
||||||
|
{
|
||||||
|
time=spl[0]*3600;
|
||||||
|
time+=spl[1]*60;
|
||||||
|
time+=spl[2]*1;
|
||||||
|
}
|
||||||
|
else if(spl.length==2)
|
||||||
|
{
|
||||||
|
time=spl[0]*60;
|
||||||
|
time=spl[1]*1;
|
||||||
|
}
|
||||||
|
//console.log("Time: "+time+" CTime: "+currenttime+" LastTime: "+lasttime);
|
||||||
|
if(time>currenttime && lasttime<currenttime)
|
||||||
|
break;
|
||||||
|
lastmatch=match;
|
||||||
|
lasttime=time;
|
||||||
|
match = regexp.exec(text);
|
||||||
|
}
|
||||||
|
title=lastmatch[2]+" - "+lastmatch[3]; //TODO
|
||||||
|
}
|
||||||
if(title!==null)
|
if(title!==null)
|
||||||
window.lasttitle=title;
|
window.lasttitle=title;
|
||||||
if(document.getElementById("mlbutton")!==null)
|
|
||||||
return;
|
|
||||||
var cont=null;
|
var cont=null;
|
||||||
if(window.location.href.indexOf("youtube.com")!=-1)
|
if(title==window.lasttitle && addtries<10)
|
||||||
{
|
{
|
||||||
if(title==lasttitle && window.lasttries<10)
|
addtries++;
|
||||||
{
|
window.setTimeout(function(){AddYouTube(addtries);}, 100);
|
||||||
window.addtries++;
|
|
||||||
window.setTimeout(Add, 100);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cont=document.getElementById("watch7-subscription-container");
|
cont=document.getElementById("watch7-subscription-container");
|
||||||
}
|
|
||||||
if(cont===null)
|
|
||||||
cont=window.twitchmsg;
|
|
||||||
if(cont===null)
|
if(cont===null)
|
||||||
return;
|
return;
|
||||||
if(window.twitchmsg!==null && window.twitchmsg!=="")
|
if(document.getElementById("mlbutton")!==null)
|
||||||
window.lasttitle=window.twitchmsg.innerHTML.replace("Now Playing: ", "").replace(/ \- Listen now: .+/g, "");
|
return;
|
||||||
cont.innerHTML+="<button type=\"button\" onClick=\"window.showLyrics()\" id=\"mlbutton\" class=\"yt-uix-button yt-uix-button-size-default yt-uix-button-subscribed-branded no-icon-markup yt-uix-subscription-button yt-can-buffer hover-enabled\">Lyrics video</button>";
|
cont.innerHTML+="<button type=\"button\" onClick=\"window.showLyrics()\" id=\"mlbutton\" class=\"yt-uix-button yt-uix-button-size-default yt-uix-button-subscribed-branded no-icon-markup yt-uix-subscription-button yt-can-buffer hover-enabled\">Lyrics video</button>";
|
||||||
console.log("!");
|
//TODO: Show Lyrics button
|
||||||
//window.lasturl=window.location.href; //TODO: Show Lyrics button
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function AddIfChanged()
|
function AddTwitch() {
|
||||||
{
|
var twitchmsg=null;
|
||||||
var namecont=document.getElementById("watch7-user-header");
|
|
||||||
var namecontTwitch=document.getElementsByClassName("chat-line");
|
|
||||||
var Twitch=null;
|
|
||||||
for(var i=namecontTwitch.length-1; i>=0; i--) //Reminder: Don't put i++ in a supposedly decrementing loop... It's hard to debug
|
for(var i=namecontTwitch.length-1; i>=0; i--) //Reminder: Don't put i++ in a supposedly decrementing loop... It's hard to debug
|
||||||
{
|
{
|
||||||
if(typeof namecontTwitch[i] != 'undefined' && namecontTwitch[i].getElementsByClassName("from")[0].innerHTML=="Monstercat")
|
if(typeof namecontTwitch[i] != 'undefined' && namecontTwitch[i].getElementsByClassName("from")[0].innerHTML=="Monstercat")
|
||||||
{
|
{
|
||||||
Twitch=namecontTwitch[i].getElementsByClassName("message")[0];
|
twitchmsg=namecontTwitch[i].getElementsByClassName("message")[0];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((namecont===null || namecont.innerHTML.indexOf("Monstercat")==-1) && (Twitch===null))
|
if((namecont===null || namecont.innerHTML.indexOf("Monstercat")==-1) && (Twitch===null))
|
||||||
return;
|
return;
|
||||||
if(window.location.href==window.lasturl)
|
var cont=""; //TODO
|
||||||
|
if(cont===null)
|
||||||
return;
|
return;
|
||||||
|
if(twitchmsg!==null && twitchmsg!=="")
|
||||||
|
window.lasttitle=twitchmsg.innerHTML.replace("Now Playing: ", "").replace(/ \- Listen now: .+/g, "");
|
||||||
if(document.getElementById("mlbutton")!==null)
|
if(document.getElementById("mlbutton")!==null)
|
||||||
return;
|
return;
|
||||||
window.twitchmsg=Twitch;
|
cont.innerHTML+="<button type=\"button\" onClick=\"window.showLyrics()\" id=\"mlbutton\" class=\"yt-uix-button yt-uix-button-size-default yt-uix-button-subscribed-branded no-icon-markup yt-uix-subscription-button yt-can-buffer hover-enabled\">Lyrics video</button>";
|
||||||
var cont=document.getElementById("watch7-subscription-container");
|
console.log("!");
|
||||||
if(cont===null && Twitch===null)
|
}
|
||||||
return;
|
|
||||||
window.setTimeout(Add, 100);
|
function AddIfChanged() //...and update track text
|
||||||
|
{
|
||||||
|
if(window.location.href.indexOf("youtube.com")!=-1)
|
||||||
|
window.setTimeout(function(){AddYouTube(0);}, 100);
|
||||||
|
else if(window.location.href.indexOf("live.monstercat.com")!=-1 || window.location.href.indexOf("twitch.tv")!=-1)
|
||||||
|
window.setTimeout(function(){AddTwitch();}, 100);
|
||||||
} //TODO: Add for every platform, not just YouTube and add tracklist support
|
} //TODO: Add for every platform, not just YouTube and add tracklist support
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
Loading…
Reference in a new issue