MediaWiki:Common.js:修订间差异
来自AG1444
无编辑摘要 |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ | /* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ | ||
//leaflet | /* 全站加载 Leaflet 地图 */ | ||
mw.loader.load('https://unpkg.com/leaflet@1.9.4/dist/leaflet.css', 'text/css'); | |||
mw.loader.load('https://unpkg.com/leaflet@1.9.4/dist/leaflet.js'); | mw.loader.load('https://unpkg.com/leaflet@1.9.4/dist/leaflet.js'); | ||
mw.loader.using('mediawiki.util', function () { | mw.loader.using(['mediawiki.util'], function () { | ||
function initMap() { | function initMap() { | ||
// 页面里没有 map 容器就直接退出 | |||
const mapDiv = document.getElementById('map'); | |||
if (!mapDiv) return; | |||
// Leaflet 还没加载完就等 | |||
if (typeof L === 'undefined') { | if (typeof L === 'undefined') { | ||
setTimeout(initMap, 100); | setTimeout(initMap, 100); | ||
| 第14行: | 第20行: | ||
const width = 14090; | const width = 14090; | ||
const height = 7045; | const height = 7045; | ||
const bounds = [[0, 0], [height, width]]; | const bounds = [[0, 0], [height, width]]; | ||
const map = L.map('map', { | const map = L.map('map', { | ||
| 第51行: | 第27行: | ||
minZoom: 0, | minZoom: 0, | ||
maxZoom: 5, | maxZoom: 5, | ||
zoomControl: true | zoomControl: true, | ||
maxBounds: bounds | |||
}); | }); | ||
map.fitBounds(bounds); | map.fitBounds(bounds); | ||
| 第61行: | 第38行: | ||
bounds: bounds | bounds: bounds | ||
}).addTo(map); | }).addTo(map); | ||
} | } | ||
2026年2月4日 (三) 03:41的版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* 全站加载 Leaflet 地图 */
mw.loader.load('https://unpkg.com/leaflet@1.9.4/dist/leaflet.css', 'text/css');
mw.loader.load('https://unpkg.com/leaflet@1.9.4/dist/leaflet.js');
mw.loader.using(['mediawiki.util'], function () {
function initMap() {
// 页面里没有 map 容器就直接退出
const mapDiv = document.getElementById('map');
if (!mapDiv) return;
// Leaflet 还没加载完就等
if (typeof L === 'undefined') {
setTimeout(initMap, 100);
return;
}
const width = 14090;
const height = 7045;
const bounds = [[0, 0], [height, width]];
const map = L.map('map', {
crs: L.CRS.Simple,
minZoom: 0,
maxZoom: 5,
zoomControl: true,
maxBounds: bounds
});
map.fitBounds(bounds);
L.tileLayer('/map/tiles/{z}/{x}/{y}.jpg', {
tileSize: 512,
noWrap: true,
bounds: bounds
}).addTo(map);
}
$(initMap);
});
//BGM
mw.loader.using('mediawiki.util', function () {
const bgm = new Audio('/bgm/英雄主义pt.2.mp3');
bgm.loop = true;
bgm.volume = 0.5;
//按钮
const btn = document.createElement('button');
btn.textContent = '🎵';
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 = '🎵';
} else {
bgm.pause();
btn.textContent = '⏸';
}
};
document.body.appendChild(btn);
});