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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
| function whenDOMReady() { console.log("pjax开启"); musicState(); }
function musicState() { const music_state = document.querySelector("meting-js").aplayer.audio.paused; if (music_state) { document.querySelector("#music-Switch i").classList.remove("fa-pause"); document.querySelector("#music-Switch i").classList.add("fa-play"); document.querySelector("#console #music-ctrl-btn-center i").classList.remove("fa-pause"); document.querySelector("#console #music-ctrl-btn-center i").classList.add("fa-play"); } else { document.querySelector("#music-Switch i").classList.remove("fa-play"); document.querySelector("#music-Switch i").classList.add("fa-pause"); document.querySelector("#console #music-ctrl-btn-center i").classList.remove("fa-play"); document.querySelector("#console #music-ctrl-btn-center i").classList.add("fa-pause"); } }
function secToTime(s) { if (isNaN(s)) s = 0; var min = Math.floor(s / 60); var sec = Math.floor(s % 60); var t = min.toString().padStart(2, '0') + ":" + sec.toString().padStart(2, '0'); return t; }
var ctrl = {
showConsole: function () { document.querySelector("#console-music-item-main").classList.add("item-show"); document.querySelector("#console").classList.add("show"); ctrl.initConsoleState(); },
hideConsole: function () { var items = document.querySelectorAll(".item-show"); for(var i=0; i<items.length; i++) items[i].classList.remove("item-show"); document.querySelector("#console").classList.remove("show"); },
consoleBackBtn: function () { var top_item = document.querySelector(".item-show"); switch (top_item.id) { case 'console-music-item-mini': break; case 'console-music-item-main': ctrl.hideConsole(); break; case 'console-music-item-list': top_item.classList.remove("item-show"); document.getElementById("console-music-item-main").classList.add("item-show"); break; case 'console-songsheet-item-list': top_item.classList.remove("item-show"); document.getElementById("console-music-item-list").classList.add("item-show"); break; case 'console-music-item-lrc': top_item.classList.remove("item-show"); document.getElementById("console-music-item-main").classList.add("item-show"); break; default: console.log("异常情况"); } },
ircShowHide: function () { const irc = document.querySelector(".aplayer > .aplayer-lrc-hide"); if (irc === null) { document.querySelector(".aplayer > .aplayer-lrc").classList.add("aplayer-lrc-hide"); document.querySelector("#ircItem").classList.remove("on"); } else { document.querySelector(".aplayer > .aplayer-lrc").classList.remove("aplayer-lrc-hide"); document.querySelector("#ircItem").classList.add("on"); } },
musicSwitch: function () { const music_state = document.querySelector("meting-js").aplayer.audio.paused; if (music_state) { document.querySelector("#music-Switch i").classList.remove("fa-play"); document.querySelector("#music-Switch i").classList.add("fa-pause"); document.querySelector("#music-ctrl-btn-center i").classList.remove("fa-play"); document.querySelector("#music-ctrl-btn-center i").classList.add("fa-pause"); } else { document.querySelector("#music-Switch i").classList.remove("fa-pause"); document.querySelector("#music-Switch i").classList.add("fa-play"); document.querySelector("#music-ctrl-btn-center i").classList.remove("fa-pause"); document.querySelector("#music-ctrl-btn-center i").classList.add("fa-play"); } document.querySelector("meting-js").aplayer.toggle(); },
musicForward: function () { document.querySelector("meting-js").aplayer.skipForward(); ctrl.getMusicInfo(); },
musicBackward: function () { document.querySelector("meting-js").aplayer.skipBack(); ctrl.getMusicInfo(); },
getMusicInfo: function () { var music_id = document.querySelector("meting-js").aplayer.list.index; var music_cover = document.querySelector("meting-js").aplayer.list.audios[music_id].cover; var music_author = document.querySelector("meting-js").aplayer.list.audios[music_id].author; var music_title = document.querySelector("meting-js").aplayer.list.audios[music_id].title; document.getElementById("console-music-cover").innerHTML = "<img src='" + music_cover + "' style='width:100%;height:100%;border-radius:0.5rem;'>"; document.getElementById("console-music-title").innerHTML = music_title; document.getElementById("console-music-author").innerHTML = music_author; },
refreshProgress: function () { var nowTime = document.querySelector("meting-js").aplayer.audio.currentTime; if (isNaN(nowTime)) nowTime = 0; var nowTimeString = secToTime(nowTime); var allTime = document.querySelector("meting-js").aplayer.audio.duration; if (isNaN(allTime)) allTime = 0; var allTimeString = secToTime(allTime); document.getElementById("progress-low-btn").innerHTML = nowTimeString; document.getElementById("progress-high-btn").innerHTML = allTimeString; document.querySelector("#p_bar").style.width = document.querySelector("#p_bar_bg").offsetWidth * (nowTime / allTime) + "px"; },
importMusicList: function() { var audios = document.querySelector("meting-js").aplayer.list.audios; var list_html; for (var i = 0; i < audios.length; i++) { list_html = document.getElementById("console-music-list").innerHTML; document.getElementById("console-music-list").innerHTML = list_html + "<li class='music-list-item'><div class='list-music-info1'><a class='list-music-id' data-pjax-state=''>" + (i + 1) + "</a><a class='list-music-state' data-pjax-state=''><i class='iconfont icon-waveform'></i></a></div><div class='list-music-info2'><a class='list-music-title' data-pjax-state=''>" + audios[i].title + "</a><a class='list-music-author' data-pjax-state=''> - " + audios[i].author + "</a></div></li>"; } },
changeMusicList: function(Music_id, Music_server) { var ap = document.querySelector("meting-js").aplayer; var music_list_url_str = "https://metingjs.gavin-chen.top/api?server=" + Music_server + "&type=playlist" + "&id=" + Music_id; ap.list.clear(); fetch(music_list_url_str).then(response => response.json()).then(data => { newSongsheetLen = data.length; console.log(newSongsheetLen); ap.list.add(data); }) .catch(error => console.error(error)); },
initConsoleState: function () { const irc = document.querySelector(".aplayer > .aplayer-lrc-hide"); const aplayer = document.querySelector(".aplayer > .aplayer-lrc"); irc === null && aplayer != null ? document.querySelector("#ircItem").classList.add("on") : document.querySelector("#ircItem").classList.remove("on"); saveToLocal.get('aside-status') === 'hide' ? document.querySelector("#asideItem").classList.add("on") : document.querySelector("#asideItem").classList.remove("on"); var console_musicBody = document.querySelector("#console .console-music-ctrl-item"); var console_musicCover = document.getElementById("console-music-cover"); console_musicCover.style.height = console_musicCover.offsetWidth + "px"; console_musicBody.style.height = (console_musicCover.offsetWidth + 236) + "px"; ctrl.getMusicInfo(); var nowVolume = document.querySelector("meting-js").aplayer.audio.volume; document.querySelector("#v_bar").style.width = document.querySelector("#v_bar_bg").offsetWidth * nowVolume + "px"; }
}
var music_list_switch = document.getElementById("music-ctrl-btn-end"); var music_list_title = document.getElementById("music-list-title"); music_list_switch.addEventListener("click", function (e) { document.getElementById("console-music-item-main").classList.remove("item-show"); document.getElementById("console-music-item-list").classList.add("item-show"); }); music_list_title.addEventListener("click", function (e) { document.getElementById("console-music-item-list").classList.remove("item-show"); document.getElementById("console-songsheet-item-list").classList.add("item-show"); });
var songsheet0 = document.getElementById("songsheet-X"); var songsheet1 = document.getElementById("songsheet-A"); var songsheet2 = document.getElementById("songsheet-B"); var songsheet3 = document.getElementById("songsheet-C"); songsheet0.addEventListener("click", function (e) { document.getElementById("console-loading-icon").classList.add("show"); console.log("正在切换至默认专辑"); global_music_flag = 1; ctrl.changeMusicList("8086610771","netease"); document.getElementById("music-list-title").innerHTML = "网易云"; }); songsheet1.addEventListener("click", function (e) { document.getElementById("console-loading-icon").classList.add("show"); console.log("正在切换至纯音乐专辑"); global_music_flag = 1; ctrl.changeMusicList("651630118","netease"); document.getElementById("music-list-title").innerHTML = "纯音乐"; }); songsheet2.addEventListener("click", function (e) { document.getElementById("console-loading-icon").classList.add("show"); console.log("正在切换至古风专辑"); global_music_flag = 1; ctrl.changeMusicList("5296755943","netease"); document.getElementById("music-list-title").innerHTML = "古风"; }); songsheet3.addEventListener("click", function (e) { document.getElementById("console-loading-icon").classList.add("show"); console.log("正在切换至镜子Vlog专辑"); global_music_flag = 1; ctrl.changeMusicList("4932756913","netease"); document.getElementById("music-list-title").innerHTML = "镜子Vlog"; });
var console_music_list = document.getElementById("console-music-list"); var music_id = null; console_music_list.addEventListener('click', function (e) { var ap = document.querySelector("meting-js").aplayer if (e.target && e.target.nodeName.toUpperCase() == "LI") { music_id = parseInt(e.target.querySelector(".list-music-id").innerHTML); ap.list.switch(music_id - 1); ap.play(); ctrl.getMusicInfo(); } else if (e.target && e.target.nodeName.toUpperCase() == "DIV") { music_id = parseInt(e.target.parentElement.querySelector(".list-music-id").innerHTML); ap.list.switch(music_id - 1); ap.play(); ctrl.getMusicInfo(); } else if (e.target && (e.target.nodeName.toUpperCase() == "A" || e.target.nodeName.toUpperCase() == "I")) { music_id = parseInt(e.target.parentElement.parentElement.querySelector(".list-music-id").innerHTML); ap.list.switch(music_id - 1); ap.play(); ctrl.getMusicInfo(); } else alert("ERROR!") }, false);
var music_volumebar = document.getElementById("music-volumebar"); var v_bar_bg = document.getElementById("v_bar_bg"); var v_bar = document.getElementById("v_bar"); var v_low = document.getElementById("volume-low-btn"); var v_high = document.getElementById("volume-high-btn"); var v_bar_bg_Len = v_bar_bg.offsetWidth;
music_volumebar.addEventListener("mousedown", function (e) { v_bar_bg.style.height = "0.6rem"; v_bar.style.backgroundColor = "var(--anzhiyu-reverse)"; v_low.style.color = "var(--anzhiyu-reverse)"; v_high.style.color = "var(--anzhiyu-reverse)"; let x = e.pageX; v_bar.style.width = (0 + e.offsetX) + "px"; let v_bar_Len = v_bar.offsetWidth; v_bar_bg_Len = v_bar_bg.offsetWidth; let newVolume = e.offsetX / v_bar_bg_Len; document.querySelector("meting-js").aplayer.volume(newVolume, true); document.onmousemove = function (e) { let diff = x - e.pageX; let v_bar_Len_New = v_bar_Len - diff; if (v_bar_Len_New < 0) { v_bar_Len_New = 0; } else if (v_bar_Len_New > v_bar_bg_Len) { v_bar_Len_New = v_bar_bg_Len; } v_bar.style.width = v_bar_Len_New + "px"; newVolume = v_bar_Len_New / v_bar_bg_Len; document.querySelector("meting-js").aplayer.volume(newVolume, true); } });
music_volumebar.addEventListener("touchstart", function (e) { v_bar_bg.style.height = "0.6rem"; v_bar.style.backgroundColor = "var(--anzhiyu-reverse)"; v_low.style.color = "var(--anzhiyu-reverse)"; v_high.style.color = "var(--anzhiyu-reverse)"; let x = e.targetTouches[0].pageX; v_bar.style.width = (0 + e.targetTouches[0].offsetX) + "px"; let v_bar_Len = v_bar.offsetWidth; v_bar_bg_Len = v_bar_bg.offsetWidth; let newVolume = e.targetTouches[0].offsetX / v_bar_bg_Len; document.querySelector("meting-js").aplayer.volume(newVolume, true); document.ontouchmove = function (e) { let diff = x - e.targetTouches[0].pageX; let v_bar_Len_New = v_bar_Len - diff; if (v_bar_Len_New < 0) { v_bar_Len_New = 0; } else if (v_bar_Len_New > v_bar_bg_Len) { v_bar_Len_New = v_bar_bg_Len; } v_bar.style.width = v_bar_Len_New + "px"; newVolume = v_bar_Len_New / v_bar_bg_Len; document.querySelector("meting-js").aplayer.volume(newVolume, true); } });
var music_progressbar = document.getElementById("music-progressbar"); var p_bar_bg = document.getElementById("p_bar_bg"); var p_bar = document.getElementById("p_bar"); var p_low = document.getElementById("progress-low-btn"); var p_high = document.getElementById("progress-high-btn"); var p_bar_Len_New = 0; var p_bar_bg_Len = p_bar_bg.offsetWidth; var ctrl_flag = 1; var mousemove_flag = 1;
music_progressbar.addEventListener("mousedown", function (e) { p_bar_bg.style.height = "0.6rem"; p_bar.style.backgroundColor = "var(--anzhiyu-reverse)"; p_low.style.color = "var(--anzhiyu-reverse)"; p_high.style.color = "var(--anzhiyu-reverse)"; ctrl_flag = 0; global_music_flag = 1; let x = e.pageX; let p_bar_Len = p_bar.offsetWidth; p_bar_bg_Len = p_bar_bg.offsetWidth; document.onmousemove = function (e) { let diff = x - e.pageX; mousemove_flag = 0; p_bar_Len_New = p_bar_Len - diff; if (p_bar_Len_New < 0) { p_bar_Len_New = 0; } else if (p_bar_Len_New > p_bar_bg_Len) { p_bar_Len_New = p_bar_bg_Len; } p_bar.style.width = p_bar_Len_New + "px"; let all_Time = document.querySelector("meting-js").aplayer.audio.duration; let current_time = (p_bar_Len_New / p_bar_bg_Len) * all_Time; document.getElementById("progress-low-btn").innerHTML = secToTime(current_time); } });
music_progressbar.addEventListener("touchstart", function (e) { p_bar_bg.style.height = "0.6rem"; p_bar.style.backgroundColor = "var(--anzhiyu-reverse)"; p_low.style.color = "var(--anzhiyu-reverse)"; p_high.style.color = "var(--anzhiyu-reverse)"; ctrl_flag = 0; global_music_flag = 1; let x = e.targetTouches[0].pageX; let p_bar_Len = p_bar.offsetWidth; p_bar_bg_Len = p_bar_bg.offsetWidth; document.ontouchmove = function (e) { let diff = x - e.targetTouches[0].pageX; mousemove_flag = 0; p_bar_Len_New = p_bar_Len - diff; if (p_bar_Len_New < 0) { p_bar_Len_New = 0; } else if (p_bar_Len_New > p_bar_bg_Len) { p_bar_Len_New = p_bar_bg_Len; } p_bar.style.width = p_bar_Len_New + "px"; let all_Time = document.querySelector("meting-js").aplayer.audio.duration; let current_time = (p_bar_Len_New / p_bar_bg_Len) * all_Time; document.getElementById("progress-low-btn").innerHTML = secToTime(current_time); } });
document.onmouseup = function () { v_bar_bg.style.height = "0.4rem"; v_bar.style.backgroundColor = "var(--font-color)"; v_low.style.color = "var(--font-color)"; v_high.style.color = "var(--font-color)"; p_bar_bg.style.height = "0.4rem"; p_bar.style.backgroundColor = "var(--font-color)"; p_low.style.color = "var(--font-color)"; p_high.style.color = "var(--font-color)"; if (ctrl_flag == 0 && mousemove_flag == 0) { let all_Time = document.querySelector("meting-js").aplayer.audio.duration; let new_Time = (p_bar_Len_New / p_bar_bg_Len) * all_Time; document.querySelector("meting-js").aplayer.seek(new_Time); } global_music_flag = 0; ctrl_flag = 1; mousemove_flag = 1; document.onmousemove = null; };
document.ontouchend = function () { v_bar_bg.style.height = "0.4rem"; v_bar.style.backgroundColor = "var(--font-color)"; v_low.style.color = "var(--font-color)"; v_high.style.color = "var(--font-color)"; p_bar_bg.style.height = "0.4rem"; p_bar.style.backgroundColor = "var(--font-color)"; p_low.style.color = "var(--font-color)"; p_high.style.color = "var(--font-color)"; if (ctrl_flag == 0 && mousemove_flag == 0) { let all_Time = document.querySelector("meting-js").aplayer.audio.duration; let new_Time = (p_bar_Len_New / p_bar_bg_Len) * all_Time; document.querySelector("meting-js").aplayer.seek(new_Time); } global_music_flag = 0; ctrl_flag = 1; mousemove_flag = 1; document.ontouchmove = null; };
var global_music_flag = 0; var meting_load = 1; var listener = 0; var old_music_id = null; var now_music_id = null; var newSongsheetLen = 0; var t_load;
setInterval(() => { if (document.querySelector("meting-js").aplayer != undefined) meting_load = 0; if (meting_load == 0 && listener == 0) { ctrl.importMusicList(); var ap = document.querySelector("meting-js").aplayer; ap.on('play', function () { ctrl.getMusicInfo(); document.querySelector("#music-Switch i").classList.remove("fa-play"); document.querySelector("#music-Switch i").classList.add("fa-pause"); document.querySelector("#music-ctrl-btn-center i").classList.remove("fa-play"); document.querySelector("#music-ctrl-btn-center i").classList.add("fa-pause"); old_music_id = now_music_id; now_music_id = ap.list.index; var ids = document.querySelectorAll("#console-music-list .list-music-id"); var states = document.querySelectorAll("#console-music-list .list-music-state"); for (var i = 0; i < ids.length; i++) { if (parseInt(ids[i].innerHTML) == now_music_id + 1) { if (old_music_id != null) { ids[old_music_id].classList.remove("hide"); states[old_music_id].classList.remove("show"); ids[old_music_id].parentElement.parentElement.style.backgroundColor = ""; } ids[now_music_id].classList.add("hide"); states[now_music_id].classList.add("show"); ids[now_music_id].parentElement.parentElement.style.backgroundColor = "var(--vercel-hover-bg)"; } } }); ap.on('pause', function () { document.querySelector("#music-Switch i").classList.remove("fa-pause"); document.querySelector("#music-Switch i").classList.add("fa-play"); document.querySelector("#music-ctrl-btn-center i").classList.remove("fa-pause"); document.querySelector("#music-ctrl-btn-center i").classList.add("fa-play"); }); var play_mode = document.getElementById("music-ctrl-btn-first"); var ap_play_mode = document.querySelector(".aplayer-icon.aplayer-icon-order"); var loop_str = '<path d="M0.622 18.334h19.54v7.55l11.052-9.412-11.052-9.413v7.549h-19.54v3.725z"></path>'; var random_str = '<path d="M22.667 4l7 6-7 6 7 6-7 6v-4h-3.653l-3.76-3.76 2.827-2.827 2.587 2.587h2v-8h-2l-12 12h-6v-4h4.347l12-12h3.653v-4zM2.667 8h6l3.76 3.76-2.827 2.827-2.587-2.587h-4.347v-4z"></path>'; play_mode.addEventListener("click", function (e) { var ap_play_mode_str = document.querySelector(".aplayer-icon.aplayer-icon-order svg path").outerHTML; if (ap_play_mode_str == loop_str) { play_mode.querySelector("i").classList.remove("fa-repeat"); play_mode.querySelector("i").classList.add("fa-shuffle"); ap_play_mode.click(); } else if (ap_play_mode_str == random_str) { play_mode.querySelector("i").classList.remove("fa-shuffle"); play_mode.querySelector("i").classList.add("fa-repeat"); ap_play_mode.click(); } else alert("程序错误,请刷新!"); }); ap_play_mode.addEventListener("click", function (e) { var ap_play_mode_str = ap_play_mode.querySelector("svg path").outerHTML; if (ap_play_mode_str == loop_str) { play_mode.querySelector("i").classList.remove("fa-shuffle"); play_mode.querySelector("i").classList.add("fa-repeat"); console.log("进入顺序播放模式"); } else if (ap_play_mode_str == random_str) { play_mode.querySelector("i").classList.remove("fa-repeat"); play_mode.querySelector("i").classList.add("fa-shuffle"); console.log("进入随机播放模式"); } else alert("程序错误,请刷新!"); }); ap.on("listclear", function(){ document.getElementById("console-music-list").innerHTML = ""; }); ap.on("listadd", function(){ var current_len = ap.list.audios.length; t_load = setInterval(() => { current_len = ap.list.audios.length; if (current_len < newSongsheetLen) { console.log("current_len: " + current_len); } else { console.log("开始导入") ctrl.importMusicList(); global_music_flag = 1; console.log("导入完毕") clearInterval(t_load); document.getElementById("console-loading-icon").classList.remove("show"); ctrl.consoleBackBtn(); } }, 50); }); listener = 1; }; if (meting_load == 0 && global_music_flag == 0) ctrl.refreshProgress(); }, 100);
whenDOMReady(); document.addEventListener("pjax:complete", whenDOMReady);
|