-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
98 lines (88 loc) · 2.93 KB
/
index.js
File metadata and controls
98 lines (88 loc) · 2.93 KB
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
var list = []
var searchValue = '周杰伦'
var currentPage = 1
var pageSize = 10
var total = 9999
var currentSong = {}
var audio = document.querySelector('audio');
var playStatus = audio.paused // 播放状态
audio.onended = function () {
randomGet()
};
function keyDown(event, el) {
if (event.keyCode === 13) {
search_btn()
}
}
function change(e, type) {
window[type] = document.querySelector(`#${type}`).value
}
function search_btn() {
if (pageSize * (currentPage - 1) > total) {
alert('????体育老师教的?不会算有几页吗?')
} else {
xhrFuc()
}
}
function changePage(type) {
if (type == 'reduce') {
if (currentPage == 1) {
return alert('还上一页个锤子?')
}
currentPage--
} else if (type == 'add') {
currentPage++
}
search_btn()
}
function randomGet() {
var random = Math.random()
var length = list.length
random = Math.floor(random * length)
sing(list[random])
}
function xhrFuc() {
var xhr = new XMLHttpRequest();
xhr.open("get", `http://pd.musicapp.migu.cn/MIGUM2.0/v1.0/content/search_all.do?&ua=Android_migu&version=5.0.1&text=${encodeURI(searchValue)}&pageNo=${currentPage}&pageSize=${pageSize}&searchSwitch={"song":1,"album":0,"singer":0,"tagSong":0,"mvSong":0,"songlist":0,"bestShow":1}`, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
let res = JSON.parse(xhr.responseText)
if (res.code === '000000') {
list = res.songResultData.result || []
total = res.songResultData.totalCount
document.querySelector('#search_type').innerHTML = `总数量:${total} 当前页数:${currentPage} 每页条数:${pageSize}`
createNode()
} else {
alert(res.info)
}
}
}
}
xhr.send();
}
function createSingleNode(val,index) {
return `<div ><span class="pointer">${val.singers && val.singers.length > 0 ? val.singers[0].name : ''}</span> - <span class="pointer" onclick="checkSong(${index})">${val.name}</span></div>`
}
function createNode() {
var node = '<div>'
list.map((i,index) => {
node += createSingleNode(i,index)
})
node += '</div>'
document.querySelector('#song-list').innerHTML = node
document.querySelector('#operation').style.visibility = 'visible'
}
function checkSong(val) {
currentSong = list[val]
sing(currentSong)
}
function sing(currentSong) {
let contentId = currentSong.contentId
audioPlayerTemp.setAttribute('songName', currentSong.name)
// audioPlayerTemp.querySelector('#songName').innerHTML = currentSong.name
// 无损 formatType = SQ resourceType = E
// 高品 formatType = HQ resourceType = 2
let uri = `http://app.pd.nf.migu.cn/MIGUM2.0/v1.0/content/sub/listenSong.do?toneFlag=HQ&netType=00&userId=15548614588710179085069&ua=Android_migu&version=5.1©rightId=0&contentId=${contentId}&resourceType=2&channel=1`
audio.src = uri
}