-
Notifications
You must be signed in to change notification settings - Fork 4
/
hypem.js
65 lines (61 loc) · 2.74 KB
/
hypem.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
// ==UserScript==
// @name Hype Machine direct download links v3
// @author @tonyskn @obmas @blissofbeing
// @description Add download links next to tracks on The Hype Machine.
// @include http://hypem.com/*
// ==/UserScript==
//
// Orginal Script by @tonyskn
// Modified by @obmas
// I got rid of the hot keys and the embeded icon. This now adds (Download) next to the track and attributes to work with the DownThemAll plugin.
// Modified by @blissofbeing
// Replaced Protoype code with pure JS or jQuery to fix Aug 25 2011 update on hypem.com. Removed un-needed code.
//GM_log("fired");
var TrackList;
var TrackElements;
var SelectedTrack;
function addLinks() {
// GM_log('addLinks');
TrackList = unsafeWindow.trackList[document.location.href];
if (TrackList == undefined || TrackList.length < 1) {
//GM_log('delay');
unsafeWindow.setTimeout(addLinks, 1000);
} else {
// Check if this particular page has been processed through a previous call
if (unsafeWindow.jQuery('.gmlink').length < 1) {
// GM_log("here we go! "+document.location.href);
// Update some global variables than add links
TrackElements = unsafeWindow.jQuery('div.section-track');
SelectedTrack = 0;
var index = 0;
var tracks = unsafeWindow.jQuery('div.section-track .track_name');
tracks.each(function(index, element) {
var trackId = TrackList[index].id;
var trackKey = TrackList[index].key;
var trackArtist = TrackList[index].artist;
var trackSong = TrackList[index].song;
// GM_log(index + " - " + trackId + " - " + trackKey);
if (trackKey) {
if(element.innerHTML.indexOf("Download")==-1){
//window.Element.insert(element, "<a title='"+trackArtist+" - "+trackSong+"' href='/serve/play/"+trackId+"/"+trackKey+"'> <sub><b style='color:red'>(download)</b></sub><sub style='font-size:0px;'>"+trackArtist+" - "+trackSong+"</sub></a>");
//above line stopped working Aug 2011, changed to pure JS by @blissofbeing
var ahref = document.createElement('a');
ahref.setAttribute('href', "/serve/play/"+trackId+"/"+trackKey);
ahref.setAttribute('style','color:red;position: absolute;right: 10px;top: 5px;z-index: 9969;');
ahref.setAttribute('title',trackArtist+" - "+trackSong);
ahref.setAttribute('class','gmlink');
ahref.appendChild(document.createTextNode("Download"));
element.parentNode.insertBefore( ahref, element.nextSibling );
}
}
index++;
});
}
}
}
addLinks();
// Display links after an Ajax update is complete
unsafeWindow.jQuery(document).ajaxComplete(function() {
//unsafeWindow.console.log("ajax url: "+document.location.href);
addLinks();
});