Added experimental Twitch support
This commit is contained in:
parent
06f18de15a
commit
ab2005e27e
1 changed files with 31 additions and 11 deletions
|
@ -1,7 +1,7 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name MonsterLyrics button
|
// @name MonsterLyrics button
|
||||||
// @namespace https://github.com/NorbiPeti/
|
// @namespace https://github.com/NorbiPeti/
|
||||||
// @version 0.3
|
// @version 0.4
|
||||||
// @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/
|
// @match https://www.youtube.com/
|
||||||
|
@ -11,36 +11,56 @@
|
||||||
// @grant none
|
// @grant none
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
window.lasturl="";
|
|
||||||
window.lasttitle="";
|
window.lasttitle="";
|
||||||
window.addtries=0;
|
window.addtries=0;
|
||||||
|
window.twitchmsg="";
|
||||||
|
|
||||||
function Add() {
|
function Add() {
|
||||||
var title=document.getElementById("eow-title").title;
|
var title=document.getElementById("eow-title");
|
||||||
if(window.location.href==window.lasturl)
|
if(title!==null)
|
||||||
|
title=title.title;
|
||||||
|
if(document.getElementById("mlbutton")!==null)
|
||||||
return;
|
return;
|
||||||
if(title==lasttitle && window.lasttries<10)
|
if(window.location.href.indexOf("youtube.com")!=-1 && title==lasttitle && window.lasttries<10)
|
||||||
{
|
{
|
||||||
window.addtries++;
|
window.addtries++;
|
||||||
window.setTimeout(Add, 100);
|
window.setTimeout(Add, 100);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var cont=document.getElementById("watch7-subscription-container");
|
var cont=document.getElementById("watch7-subscription-container");
|
||||||
|
if(cont===null)
|
||||||
|
cont=window.twitchmsg;
|
||||||
if(cont===null)
|
if(cont===null)
|
||||||
return;
|
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.lasttitle=window.twitchmsg.innerHTML.replace("Now Playing: ", "").replace(/ \- Listen now: .+/g, "");
|
||||||
window.lasturl=window.location.href; //TODO: Show Lyrics 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("!");
|
||||||
|
//window.lasturl=window.location.href; //TODO: Show Lyrics button
|
||||||
}
|
}
|
||||||
|
|
||||||
function AddIfChanged()
|
function AddIfChanged()
|
||||||
{
|
{
|
||||||
var namecont=document.getElementById("watch7-user-header");
|
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;
|
return;
|
||||||
if(window.location.href==window.lasturl)
|
if(window.location.href==window.lasturl)
|
||||||
return;
|
return;
|
||||||
|
if(document.getElementById("mlbutton")!==null)
|
||||||
|
return;
|
||||||
|
console.log("Twitch");
|
||||||
|
window.twitchmsg=Twitch;
|
||||||
var cont=document.getElementById("watch7-subscription-container");
|
var cont=document.getElementById("watch7-subscription-container");
|
||||||
if(cont===null)
|
if(cont===null && Twitch===null)
|
||||||
return;
|
return;
|
||||||
window.setTimeout(Add, 100);
|
window.setTimeout(Add, 100);
|
||||||
} //TODO: Add for every platform, not just YouTube
|
} //TODO: Add for every platform, not just YouTube
|
||||||
|
@ -48,14 +68,14 @@ function AddIfChanged()
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Your code here...
|
|
||||||
AddIfChanged();
|
AddIfChanged();
|
||||||
window.setInterval(AddIfChanged, 1000);
|
window.setInterval(AddIfChanged, 1000);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
window.showLyrics=function()
|
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)
|
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;
|
window.location.href="https://www.youtube.com/user/monstercatmedialyric/search?query="+title;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue