-
Notifications
You must be signed in to change notification settings - Fork 150
/
Meting.js
104 lines (90 loc) · 3.54 KB
/
Meting.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
console.log(`${'\n'} %c MetingJS v1.2.0 %c https://github.com/metowolf/MetingJS ${'\n'}`, 'color: #fadfa3; background: #030307; padding:5px 0;', 'background: #fadfa3; padding:5px 0;');
let aplayers = [];
let loadMeting = () => {
let api = 'https://api.i-meto.com/meting/api?server=:server&type=:type&id=:id&r=:r';
if (typeof meting_api !== 'undefined') api = meting_api;
for (let i = 0; i < aplayers.length; i++) {
if(!aplayers[i].container.classList.contains("no-destroy")){
try {
aplayers[i].destroy();
} catch (e) {
console.log(e);
}
}
}
aplayers = [];
let elements = document.querySelectorAll(".aplayer");
for (var i = 0; i < elements.length; i++) {
const el = elements[i];
if(el.classList.contains("no-reload")) continue;
if(el.classList.contains("no-destroy")) el.classList.add("no-reload");
let id = el.dataset.id;
if (id) {
let url = el.dataset.api || api;
url = url.replace(":server", el.dataset.server);
url = url.replace(":type", el.dataset.type);
url = url.replace(":id", el.dataset.id);
url = url.replace(":auth", el.dataset.auth);
url = url.replace(":r", Math.random());
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
let response = JSON.parse(xhr.responseText);
build(el, response);
}
}
};
xhr.open('get', url, true);
xhr.send(null);
} else if (el.dataset.url) {
let data = [{
name: el.dataset.name || el.dataset.title || 'Audio name',
artist: el.dataset.artist || el.dataset.author || 'Audio artist',
url: el.dataset.url,
cover: el.dataset.cover || el.dataset.pic,
lrc: el.dataset.lrc,
type: el.dataset.type || 'auto'
}];
build(el, data);
}
}
function build(element, music) {
let defaultOption = {
container: element,
audio: music,
mini: null,
fixed: null,
autoplay: false,
mutex: true,
lrcType: 3,
listFolded: false,
preload: 'auto',
theme: '#2980b9',
loop: 'all',
order: 'list',
volume: null,
listMaxHeight: null,
customAudioType: null,
storageName: 'metingjs'
};
if (!music.length) {
return;
}
if (!music[0].lrc) {
defaultOption['lrcType'] = 0;
}
let options = {};
for (const defaultKey in defaultOption) {
let eleKey = defaultKey.toLowerCase();
if (element.dataset.hasOwnProperty(eleKey) || element.dataset.hasOwnProperty(defaultKey) || defaultOption[defaultKey] !== null) {
options[defaultKey] = element.dataset[eleKey] || element.dataset[defaultKey] || defaultOption[defaultKey];
if (options[defaultKey] === 'true' || options[defaultKey] === 'false') {
options[defaultKey] = (options[defaultKey] == 'true');
}
}
}
aplayers.push(new APlayer(options));
}
}
document.addEventListener('DOMContentLoaded', loadMeting, false);