Created
October 31, 2008 16:11
-
-
Save ucnv/21335 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 NoiseMP3.com Player | |
// @namespace http://userscripts.org/users/40991 | |
// @include http://www.noisemp3.com/* | |
// @include http://noisemp3.com/* | |
// @require http://gist.github.com/3242.txt | |
// ==/UserScript== | |
var NoiseMP3Player = { | |
id: 'NoiseMP3Player', | |
shuffle: true, | |
files: [], | |
playing: '', | |
initialize: function() { | |
var self = NoiseMP3Player; | |
self.collect(document); | |
document.addEventListener('DOMNodeInserted', self.collect, false); | |
self.render(); | |
}, | |
collect: function(context) { | |
var self = NoiseMP3Player; | |
context = context.target || context; | |
var l = $X('.//a[contains(@href, "download_mp3.php") and text()="Download"]', context); | |
self.files = self.files.concat(l.map(function(e) { $X('./../../../../../..', e)[0].id = e.href; return e.href })); | |
}, | |
render: function() { | |
var self = NoiseMP3Player; | |
var params = { | |
width: '100%', | |
height: 15, | |
enablejavascript: true, | |
autostart: true, | |
loop: false, | |
panel: 1, | |
src: self.nextFile(), | |
postdomevents: true, | |
type: 'audio/mpeg', | |
kioskmode: false, | |
controller: true, | |
}; | |
var container = document.createElement('div'); | |
container.id = self.id + '-container'; | |
container.style.cssText = 'position:fixed;bottom:0;height:15px;width:100%;background-color:#000;'; | |
var player = unsafeWindow.document.createElement('embed'); | |
player.id = player.name = self.id; | |
(function(o, p) { for(var i in p) o.setAttribute(i, p[i]); })(player, params); | |
container.appendChild(player); | |
document.body.appendChild(container); | |
var id = setInterval(function() { | |
switch(player.GetPluginStatus()) { | |
case 'Playable': | |
case 'Complete': | |
if(player.GetEndTime() > player.GetTime()) break; | |
var next = self.nextFile(); | |
if(!next) clearInterval(id); | |
player.src = next; | |
} | |
}, 60); | |
}, | |
nextFile: function() { | |
var self = NoiseMP3Player; | |
if(document.getElementById(self.playing)) | |
document.getElementById(self.playing).style.backgroundColor = ''; | |
if(self.shuffle) self.playing = self.files.splice(Math.random() * (self.files.length - 1), 1)[0]; | |
else self.playing = self.files.shift(); | |
document.getElementById(self.playing).style.backgroundColor = '#006699'; | |
return self.playing; | |
} | |
}; | |
NoiseMP3Player.initialize(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment