MonsterLyricsButton/MLButton.user.js

82 lines
3 KiB
JavaScript
Raw Normal View History

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-01 20:45:42 +00:00
// @version 0.4
2016-05-28 12:15:37 +00:00
// @description Creates a button that searches for a lyrics video!
// @author NorbiPeti
// @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="";
window.addtries=0;
2016-06-01 20:45:42 +00:00
window.twitchmsg="";
2016-05-31 20:17:45 +00:00
function Add() {
2016-06-01 20:45:42 +00:00
var title=document.getElementById("eow-title");
if(title!==null)
title=title.title;
if(document.getElementById("mlbutton")!==null)
2016-05-31 20:17:45 +00:00
return;
2016-06-01 20:45:42 +00:00
if(window.location.href.indexOf("youtube.com")!=-1 && title==lasttitle && window.lasttries<10)
2016-05-31 20:17:45 +00:00
{
window.addtries++;
window.setTimeout(Add, 100);
return;
}
var cont=document.getElementById("watch7-subscription-container");
2016-06-01 20:45:42 +00:00
if(cont===null)
cont=window.twitchmsg;
2016-05-31 20:17:45 +00:00
if(cont===null)
return;
2016-06-01 20:45:42 +00:00
window.lasttitle=window.twitchmsg.innerHTML.replace("Now Playing: ", "").replace(/ \- Listen now: .+/g, "");
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("!");
//window.lasturl=window.location.href; //TODO: Show Lyrics button
2016-05-31 20:17:45 +00:00
}
2016-05-28 12:15:37 +00:00
function AddIfChanged()
{
var namecont=document.getElementById("watch7-user-header");
2016-06-01 20:45:42 +00:00
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
{
if(typeof namecontTwitch[i] != 'undefined' && namecontTwitch[i].getElementsByClassName("from")[0].innerHTML=="Monstercat")
{
Twitch=namecontTwitch[i].getElementsByClassName("message")[0];
break;
}
}
if((namecont===null || namecont.innerHTML.indexOf("Monstercat")==-1) && (Twitch===null))
return;
2016-05-28 12:15:37 +00:00
if(window.location.href==window.lasturl)
return;
2016-06-01 20:45:42 +00:00
if(document.getElementById("mlbutton")!==null)
return;
console.log("Twitch");
window.twitchmsg=Twitch;
2016-05-28 12:15:37 +00:00
var cont=document.getElementById("watch7-subscription-container");
2016-06-01 20:45:42 +00:00
if(cont===null && Twitch===null)
2016-05-28 12:15:37 +00:00
return;
2016-05-31 20:17:45 +00:00
window.setTimeout(Add, 100);
2016-05-31 09:17:15 +00:00
} //TODO: Add for every platform, not just YouTube
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;
var title=window.lastitle;
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;
};