automatic solver for simple reverse geocaches

automatically finds the three 6 digit numbers and shows final coordinates at the start of cache description

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         automatic solver for simple reverse geocaches
// @namespace    http://hautio.net/gctools/
// @version      2026-03-03-0
// @description  automatically finds the three 6 digit numbers and shows final coordinates at the start of cache description
// @author       Kari Hautio <[email protected]>
// @match        https://www.geocaching.com/geocache/GC*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=geocaching.com
// @grant        none
// @license      CC CY-NC-SA 4.0
// ==/UserScript==

(function() {
    'use strict';
    function getdigit(a,n) {
        return Math.floor((a % Math.pow(10,n)) / Math.pow(10,n-1));
    }
    function reverse(a,b,c) {
        var lat, lon;
        var aa=[];
        var bb=[];
        var cc=[];
        for (var i=0; i<6; i++) {
            aa[i] = getdigit(a,6-i);
            bb[i] = getdigit(b,6-i);
            cc[i] = getdigit(c,6-i);
        }
        if ((cc[1]+cc[4]) % 2 == 0) {
            lat = aa[2] * 10 + bb[4] + bb[1] * 0.1 + cc[3] * 0.01 +
                aa[0] * 0.001 + cc[4] * 0.0001 + aa[5] * 0.00001;
            lon = aa[1] * 100 + cc[0] * 10 + cc[5] + bb[3] * 0.1 +
                bb[0] * 0.01 + aa[4] * 0.001 + cc[1] * 0.0001 + bb[5] * 0.00001;
        } else {
            lat = bb[0] * 10 + aa[5] + aa[2] * 0.1 + cc[0] * 0.01 +
                cc[3] * 0.001 + cc[4] * 0.0001 + aa[0] * 0.00001;
            lon = bb[4] * 100 + cc[5] * 10 + aa[4] + aa[1] * 0.1 +
                bb[3] * 0.01 + bb[5] * 0.001 + cc[1] * 0.0001 + bb[1] * 0.00001;
        }
      switch(aa[3]) {
        case 1:
            return [lat,lon];
        case 2:
            return [-lat,lon];
        case 3:
            return [lat,-lon];
        case 4:
            return [-lat,-lon];
        default:
            return [NaN,NaN];
        }
    }

    function printcoords(n,e) {
        var nn = Math.abs(n);
        var ee = Math.abs(e);
        var nnd = Math.floor(nn);
        var eed = Math.floor(ee);
        var nnm = 60 * (nn-nnd);
        var eem = 60 * (ee-eed);
        return `${n>0?'N':'S'}${nnd} ${nnm.toFixed(3)} ${e>0?'E':'W'}${eed} ${eem.toFixed(3)}`;
    }

    function findNumbers() {
        var numbers = new Array(0);
        // first look into note for the numbers
        var container = document.getElementById("srOnlyCacheNote");
        if (container) {
          // console.log("check1:" + container.innerHTML);
          const text = container.innerHTML;
          numbers = text.match(/\d{6}/g); // matches numbers with 6 digits
        }
        // if not found from note then check description
        container = document.getElementById("ctl00_ContentBody_LongDescription");
        if (container && (!numbers || numbers.length != 3)) {
          if (container) {
            // console.log("check2:" + container.innerText);
            const text = container.innerText;
            numbers = text.match(/\d{6}/g); // matches numbers with 6 digits
          }
        }
        // if exaclt 3 numbers found reverse them (multiplies accepted to handle translations)
        if ((numbers.length >= 3) && ((numbers.length % 3) == 0)) {
            // console.log("reversing:" + numbers);
            var out = reverse(numbers[0], numbers[1], numbers[2]);
            var coordstr = printcoords(out[0],out[1]);
	    // Update solution to the front of the page
            container.innerHTML="<p>Wherigo numbers (<I>" + numbers[0] + " " + numbers[1] + " " + numbers[2] + "</I>) found and parsed from the page, final coordinates are:<br><B>" + coordstr + "</B></br>These have been copied to cliboard.</p>" + container.innerHTML;
            // Copy solution to clipboard
            navigator.clipboard.writeText(coordstr);
        }
    }

    // Run after page load
    window.addEventListener("load", findNumbers);
})();