Fixed stuff

This commit is contained in:
Norbi Peti 2016-06-02 19:03:53 +02:00
parent ab2005e27e
commit 3f43fafe60

View file

@ -1,11 +1,11 @@
// ==UserScript== // ==UserScript==
// @name MonsterLyrics button // @name MonsterLyrics button
// @namespace https://github.com/NorbiPeti/ // @namespace https://github.com/NorbiPeti/
// @version 0.4 // @version 0.5
// @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/watch*
// @include http://www.youtube.com/* // @include http://www.youtube.com/watch*
// @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
@ -19,19 +19,26 @@ function Add() {
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)
window.lasttitle=title;
if(document.getElementById("mlbutton")!==null) if(document.getElementById("mlbutton")!==null)
return; return;
if(window.location.href.indexOf("youtube.com")!=-1 && title==lasttitle && window.lasttries<10) var cont=null;
if(window.location.href.indexOf("youtube.com")!=-1)
{
if(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"); cont=document.getElementById("watch7-subscription-container");
}
if(cont===null) if(cont===null)
cont=window.twitchmsg; cont=window.twitchmsg;
if(cont===null) if(cont===null)
return; return;
if(window.twitchmsg!==null && window.twitchmsg!=="")
window.lasttitle=window.twitchmsg.innerHTML.replace("Now Playing: ", "").replace(/ \- Listen now: .+/g, ""); 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>"; 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("!"); console.log("!");
@ -57,13 +64,12 @@ function AddIfChanged()
return; return;
if(document.getElementById("mlbutton")!==null) if(document.getElementById("mlbutton")!==null)
return; return;
console.log("Twitch");
window.twitchmsg=Twitch; window.twitchmsg=Twitch;
var cont=document.getElementById("watch7-subscription-container"); var cont=document.getElementById("watch7-subscription-container");
if(cont===null && Twitch===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 and add tracklist support
(function() { (function() {
'use strict'; 'use strict';
@ -75,7 +81,7 @@ function AddIfChanged()
window.showLyrics=function() window.showLyrics=function()
{ {
//var title=document.getElementById("eow-title").title; //var title=document.getElementById("eow-title").title;
var title=window.lastitle; var title=window.lasttitle;
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;
}; };