Open main menu

Changes

MediaWiki:Common.js

341 bytes added, 16:45, 20 November 2024
no edit summary
(function(){
/* Any JavaScript here will be loaded for all users on every page load. */
/* https://github.com/Hitchwiki/hitchwiki/issues/23 */
if ($document.querySelector('body.mw-special-Block').length) { $document.querySelector('#mw-input-wpDisableEmail').click(); $document.querySelector('#mw-input-wpHardBlock').click(); $document.querySelector('#mw-input-wpExpiry')[0].value = 'infinite';
}
async function createStaticMap(mapContainer, lat, lon, zoom, width, height) {const var TILE_SIZE = 256; const var centerX = ((lon + 180) / 360) * Math.pow(2, zoom) * TILE_SIZE; const var centerY = ((1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2) * Math.pow(2, zoom) * TILE_SIZE; const var topLeftX = centerX - width / 2, ; var topLeftY = centerY - height / 2; const var startTileX = Math.floor(topLeftX / TILE_SIZE), ; var startTileY = Math.floor(topLeftY / TILE_SIZE); const var xOffset = -(topLeftX % TILE_SIZE), ; var yOffset = -(topLeftY % TILE_SIZE); const var xTiles = Math.ceil(width / TILE_SIZE) + 1, ; var yTiles = Math.ceil(height / TILE_SIZE) + 1;   mapContainer.style.cssText width = `width:${width}+ 'px'; mapContainer.style.height:${= height}+ 'px'; mapContainer.style.position:= 'relative'; mapContainer.style.overflow:= 'hidden`';   for (let var x = 0; x < xTiles; x++) { for (let var y = 0; y < yTiles; y++) {const var img = document.createElement("img"); img.src = `'https://tile.openstreetmap.org/${' + zoom}+ '/${' + (startTileX + x}) + '/${' + (startTileY + y}) + '.png`'; img.style.cssText position = `position:'absolute'; img.style.width:${= TILE_SIZE}+ 'px'; img.style.height:${= TILE_SIZE}+ 'px'; img.style.left:${= (x * TILE_SIZE+ xOffset) + xOffset}'px'; img.style.top:${= (y * TILE_SIZE+ yOffset) + yOffset}'px`'; mapContainer.appendChild(img); } }}
var mapbox = document.querySelector('.infobox-map');
function findFloatAttr(attr) {
let var floatRegex = /\d+(\.\d+)?/; return + var attrValue = mapbox.innerText.split(attr)[1].match(floatRegex); return attrValue ? parseFloat(attrValue[0]) : 0;
}
// Create an anchor element that wraps the map container
var mapLink = document.createElement("a");
mapLink.href = `'https://hitchmap.com/#location,${' + lat}+ ',${' + lon}+ ',${' + zoom}`;
mapLink.appendChild(mapContainer);
mapbox.innerHTML = '';
mapbox.appendChild(mapLink);
 
})();