MediaWiki:Common.js: Difference between revisions
From Jcastle.info
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
$(function () { | $(function () { | ||
if (mw.config.get('wgAction') === 'formedit') { | if (mw.config.get('wgAction') === 'formedit') { | ||
console.log("📄 GPS helper active on | console.log("📄 GPS helper active on Semantic Form edit page"); | ||
setTimeout(function () { | setTimeout(function () { | ||
Line 12: | Line 11: | ||
if (!latText || !lonText) { | if (!latText || !lonText) { | ||
console.log("❌ | console.log("❌ GPSLatitude or GPSLongitude not found in EXIF."); | ||
return; | return; | ||
} | } | ||
function dmsToDecimal(dmsStr) { | function dmsToDecimal(dmsStr) { | ||
var parts = dmsStr.match(/([\d.]+)[^\d]+([\d.]+)[^\d]+([\d.]+)?[^\d]+([NSEW])/); | var parts = dmsStr.match(/([\d.]+)[^\d]+([\d.]+)[^\d]+([\d.]+)?[^\d]+([NSEW])/); | ||
Line 32: | Line 30: | ||
var lonDec = dmsToDecimal(lonText); | var lonDec = dmsToDecimal(lonText); | ||
if (!latDec || !lonDec) { | if (!latDec || !lonDec) { | ||
console.log("❌ GPS | console.log("❌ Failed to convert GPS EXIF."); | ||
return; | return; | ||
} | } | ||
var gpsValue = latDec + ", " + lonDec; | var gpsValue = latDec + ", " + lonDec; | ||
var $input = $('input.pfCoordsInput[name="Castle Photo[GPSLocation]"]'); | |||
var $input = $('input[name | |||
if ($input.length === 0) { | if ($input.length === 0) { | ||
console.log("⚠️ | console.log("⚠️ GPS input field not found."); | ||
return; | return; | ||
} | } | ||
var $button = $('<button>') | var $button = $('<button>') | ||
.text("📋 | .text("📋 Insert EXIF GPS") | ||
.css({ marginLeft: " | .attr("type", "button") | ||
.click(function ( | .css({ marginLeft: "0.5em", fontSize: "90%" }) | ||
.click(function () { | |||
$input.val(gpsValue).focus(); | $input.val(gpsValue).focus(); | ||
alert("✅ GPS inserted | alert("✅ GPS inserted: " + gpsValue); | ||
}); | }); | ||
$input.after($button); | $input.after($button); | ||
}, 500); // Allow DOM + EXIF output to fully load | |||
}, 500); // | |||
} | } | ||
}); | }); |
Revision as of 15:34, 3 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') { console.log("📄 GPS helper active on Semantic Form edit page"); setTimeout(function () { var latText = mw.util.$content.find('.mediaexif-gpslatitude').text().trim(); var lonText = mw.util.$content.find('.mediaexif-gpslongitude').text().trim(); if (!latText || !lonText) { console.log("❌ GPSLatitude or GPSLongitude not found in EXIF."); return; } function dmsToDecimal(dmsStr) { var parts = dmsStr.match(/([\d.]+)[^\d]+([\d.]+)[^\d]+([\d.]+)?[^\d]+([NSEW])/); if (!parts) return null; var deg = parseFloat(parts[1]); var min = parseFloat(parts[2]); var sec = parseFloat(parts[3] || "0"); var ref = parts[4]; var dec = deg + min / 60 + sec / 3600; if (ref === "S" || ref === "W") dec *= -1; return dec.toFixed(6); } var latDec = dmsToDecimal(latText); var lonDec = dmsToDecimal(lonText); if (!latDec || !lonDec) { console.log("❌ Failed to convert GPS EXIF."); return; } var gpsValue = latDec + ", " + lonDec; var $input = $('input.pfCoordsInput[name="Castle Photo[GPSLocation]"]'); if ($input.length === 0) { console.log("⚠️ GPS input field not found."); return; } var $button = $('<button>') .text("📋 Insert EXIF GPS") .attr("type", "button") .css({ marginLeft: "0.5em", fontSize: "90%" }) .click(function () { $input.val(gpsValue).focus(); alert("✅ GPS inserted: " + gpsValue); }); $input.after($button); }, 500); // Allow DOM + EXIF output to fully load } });