MediaWiki:Common.js: Difference between revisions

From Jcastle.info
No edit summary
Tag: Manual revert
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 2: Line 2:
mw.loader.load('//use.fontawesome.com/053a76b93c.js');
mw.loader.load('//use.fontawesome.com/053a76b93c.js');


$(function () {
setTimeout(function () {
   if (mw.config.get('wgAction') === 'formedit') {
   var $gpsInput = $('input[name="Castle Photo[GPSLocation]"]');
  var $orderInput = $('input[name="Castle Photo[order]"]');
  var $imgEl = $('img[alt$=".jpg"], img[alt$=".jpeg"], img[alt$=".JPG"], img[alt$=".JPEG"]');


    setTimeout(function () {
  if ($gpsInput.length === 0 || $orderInput.length === 0 || $imgEl.length === 0) return;
      var $latEl = mw.util.$content.find('.mediaexif-gpslatitude');
      var $lonEl = mw.util.$content.find('.mediaexif-gpslongitude');
      var $fileEl = mw.util.$content.find('.mediafile > a');


      if ($latEl.length === 0 || $lonEl.length === 0 || $fileEl.length === 0) return;
  var filename = $imgEl.attr('alt'); // e.g., yakami25.jpg


      var latText = $latEl.text().trim();
  // Try to extract GPS values (optional)
      var lonText = $lonEl.text().trim();
  var gpsValue = null;
      var filename = $fileEl.text().trim();
  var $latEl = $('.mediaexif-gpslatitude');
 
  var $lonEl = $('.mediaexif-gpslongitude');
      var latDec = parseFloat(latText);
  if ($latEl.length && $lonEl.length) {
      var lonDec = parseFloat(lonText);
    var latDec = parseFloat($latEl.text().trim());
 
    var lonDec = parseFloat($lonEl.text().trim());
      if (isNaN(latDec) || isNaN(lonDec)) return;
    if (!isNaN(latDec) && !isNaN(lonDec)) {
 
       gpsValue = latDec.toFixed(6) + ", " + lonDec.toFixed(6);
       var gpsValue = latDec.toFixed(6) + ", " + lonDec.toFixed(6);
    }
      var $gpsInput = $('input.pfCoordsInput[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 () {
       if (gpsValue) {
        $gpsInput.val(gpsValue).focus().trigger('change');
      }


       var $button = $('<button>')
       var match = filename.match(/\d+/);
        .text("📋 Insert EXIF GPS & Order")
      if (match) {
        .attr("type", "button")
         var orderValue = parseInt(match[0], 10) * 10;
         .css({ marginLeft: "0.5em", fontSize: "90%" })
         $orderInput.val(orderValue).focus().trigger('change');
         .click(function () {
      }
          $gpsInput.val(gpsValue).focus();


          var match = filename.match(/\d+/);
//     alert("✅ Fields updated.");
          if (match) {
    });
            var orderValue = parseInt(match[0], 10) * 10;
            $orderInput.val(orderValue);
          }


          alert("✅ GPS and Order inserted.");
  $gpsInput.after($button);
        });
}, 500);
 
      $gpsInput.after($button);
    }, 500);
  }
});

Latest revision as of 16:09, 18 May 2025

/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.load('//use.fontawesome.com/053a76b93c.js');

setTimeout(function () {
  var $gpsInput = $('input[name="Castle Photo[GPSLocation]"]');
  var $orderInput = $('input[name="Castle Photo[order]"]');
  var $imgEl = $('img[alt$=".jpg"], img[alt$=".jpeg"], img[alt$=".JPG"], img[alt$=".JPEG"]');

  if ($gpsInput.length === 0 || $orderInput.length === 0 || $imgEl.length === 0) return;

  var filename = $imgEl.attr('alt');  // e.g., yakami25.jpg

  // Try to extract GPS values (optional)
  var gpsValue = null;
  var $latEl = $('.mediaexif-gpslatitude');
  var $lonEl = $('.mediaexif-gpslongitude');
  if ($latEl.length && $lonEl.length) {
    var latDec = parseFloat($latEl.text().trim());
    var lonDec = parseFloat($lonEl.text().trim());
    if (!isNaN(latDec) && !isNaN(lonDec)) {
      gpsValue = latDec.toFixed(6) + ", " + lonDec.toFixed(6);
    }
  }

  var $button = $('<button>')
    .text("📋 Insert EXIF GPS & Order")
    .attr("type", "button")
    .css({ marginLeft: "0.5em", fontSize: "90%" })
    .click(function () {
      if (gpsValue) {
        $gpsInput.val(gpsValue).focus().trigger('change');
      }

      var match = filename.match(/\d+/);
      if (match) {
        var orderValue = parseInt(match[0], 10) * 10;
        $orderInput.val(orderValue).focus().trigger('change');
      }

//      alert("✅ Fields updated.");
    });

  $gpsInput.after($button);
}, 500);