MediaWiki:Common.js: Difference between revisions
From Jcastle.info
No edit summary |
No edit summary |
||
Line 35: | Line 35: | ||
if (match) { | if (match) { | ||
var orderValue = parseInt(match[0], 10) * 10; | var orderValue = parseInt(match[0], 10) * 10; | ||
$orderInput | |||
.val(orderValue) | |||
.focus() | |||
.trigger('change'); | |||
} | } | ||
Revision as of 11:11, 18 May 2025
/* Any JavaScript here will be loaded for all users on every page load. */ mw.loader.load('//use.fontawesome.com/053a76b93c.js'); $(function () { if (mw.config.get('wgAction') === 'formedit') { setTimeout(function () { var $latEl = $('.mediaexif-gpslatitude'); var $lonEl = $('.mediaexif-gpslongitude'); var $imgEl = $('img[alt$=".jpg"], img[alt$=".jpeg"], img[alt$=".JPG"], img[alt$=".JPEG"]'); if ($latEl.length === 0 || $lonEl.length === 0 || $imgEl.length === 0) return; var latText = $latEl.text().trim(); var lonText = $lonEl.text().trim(); var filename = $imgEl.attr('alt'); // e.g., Yakamitanba32.jpg var latDec = parseFloat(latText); var lonDec = parseFloat(lonText); if (isNaN(latDec) || isNaN(lonDec) || !filename) return; var gpsValue = latDec.toFixed(6) + ", " + lonDec.toFixed(6); var $gpsInput = $('input[name="Castle Photo[GPSLocation]"]'); var $orderInput = $('input[name="Castle Photo[order]"]'); if ($gpsInput.length === 0 || $orderInput.length === 0) return; var $button = $('<button>') .text("📋 Insert EXIF GPS & Order") .attr("type", "button") .css({ marginLeft: "0.5em", fontSize: "90%" }) .click(function () { $gpsInput.val(gpsValue).focus(); var match = filename.match(/\d+/); if (match) { var orderValue = parseInt(match[0], 10) * 10; $orderInput .val(orderValue) .focus() .trigger('change'); } alert("✅ GPS and Order inserted."); }); $gpsInput.after($button); }, 500); } });