MediaWiki:Common.js: Difference between revisions
From Jcastle.info
No edit summary |
No edit summary Tag: Reverted |
||
Line 4: | Line 4: | ||
$(function () { | $(function () { | ||
if (mw.config.get('wgAction') === 'formedit') { | if (mw.config.get('wgAction') === 'formedit') { | ||
setTimeout(function () { | setTimeout(function () { | ||
Line 10: | Line 9: | ||
var lonText = mw.util.$content.find('.mediaexif-gpslongitude').text().trim(); | var lonText = mw.util.$content.find('.mediaexif-gpslongitude').text().trim(); | ||
var latDec = parseFloat(latText); | var latDec = parseFloat(latText); | ||
var lonDec = parseFloat(lonText); | var lonDec = parseFloat(lonText); | ||
if (isNaN(latDec) || isNaN(lonDec)) { | if (isNaN(latDec) || isNaN(lonDec)) { | ||
return; | return; | ||
} | } | ||
var gpsValue = latDec.toFixed(6) + ", " + lonDec.toFixed(6); | var gpsValue = latDec.toFixed(6) + ", " + lonDec.toFixed(6); | ||
var $ | var $gpsInput = $('input.pfCoordsInput[name="Castle Photo[GPSLocation]"]'); | ||
var $orderInput = $('input[name="Castle Photo[Order]"]'); | |||
var $filenameText = mw.util.$content.find('.mediafile > a').text().trim(); // e.g., yakami25.jpg | |||
if ($ | if ($gpsInput.length === 0 || $orderInput.length === 0) { | ||
return; | return; | ||
} | } | ||
var $button = $('<button>') | var $button = $('<button>') | ||
.text("📋 Insert EXIF GPS") | .text("📋 Insert EXIF GPS & Order") | ||
.attr("type", "button") | .attr("type", "button") | ||
.css({ marginLeft: "0.5em", fontSize: "90%" }) | .css({ marginLeft: "0.5em", fontSize: "90%" }) | ||
.click(function () { | .click(function () { | ||
$ | $gpsInput.val(gpsValue).focus(); | ||
alert("✅ GPS inserted | |||
// Extract number from filename and multiply by 10 | |||
var match = $filenameText.match(/\d+/); | |||
if (match) { | |||
var orderValue = parseInt(match[0], 10) * 10; | |||
$orderInput.val(orderValue); | |||
} | |||
alert("✅ GPS and Order inserted."); | |||
}); | }); | ||
$ | $gpsInput.after($button); | ||
}, 500); | }, 500); | ||
} | } | ||
}); | }); |
Revision as of 10:19, 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 latText = mw.util.$content.find('.mediaexif-gpslatitude').text().trim(); var lonText = mw.util.$content.find('.mediaexif-gpslongitude').text().trim(); var latDec = parseFloat(latText); var lonDec = parseFloat(lonText); if (isNaN(latDec) || isNaN(lonDec)) { return; } var gpsValue = latDec.toFixed(6) + ", " + lonDec.toFixed(6); var $gpsInput = $('input.pfCoordsInput[name="Castle Photo[GPSLocation]"]'); var $orderInput = $('input[name="Castle Photo[Order]"]'); var $filenameText = mw.util.$content.find('.mediafile > a').text().trim(); // e.g., yakami25.jpg 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(); // Extract number from filename and multiply by 10 var match = $filenameText.match(/\d+/); if (match) { var orderValue = parseInt(match[0], 10) * 10; $orderInput.val(orderValue); } alert("✅ GPS and Order inserted."); }); $gpsInput.after($button); }, 500); } });