forked from alastair/tomahawk-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiql_playdar.user.js
120 lines (106 loc) · 4.04 KB
/
fiql_playdar.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// ==UserScript==
// @name Fiql playdar
// @namespace http://jherskowitz.github.com
// @include http://fiql.com/playlists/*
// @include http://www.fiql.com/plalists/*
// ==/UserScript==
// Catch console output. From firebugx.js
if (!window.console || !console.firebug) {
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
window.console = {};
for (var i = 0; i < names.length; ++i) {
window.console[names[i]] = function() {};
}
}
function load_script (url) {
// Load the playdar.js
var s = document.createElement('script');
s.src = url;
document.getElementsByTagName("head")[0].appendChild(s);
}
var playdar_web_host = "www.playdar.org";
// same js is served, this is just for log-grepping ease.
load_script('http://playdarjs.org/playdar.js?greasemonkey');
load_script('http://' + playdar_web_host + '/static/soundmanager2-nodebug-jsmin.js?greasemonkey');
function GM_wait() {
Playdar = unsafeWindow.Playdar;
soundManager = unsafeWindow.soundManager;
if (typeof Playdar == 'undefined' || typeof soundManager == 'undefined') {
window.setTimeout(GM_wait, 100);
} else {
setup_playdar();
}
}
GM_wait(); // wait for playdar.js to load.
function setup_playdar () {
Playdar.setupClient({
onStat: function (detected) {
if (detected) {
console.debug('Playdar detected');
} else {
console.debug('Playdar unavailable');
}
},
onAuth: function () {
console.debug('Access to Playdar authorised');
do_search();
},
onAuthClear: function () {
console.debug('User revoked authorisation');
}
});
soundManager.url = 'http://' + playdar_web_host + '/static/soundmanager2_flash9.swf';
soundManager.flashVersion = 9;
soundManager.onload = function () {
Playdar.setupPlayer(soundManager);
Playdar.client.go();
};
};
function start_status (qid, node) {
var status = document.createElement('span');
status.id = qid;
status.style.border = 0;
status.style.margin = "0 0 0 0";
status.style.backgroundRepeat = "no-repeat";
status.style.backgroundImage = 'url("http://' + playdar_web_host + '/static/spinner_10px.gif")';
status.style.color = "#fff";
status.style.width = "13px";
status.style.height = "13px";
status.style.textAlign = "center";
status.style.fontSize = "9px";
status.innerHTML = " ";
var parent = node.parentNode;
parent.insertBefore(status, node);
}
function do_search () {
$("div.table-track-row").each(function () {
var artistName = $(this).children('span.track-artist').children('a').text();
var trackName = $(this).children('span.track-song').children('a').text();
// console.debug(artistName);
// console.debug(releaseName);
var qid = Playdar.Util.generate_uuid();
start_status(qid, anchor);
Playdar.client.register_results_handler(results_handler, qid);
// console.debug("artist: "+ artistName + ", release: " + releaseName + ", track: " + trackName);
Playdar.client.resolve(artistName, trackName, releaseName, qid);
}
};
var results_handler = function (response, final_answer) {
if (final_answer) {
var element = document.getElementById(response.qid);
element.style.backgroundImage = 'none';
if (response.results.length) {
var sid = response.results[0].sid;
Playdar.player.register_stream(response.results[0]);
element.innerHTML = "<a href=\"#\">♫ </a>";
element.addEventListener('click', function(event) {
Playdar.player.play_stream(sid);
event.stopPropagation();
event.preventDefault();
}, true);
} else {
element.style.color = "#000";
element.innerHTML = "× ";
}
}
};