-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
207 lines (198 loc) · 6.35 KB
/
index.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
function $(selector) {
return document.querySelector(selector)
}
var audio = new Audio()
var musicList = []
var titleText = document.querySelectorAll('.title');
var singerText = document.querySelectorAll('.singer');
var songInfo = []
audio.autoplay = true
function getMusicList(callback) {
var xml = new XMLHttpRequest();
xml.open('GET','https://jirenguapi.applinzi.com/fm/getChannels.php',true);
xml.onload = function() {
if((xml.status >= 200 && xml.status < 300) || xml.status === 304) {
callback(JSON.parse(this.responseText))
}else {
console.log('List access failed ...')
}
}
xml.onerror = function() {
console.log('网络异常')
}
xml.send()
}
getMusicList(function(list) {
musicList = list
var container = document.createDocumentFragment()
for(var i in musicList.channels) {
var node = document.createElement('li')
node.innerText = (musicList.channels)[i].name
node.id = (musicList.channels)[i].channel_id
container.appendChild(node)
}
$('.list > ul').appendChild(container)
})
window.onload = function() {
function getSong(song) {
var xhr = new XMLHttpRequest();
xhr.open('GET','https://jirenguapi.applinzi.com/fm/getSong.php',true)
xhr.onload = function() {
if((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
song(JSON.parse(this.responseText))
}else {
console.log('Song access failed ...')
}
}
xhr.onerror = function() {
console.log('网络异常')
}
xhr.send('public_tuijian_spring')
}
getSong(function(info) {
songInfo = info
titleText[0].innerText = (songInfo.song)[0].title
singerText[0].innerText = (songInfo.song)[0].artist
$('.bg').style.backgroundImage = 'url('+(songInfo.song)[0].picture+')'
$('.music-img').style.backgroundImage = 'url('+(songInfo.song)[0].picture+')'
$('.img').style.backgroundImage = 'url('+(songInfo.song)[0].picture+')'
audio.src = (songInfo.song)[0].url
})
}
$('.list > ul').addEventListener('click',function(e) {
function getSong(song) {
var xhr = new XMLHttpRequest();
xhr.open('GET','https://jirenguapi.applinzi.com/fm/getSong.php',true)
xhr.onload = function() {
if((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
song(JSON.parse(this.responseText))
}else {
console.log('Song access failed ...')
}
}
xhr.onerror = function() {
console.log('网络异常')
}
xhr.send(e.target.id)
$('.list-name').innerText = e.target.innerText
$('.list-name').id = e.target.id
}
getSong(function(info) {
songInfo = info
for(var i=0; i < titleText.length; i++ ) {
titleText[i].innerText = (songInfo.song)[0].title
}
for(var i=0; i < titleText.length; i++ ) {
singerText[i].innerText = (songInfo.song)[0].artist
}
$('.bg').style.backgroundImage = 'url('+(songInfo.song)[0].picture+')'
$('.music-img').style.backgroundImage = 'url('+(songInfo.song)[0].picture+')'
$('.img').style.backgroundImage = 'url('+(songInfo.song)[0].picture+')'
audio.src = (songInfo.song)[0].url
})
})
audio.ontimeupdate = function() {
$('.progress-bar .PB-now').style.width = (this.currentTime/this.duration)*100 + '%'
$('.bar .bar-now').style.width = (this.currentTime/this.duration)*100 + '%'
}
audio.onended = function(e) {
function getSong(song) {
var xhr = new XMLHttpRequest();
xhr.open('GET','https://jirenguapi.applinzi.com/fm/getSong.php',true)
xhr.onload = function() {
if((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
song(JSON.parse(this.responseText))
}else {
console.log('Song access failed ...')
}
}
xhr.onerror = function() {
console.log('网络异常')
}
xhr.send(e.target.id)
}
getSong(function(info) {
songInfo = info
for(var i=0; i < titleText.length; i++ ) {
titleText[i].innerText = (songInfo.song)[0].title
}
for(var i=0; i < titleText.length; i++ ) {
singerText[i].innerText = (songInfo.song)[0].artist
}
$('.bg').style.backgroundImage = 'url('+(songInfo.song)[0].picture+')'
$('.music-img').style.backgroundImage = 'url('+(songInfo.song)[0].picture+')'
$('.img').style.backgroundImage = 'url('+(songInfo.song)[0].picture+')'
audio.src = (songInfo.song)[0].url
})
}
$('.progress-bar').onclick = function(e) {
var percent = e.offsetX / parseInt(getComputedStyle(this).width)
audio.currentTime = audio.duration * percent
}
$('.next-song').onclick = function() {
function getSong(song) {
var xhr = new XMLHttpRequest();
xhr.open('GET','https://jirenguapi.applinzi.com/fm/getSong.php',true)
xhr.onload = function() {
if((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
song(JSON.parse(this.responseText))
}else {
console.log('Song access failed ...')
}
}
xhr.onerror = function() {
console.log('网络异常')
}
xhr.send($('.list-name').id)
}
getSong(function(info) {
songInfo = info
for(var i=0; i < titleText.length; i++ ) {
titleText[i].innerText = (songInfo.song)[0].title
}
for(var i=0; i < titleText.length; i++ ) {
singerText[i].innerText = (songInfo.song)[0].artist
}
$('.bg').style.backgroundImage = 'url('+(songInfo.song)[0].picture+')'
$('.music-img').style.backgroundImage = 'url('+(songInfo.song)[0].picture+')'
$('.img').style.backgroundImage = 'url('+(songInfo.song)[0].picture+')'
audio.src = (songInfo.song)[0].url
})
}
$('.bar').onclick = function(e) {
var percent = e.offsetX / parseInt(getComputedStyle(this).width)
audio.currentTime = audio.duration * percent
}
$('.stop').onload = function() {
if(audio.play) {
this.querySelector('.fa').classList.add('fa-play')
this.querySelector('.fa').classList.remove('fa-pause')
}else {
this.querySelector('.fa').classList.remove('fa-play')
this.querySelector('.fa').classList.add('fa-pause')
}
}
$('.stop').onclick = function() {
if(audio.paused) {
audio.play()
this.querySelector('.fa').classList.remove('fa-play')
this.querySelector('.fa').classList.add('fa-pause')
}else {
audio.pause()
this.querySelector('.fa').classList.add('fa-play')
this.querySelector('.fa').classList.remove('fa-pause')
}
}
$('.like-it').onclick = function() {
this.querySelector('.fa').style.color = '#ea180e'
}
//无动作超过十秒后页面变化
setInterval(function() {
$('.active-state').classList.add('active')
$('.stationary-state').classList.remove('active')
},10000)
$('body').onmousemove = function() {
clearInterval()
$('.active-state').classList.remove('active')
$('.stationary-state').classList.add('active')
}