Added experimental Twitch support

This commit is contained in:
Norbi Peti 2016-06-01 22:45:42 +02:00
parent 06f18de15a
commit ab2005e27e

View file

@ -1,7 +1,7 @@
// ==UserScript==
// @name MonsterLyrics button
// @namespace https://github.com/NorbiPeti/
// @version 0.3
// @version 0.4
// @description Creates a button that searches for a lyrics video!
// @author NorbiPeti
// @match https://www.youtube.com/
@ -11,36 +11,56 @@
// @grant none
// ==/UserScript==
window.lasturl="";
window.lasttitle="";
window.addtries=0;
window.twitchmsg="";
function Add() {
var title=document.getElementById("eow-title").title;
if(window.location.href==window.lasturl)
var title=document.getElementById("eow-title");
if(title!==null)
title=title.title;
if(document.getElementById("mlbutton")!==null)
return;
if(title==lasttitle && window.lasttries<10)
if(window.location.href.indexOf("youtube.com")!=-1 && title==lasttitle && window.lasttries<10)
{
window.addtries++;
window.setTimeout(Add, 100);
return;
}
var cont=document.getElementById("watch7-subscription-container");
if(cont===null)
cont=window.twitchmsg;
if(cont===null)
return;
cont.innerHTML+="<button type=\"button\" onClick=\"window.showLyrics()\" 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>";
window.lasturl=window.location.href; //TODO: Show Lyrics button
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
}
function AddIfChanged()
{
var namecont=document.getElementById("watch7-user-header");
if(namecont===null || namecont.innerHTML.indexOf("Monstercat")==-1)
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;
if(window.location.href==window.lasturl)
return;
if(document.getElementById("mlbutton")!==null)
return;
console.log("Twitch");
window.twitchmsg=Twitch;
var cont=document.getElementById("watch7-subscription-container");
if(cont===null)
if(cont===null && Twitch===null)
return;
window.setTimeout(Add, 100);
} //TODO: Add for every platform, not just YouTube
@ -48,14 +68,14 @@ function AddIfChanged()
(function() {
'use strict';
// Your code here...
AddIfChanged();
window.setInterval(AddIfChanged, 1000);
})();
window.showLyrics=function()
{
var title=document.getElementById("eow-title").title;
//var title=document.getElementById("eow-title").title;
var title=window.lastitle;
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;
};