MonsterLyricsButton/MLButton.user.js

51 lines
1.8 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-05-28 13:47:44 +00:00
// @version 0.2
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/*
// @include https://www.youtube.com/*
2016-05-28 12:15:37 +00:00
// @grant none
// ==/UserScript==
window.lasturl="";
function AddIfChanged()
{
var namecont=document.getElementById("watch7-user-header");
if(namecont===null || namecont.innerHTML.indexOf("Monstercat")==-1)
return;
2016-05-28 12:15:37 +00:00
if(window.location.href==window.lasturl)
return;
var cont=document.getElementById("watch7-subscription-container");
if(cont===null)
return;
2016-05-28 12:41:43 +00:00
window.setTimeout(function() {
if(window.location.href==window.lasturl)
return;
//var cont=document.getElementById("watch7-subscription-container").childNodes[0];
2016-05-28 12:41:43 +00:00
var cont=document.getElementById("watch7-subscription-container");
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\">Show lyrics</button>";
2016-05-28 12:41:43 +00:00
window.lasturl=window.location.href;
}, 2000); //TODO: Detect page load finish
2016-05-28 12:15:37 +00:00
}
(function() {
'use strict';
// Your code here...
AddIfChanged();
2016-05-28 12:41:43 +00:00
window.setInterval(AddIfChanged, 1000);
2016-05-28 12:15:37 +00:00
})();
window.showLyrics=function()
{
var title=document.getElementById("eow-title").title;
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;
};