MediaWiki:Common.js
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
$(function () {
// 在线人数统计区块
var $counter = $('<div id="online-counter">当前在线 <span style="color:#a782ff;">👥</span>: <span id="online-number">加载中...</span></div>');
$('body').append($counter);
// 获取在线人数
function updateOnlineNumber() {
$.getJSON('/api/online.php', function (data) {
$('#online-number').text(data.count || 0);
}).fail(function () {
$('#online-number').text('获取失败');
});
}
updateOnlineNumber();
setInterval(updateOnlineNumber, 30000); // 每 30 秒刷新一次
// 如果你不想用这个文件,可以删除下面这行
mw.loader.load("/js/player-init.js");
});
const audio = new Audio();
let currentIndex = 0;
let playlist = [];
navigator.serviceWorker.addEventListener("message", (event) => {
if (event.data?.type === "PLAYLIST") {
playlist = event.data.tracks || [];
playTrack(currentIndex);
}
});
function playTrack(index) {
if (!playlist[index]) return;
audio.src = playlist[index];
audio.play();
}
function send(type) {
navigator.serviceWorker.controller?.postMessage({ type });
}
document.querySelector("button[data-action='PLAY']").onclick = () => playTrack(currentIndex);
document.querySelector("button[data-action='NEXT']").onclick = () => {
currentIndex = (currentIndex + 1) % playlist.length;
playTrack(currentIndex);
};
document.querySelector("button[data-action='PREV']").onclick = () => {
currentIndex = (currentIndex - 1 + playlist.length) % playlist.length;
playTrack(currentIndex);
};
document.querySelector("button[data-action='PAUSE']").onclick = () => audio.pause();