@@ -5,12 +5,22 @@ function click(event) {
5
5
httpGetAsync ( "http://www.livephish.com/bigriver/subPlayer.aspx?HLS=1&callback=angular.callbacks._9&trackID=" + trackID , download ) ;
6
6
}
7
7
8
+ async function clickAll ( event ) {
9
+ var downloadButtons = document . getElementsByClassName ( "downloadTrack" ) ;
10
+ for ( var i = 0 ; i < downloadButtons . length ; i ++ ) {
11
+ var trackID = downloadButtons [ i ] . parentNode . getAttribute ( "id" ) ;
12
+ trackID = String . prototype . replace . call ( trackID , "track-" , "" ) ;
13
+ await httpGetAsync ( "http://www.livephish.com/bigriver/subPlayer.aspx?HLS=1&callback=angular.callbacks._9&trackID=" + trackID , download ) ;
14
+ await Wait ( ) ;
15
+ }
16
+ }
17
+
18
+
8
19
/* parses the response text, and downloads the file */
9
20
function download ( responseText )
10
21
{
11
22
var dlLink = String . prototype . substring . call ( responseText , 36 ) ;
12
23
dlLink = String . prototype . split . call ( dlLink , '\"' ) [ 0 ] ;
13
-
14
24
var link = document . createElement ( "a" ) ;
15
25
link . download = "song.m4a" ;
16
26
link . href = dlLink ;
@@ -21,13 +31,25 @@ function download(responseText)
21
31
delete link ;
22
32
}
23
33
34
+ async function Wait ( ) {
35
+ console . log ( 'Taking a break...' ) ;
36
+ await sleep ( 2000 ) ;
37
+ console . log ( 'Two second later' ) ;
38
+ }
39
+
40
+ function sleep ( ms ) {
41
+ return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
42
+ }
43
+
24
44
/* Gets the page which contains our download link */
25
45
function httpGetAsync ( theUrl , callback )
26
46
{
27
47
var xmlHttp = new XMLHttpRequest ( ) ;
28
48
xmlHttp . onreadystatechange = function ( ) {
29
49
if ( xmlHttp . readyState == 4 && xmlHttp . status == 200 )
50
+ {
30
51
callback ( xmlHttp . responseText ) ;
52
+ }
31
53
}
32
54
xmlHttp . open ( "GET" , theUrl , true ) ; // true for asynchronous
33
55
@@ -40,12 +62,24 @@ window.onload = function(){
40
62
41
63
for ( var i = 0 ; i < rows . length ; i ++ ) {
42
64
var button = document . createElement ( "button" ) ;
43
- var textNode = document . createTextNode ( "download " ) ;
65
+ var textNode = document . createTextNode ( "Download track " ) ;
44
66
button . setAttribute ( "id" , "download_" + i ) ;
67
+ button . setAttribute ( "class" , "downloadTrack" )
45
68
button . setAttribute ( "href" , "javascript:void(0)" ) ;
46
69
button . setAttribute ( "style" , "margin-left: 5px; margin-top: 5px;" ) ;
47
70
button . appendChild ( textNode ) ;
48
71
rows [ i ] . insertBefore ( button , rows [ i ] . childNodes [ 0 ] ) ;
49
72
button . addEventListener ( 'click' , click ) ;
50
73
}
74
+
75
+ playSection = document . getElementsByClassName ( "recording-controls" ) [ 0 ] ;
76
+ var button = document . createElement ( "button" ) ;
77
+ var textNode = document . createTextNode ( "Download Release" ) ;
78
+ button . setAttribute ( "id" , "downloadAll_" + i ) ;
79
+ button . setAttribute ( "href" , "javascript:void(0)" ) ;
80
+ button . setAttribute ( "style" , "margin-left: 5px; margin-top: 5px;" ) ;
81
+ button . appendChild ( textNode ) ;
82
+ playSection . insertBefore ( button , playSection . childNodes [ 0 ] ) ;
83
+ button . addEventListener ( 'click' , clickAll ) ;
84
+
51
85
} ;
0 commit comments