MediaWiki:Common.js:修订间差异
跳转到导航
跳转到搜索
无编辑摘要 |
无编辑摘要 |
||
第19行: | 第19行: | ||
mw.loader.load("/js/player-init.js"); | 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(); |
2025年6月12日 (四) 10:39的版本
$(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();