2016-05-28 12:15:37 +00:00
|
|
|
// ==UserScript==
|
|
|
|
// @name MonsterLyrics button
|
2016-05-28 12:16:25 +00:00
|
|
|
// @namespace https://github.com/NorbiPeti/
|
2016-06-10 15:11:43 +00:00
|
|
|
// @version 0.6
|
2016-05-28 12:15:37 +00:00
|
|
|
// @description Creates a button that searches for a lyrics video!
|
|
|
|
// @author NorbiPeti
|
2016-06-10 15:11:43 +00:00
|
|
|
// @match https://www.youtube.com/*
|
|
|
|
// @include http://www.youtube.com/*
|
2016-05-31 20:17:45 +00:00
|
|
|
// @include https://www.twitch.tv/Monstercat*
|
|
|
|
// @include https://live.monstercat.com/*
|
2016-05-28 12:15:37 +00:00
|
|
|
// @grant none
|
|
|
|
// ==/UserScript==
|
|
|
|
|
2016-05-31 20:17:45 +00:00
|
|
|
window.lasttitle="";
|
|
|
|
|
2016-06-10 15:11:43 +00:00
|
|
|
function AddYouTube(addtries) {
|
2016-06-01 20:45:42 +00:00
|
|
|
var title=document.getElementById("eow-title");
|
|
|
|
if(title!==null)
|
|
|
|
title=title.title;
|
2016-06-10 15:11:43 +00:00
|
|
|
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
|
|
|
|
}
|
2016-06-02 17:03:53 +00:00
|
|
|
if(title!==null)
|
|
|
|
window.lasttitle=title;
|
|
|
|
var cont=null;
|
2016-06-10 15:11:43 +00:00
|
|
|
if(title==window.lasttitle && addtries<10)
|
2016-05-31 20:17:45 +00:00
|
|
|
{
|
2016-06-10 15:11:43 +00:00
|
|
|
addtries++;
|
|
|
|
window.setTimeout(function(){AddYouTube(addtries);}, 100);
|
|
|
|
return;
|
2016-05-31 20:17:45 +00:00
|
|
|
}
|
2016-06-10 15:11:43 +00:00
|
|
|
cont=document.getElementById("watch7-subscription-container");
|
2016-06-01 20:45:42 +00:00
|
|
|
if(cont===null)
|
2016-05-31 20:17:45 +00:00
|
|
|
return;
|
2016-06-10 15:11:43 +00:00
|
|
|
if(document.getElementById("mlbutton")!==null)
|
|
|
|
return;
|
2016-06-01 20:45:42 +00:00
|
|
|
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>";
|
2016-06-10 15:11:43 +00:00
|
|
|
//TODO: Show Lyrics button
|
2016-05-31 20:17:45 +00:00
|
|
|
}
|
2016-05-28 12:15:37 +00:00
|
|
|
|
2016-06-10 15:11:43 +00:00
|
|
|
function AddTwitch() {
|
|
|
|
var twitchmsg=null;
|
2016-06-01 20:45:42 +00:00
|
|
|
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")
|
|
|
|
{
|
2016-06-10 15:11:43 +00:00
|
|
|
twitchmsg=namecontTwitch[i].getElementsByClassName("message")[0];
|
2016-06-01 20:45:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if((namecont===null || namecont.innerHTML.indexOf("Monstercat")==-1) && (Twitch===null))
|
2016-05-28 13:45:36 +00:00
|
|
|
return;
|
2016-06-10 15:11:43 +00:00
|
|
|
var cont=""; //TODO
|
|
|
|
if(cont===null)
|
2016-05-28 12:15:37 +00:00
|
|
|
return;
|
2016-06-10 15:11:43 +00:00
|
|
|
if(twitchmsg!==null && twitchmsg!=="")
|
|
|
|
window.lasttitle=twitchmsg.innerHTML.replace("Now Playing: ", "").replace(/ \- Listen now: .+/g, "");
|
2016-06-01 20:45:42 +00:00
|
|
|
if(document.getElementById("mlbutton")!==null)
|
|
|
|
return;
|
2016-06-10 15:11:43 +00:00
|
|
|
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("!");
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2016-06-02 17:03:53 +00:00
|
|
|
} //TODO: Add for every platform, not just YouTube and add tracklist support
|
2016-05-28 12:15:37 +00:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
AddIfChanged();
|
2016-05-28 12:41:43 +00:00
|
|
|
window.setInterval(AddIfChanged, 1000);
|
2016-05-28 12:15:37 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
window.showLyrics=function()
|
|
|
|
{
|
2016-06-01 20:45:42 +00:00
|
|
|
//var title=document.getElementById("eow-title").title;
|
2016-06-02 17:03:53 +00:00
|
|
|
var title=window.lasttitle;
|
2016-05-28 12:15:37 +00:00
|
|
|
title=encodeURI(title.replace(/\[[^\[\]]+\]/g, "")).replace("&", ""); //Tested on: Pegboard Nerds & NGHTMRE - Superstar (ft. Krewella)
|
|
|
|
window.location.href="https://www.youtube.com/user/monstercatmedialyric/search?query="+title;
|
|
|
|
};
|