All pastes #577327 Raw Edit

Untitled

public text v1 · immutable
·published 2007-06-19 21:15 UTC
rendered paste body
// ==UserScript==
// @name           emusic inline player
// @namespace      http://michaeldehaan.net/
// @description    Version 0.01.  Converts emusic links to use an open source in-browser flash player instead of your configured m3u player (like iTunes).  http://musicplayer.sourceforge.net/. This script licensed GPL v2 or later
// ==/UserScript==

// derived from and much credit to:
//Emusic Player
// @namespace      http://www.slothlovechunk.org/greasemonkey
// @description    Version: 0.3 .  Use a tiny flash player to play track samples instead of itunes/etc.  Written by Dana Powers @ gmail.com.  Based loosely off the del.icio.us playtagger.  I provide this to you under the terms of the GNU GPL : http://www.gnu.org/licenses/gpl.txt .
// @include        http://www.emusic.com/*
//
// basically the only difference is mine is modified to use the OSS player versus
// the sloth player :)


EP = {
	playimg: null,
	player: null,
	go: function() {
		var all = document.getElementsByTagName('a')
		for (var i = 0, o; o = all[i]; i++) {
			if(o.href.match(/m3u\/song/i)) {
				var img = o.getElementsByTagName('img')[0]
				img.addEventListener('click', EP.makeToggle(img, o.href), true)
				img.setAttribute('srcorig', img.src)
				img.style.cursor = 'pointer'
				o.parentNode.insertBefore(img, o)
				o.parentNode.removeChild(o)
	}}},
	toggle: function(img, url) {
		if (EP.playimg == img) EP.destroy()
		else {
			if (EP.playimg) EP.destroy()
			img.src = 'http://www.slothlovechunk.org/stop.gif'; EP.playimg = img;
			GM_log("sending XMLHttpRequest");
			var req = new XMLHttpRequest()
			req.open("GET", url, false)
			req.send(null)
			GM_log("state: " + req.readyState);
			GM_log("status: " + req.status);
			GM_log("response: " + req.responseText);
			GM_log("track: " + req.responseText.replace(/#.*/g, '').replace(/\r?\n?/g,''));
			EP.player = document.createElement('span')


			EP.player.innerHTML = 
'<object type="application/x-shockwave-flash" data="' + 
bigp + ' height="17" width="17"><param name="movie" value="' + bigp + 
'"> no flash</object>' 

			img.parentNode.insertBefore(EP.player, img.nextSibling)
	}},
	destroy: function() {
		EP.playimg.src = EP.playimg.getAttribute('srcorig')
		EP.playimg = null
		EP.player.removeChild(EP.player.firstChild)
		EP.player.parentNode.removeChild(EP.player)
		EP.player = null
	},
	makeToggle: function(img, url) { return function(){ EP.toggle(img, url) }}
}

EP.go();