MediaWiki:Common.js:修订间差异
来自AG1444
无编辑摘要 |
无编辑摘要 |
||
| 第2行: | 第2行: | ||
mw.loader.using('mediawiki.util', function () { | mw.loader.using('mediawiki.util', function () { | ||
const bgm = new Audio('/bgm/music.mp3'); | |||
const bgm = new Audio('/bgm/ | |||
bgm.loop = true; | bgm.loop = true; | ||
bgm.volume = 0.5; | bgm.volume = 0.5; | ||
| 第9行: | 第8行: | ||
// 创建按钮 | // 创建按钮 | ||
const btn = document.createElement('button'); | const btn = document.createElement('button'); | ||
btn.textContent = '🎵 播放 BGM'; | |||
btn.textContent = '🎵'; | |||
// | // 固定右下角 | ||
btn.style.position = 'fixed'; | btn.style.position = 'fixed'; | ||
btn.style.right = '12px'; | btn.style.right = '12px'; | ||
| 第23行: | 第21行: | ||
btn.style.borderRadius = '6px'; | btn.style.borderRadius = '6px'; | ||
btn.style.cursor = 'pointer'; | btn.style.cursor = 'pointer'; | ||
// | // 点击逻辑 | ||
btn. | btn.onclick = function () { | ||
if (bgm.paused) { | if (bgm.paused) { | ||
bgm.play(); | bgm.play(); | ||
btn.textContent = '⏸'; | btn.textContent = '⏸ 暂停 BGM'; | ||
} else { | } else { | ||
bgm.pause(); | bgm.pause(); | ||
btn.textContent = '🎵'; | btn.textContent = '🎵 播放 BGM'; | ||
} | } | ||
} | }; | ||
document.body.appendChild(btn); | document.body.appendChild(btn); | ||
}); | |||
2026年1月27日 (二) 01:05的版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
mw.loader.using('mediawiki.util', function () {
const bgm = new Audio('/bgm/music.mp3');
bgm.loop = true;
bgm.volume = 0.5;
// 创建按钮
const btn = document.createElement('button');
btn.textContent = '🎵 播放 BGM';
// 固定右下角
btn.style.position = 'fixed';
btn.style.right = '12px';
btn.style.bottom = '12px';
btn.style.zIndex = '9999';
btn.style.padding = '6px 10px';
btn.style.background = '#333';
btn.style.color = '#fff';
btn.style.border = 'none';
btn.style.borderRadius = '6px';
btn.style.cursor = 'pointer';
// 点击逻辑
btn.onclick = function () {
if (bgm.paused) {
bgm.play();
btn.textContent = '⏸ 暂停 BGM';
} else {
bgm.pause();
btn.textContent = '🎵 播放 BGM';
}
};
document.body.appendChild(btn);
});