Opencaching.de Map Link in Geocaching.com Map

Inserts a link to the map of opencaching.de into geocaching.com's map.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        Opencaching.de Map Link in Geocaching.com Map
// @description Inserts a link to the map of opencaching.de into geocaching.com's map.
// @namespace   http://flopp.net/
// @version     1.0.0
// @include     https://www.geocaching.com/map*
// @grant       none
// @author      Flopp <[email protected]>   (Original author)
// @author      Kristian Thy <[email protected]> (Maintainer)
// ==/UserScript==

if( document.location.href.match( /^https:\/\/www.geocaching\.com\/map/ ) )
{
    var de = document.getElementById( "lnkMapPreferences" ).innerHTML.trim() === "Karten-Einstellungen";
    var ref_link = document.getElementById( "map_linkto" );
    if( ref_link )
    {
        function open_ocde()
        {
            var s = ref_link.value;
            var coordinates = s.match( /ll=([-0-9]*\.[0-9]*),([-0-9]*\.[0-9]*)/ );
            var zoom = s.match( /z=([0-9]*)/ );
            if( coordinates != null && zoom != null ) 
            {
                var ocde_map_url = "https://www.opencaching.de/map2.php" + "?lat=" + coordinates[1] + "&lon=" + coordinates[2] + "&zoom=" + zoom[1];
                window.open( ocde_map_url );
            }
            else 
            {
                alert( de ? "Diese Karte enthält leider keine Koordinatenangabe :(" : "This map does not contain any coordinates :(" );
            }
        }
        
        var permalink = ref_link.parentNode;
        var footer = permalink.parentNode;
        footer.style.height = "12em";

        var ocde_image = document.createElement( "img" );
        ocde_image.setAttribute( "src", "https://www.opencaching.de/resource2/ocstyle/images/oclogo/16x16-oc_logo.png" );
        ocde_image.style.marginRight = "4px";
        
        var ocde_text = document.createElement( "span" );
        ocde_text.innerHTML = de ? "Zeige bei Opencaching.de" : "Show @ Opencaching.de";
        
        var link = document.createElement( "a" );
        link.setAttribute( "class", "button" );
        link.setAttribute( "title", de ? "Zeige Gebiet bei opencaching.de" : "Open map extent on Opencaching.de");
        link.setAttribute( "href", "#" );
        link.setAttribute( "id", "ocde_lnk" );
        link.style.marginBottom =  "1em";

        link.appendChild( ocde_image );
        link.appendChild( ocde_text );
        
        permalink.parentNode.insertBefore( link, permalink );

        document.getElementById( 'ocde_lnk' ).addEventListener( "click", open_ocde, false );
    }
}