// Playlist
// v0.1
// Copyright (c) 2005, Wayne Burkett
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
// This is a Greasemonkey user script.
// http://greasemonkey.mozdev.org/
// Credits:
// Hublog's Bookmarklet [http://hublog.hubmed.org/archives/001139.html]
// DiveIntoGreasemonkey [http://diveintogreasemonkey.org/patterns/add-css.html]
// Stylegala's Bullet Madness [http://www.stylegala.com/features/bulletmadness/]
// The data: URI Kitchen [http://software.hixie.ch/utilities/cgi/data/data]
// ==UserScript==
// @name Playlist
// @namespace http://dionidium.com/projects/greasemonkey/
// @description Generate an M3U playlist of all the MP3s on a page
// @include *
// ==/UserScript==
function addStyles(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
var i, href, m3u, div, img;
var xpath = '//a[contains(@href, "mp3")]';
var mp3s = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var links = new Array();
for (i = 0; i < mp3s.snapshotLength; i += 1) {
href = mp3s.snapshotItem(i).href;
if (href.match(/\.mp3$/)) { links.push(href); }
}
m3u = links.join('%0A'); // newline
if(!m3u) { return; }
img =
'';
div = document.createElement('div');
div.id = 'gm-playlist';
div.innerHTML = '' + img + '';
window.addEventListener("load",
function() {
document.body.appendChild(div);
}, true
);
addStyles(
'#gm-playlist div, #gm-playlist a,' +
'#gm-playlist a:hover, #gm-playlist a:link {' +
' margin: 0;' +
' padding: 0;' +
' border: 0;' +
' text-decoration: none;' +
'}' +
'#gm-playlist img {' +
' position: fixed;' +
' z-index: 99999;' +
' top: 15px;' +
' right: 15px;' +
' margin: 5px;' +
' padding: 5px;' +
' color: #000;' +
' background-color: #eee;' +
' border: #000 1px solid;' +
'}'
);
// 2005-06-13 - 0.3 - further modified styles
// 2005-06-11 - 0.2 - modified styles
// 2005-06-07 - 0.1 - released