MediaWiki:Common.js:修订间差异
来自AG1444
无编辑摘要 |
无编辑摘要 |
||
| (未显示同一用户的8个中间版本) | |||
| 第1行: | 第1行: | ||
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ | /* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ | ||
/* 全站加载 Leaflet 地图 */ | /* 全站加载 Leaflet 地图 */ | ||
mw.loader.load('https:// | mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.css', 'text/css'); | ||
mw.loader.load('https:// | mw.loader.load('https://cdn.rawgit.com/ardhi/Leaflet.MousePosition/master/src/L.Control.MousePosition.css', 'text/css'); | ||
mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.js'); | |||
mw.loader.load('https://cdn.rawgit.com/ardhi/Leaflet.MousePosition/master/src/L.Control.MousePosition.js'); | |||
mw.loader.using( | mw.loader.using('mediawiki.util', function() { | ||
function initMap() { | function initMap() { | ||
const mapDiv = document.getElementById('map'); | const mapDiv = document.getElementById('map'); | ||
if (!mapDiv) return; | if (!mapDiv) return; | ||
if (typeof L === 'undefined') { | if (typeof L === 'undefined') { | ||
setTimeout(initMap, 100); | setTimeout(initMap, 100); | ||
| 第18行: | 第17行: | ||
} | } | ||
const | // 地图参数 | ||
const | const mapExtent = [0, -7045, 14090, 0]; | ||
const mapMinZoom = 0; | |||
const mapMaxZoom = 5; | |||
const tileExtent = [0, -7045, 14090, 0]; | |||
const | const crs = L.CRS.Simple; | ||
crs.transformation = new L.Transformation(1, -tileExtent[0], -1, tileExtent[3]); | |||
crs.scale = function(zoom) { | |||
return Math.pow(2, zoom) / Math.pow(2, mapMaxZoom); | |||
}; | |||
crs.zoom = function(scale) { | |||
return Math.log(scale * Math.pow(2, mapMaxZoom)) / Math.LN2; | |||
}; | |||
const map = L.map('map', { | const map = L.map('map', { | ||
minZoom: mapMinZoom, | |||
minZoom: | maxZoom: mapMaxZoom, | ||
maxZoom: | crs: crs | ||
}); | }); | ||
const layer = L.tileLayer('/map/tiles/{z}/{x}/{y}.jpg', { | |||
minZoom: mapMinZoom, | |||
maxZoom: mapMaxZoom, | |||
tileSize: 512, | tileSize: L.point(512, 512), | ||
noWrap: true, | noWrap: true, | ||
tms: false | |||
tms: | |||
}).addTo(map); | }).addTo(map); | ||
map.fitBounds([ | |||
crs.unproject(L.point(mapExtent[2], mapExtent[3])), | |||
crs.unproject(L.point(mapExtent[0], mapExtent[1])) | |||
]); | |||
L.control.mousePosition().addTo(map); | |||
} | } | ||
2026年2月4日 (三) 04:22的最新版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* 全站加载 Leaflet 地图 */
mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.css', 'text/css');
mw.loader.load('https://cdn.rawgit.com/ardhi/Leaflet.MousePosition/master/src/L.Control.MousePosition.css', 'text/css');
mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.js');
mw.loader.load('https://cdn.rawgit.com/ardhi/Leaflet.MousePosition/master/src/L.Control.MousePosition.js');
mw.loader.using('mediawiki.util', function() {
function initMap() {
const mapDiv = document.getElementById('map');
if (!mapDiv) return;
if (typeof L === 'undefined') {
setTimeout(initMap, 100);
return;
}
// 地图参数
const mapExtent = [0, -7045, 14090, 0];
const mapMinZoom = 0;
const mapMaxZoom = 5;
const tileExtent = [0, -7045, 14090, 0];
const crs = L.CRS.Simple;
crs.transformation = new L.Transformation(1, -tileExtent[0], -1, tileExtent[3]);
crs.scale = function(zoom) {
return Math.pow(2, zoom) / Math.pow(2, mapMaxZoom);
};
crs.zoom = function(scale) {
return Math.log(scale * Math.pow(2, mapMaxZoom)) / Math.LN2;
};
const map = L.map('map', {
minZoom: mapMinZoom,
maxZoom: mapMaxZoom,
crs: crs
});
const layer = L.tileLayer('/map/tiles/{z}/{x}/{y}.jpg', {
minZoom: mapMinZoom,
maxZoom: mapMaxZoom,
tileSize: L.point(512, 512),
noWrap: true,
tms: false
}).addTo(map);
map.fitBounds([
crs.unproject(L.point(mapExtent[2], mapExtent[3])),
crs.unproject(L.point(mapExtent[0], mapExtent[1]))
]);
L.control.mousePosition().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);
});