Created
October 5, 2016 19:12
-
-
Save dorukcan/dd99c922862e97c7808fbfbf1a91a997 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name YouSpotify | |
// @author doruk | |
// @description Adds a play on spotify button | |
// @include http://*.youtube.com/watch?*v=* | |
// @include http://*.youtube.com/watch#!*v=* | |
// @include http://youtube.com/watch?*v=* | |
// @include http://youtube.com/watch?v=* | |
// @include http://youtube.com/watch#!*v=* | |
// @include http://www.youtube.com/user/* | |
// @include https://*.youtube.com/watch?*v=* | |
// @include https://*.youtube.com/watch#!*v=* | |
// @include https://youtube.com/watch?*v=* | |
// @include https://youtube.com/watch?v=* | |
// @include https://youtube.com/watch#!*v=* | |
// @include https://www.youtube.com/user/* | |
// @include http://*.youtube.com/watch%3F*v=* | |
// @version 1 | |
// ==/UserScript== | |
var title = document.getElementById("eow-title").innerText.replace('/\([^)]*\)/', ""); | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp.onreadystatechange = function() { | |
if (xmlhttp.readyState == XMLHttpRequest.DONE ) { | |
if(xmlhttp.status == 200){ | |
var data = JSON.parse(xmlhttp.responseText); | |
var id = data["tracks"]["items"][0]["id"]; | |
var e = document.createElement('iframe'); | |
e.src = "https://embed.spotify.com/?uri=spotify:track:" + id; | |
e.width = "100%"; | |
e.height = 80; | |
e.frameborder = 0; | |
e.allowtransparency = true; | |
document.getElementById("watch-description-clip").insertBefore(e, document.getElementById("watch-description-clip").childNodes[0]); | |
} | |
else { | |
console.log('something else other than 200 was returned. code: ' + xmlhttp.status); | |
} | |
} | |
} | |
xmlhttp.open("GET", "https://api.spotify.com/v1/search?q=" + title + "&type=track", true); | |
xmlhttp.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment