Opencaching.de Map Link in Geocaching.com Map

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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 );
    }
}