Ritural Archive Map Link

Add real yandex map link for grave coordinates

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         Ritural Archive Map Link
// @license MIT
// @namespace    http://tampermonkey.net/
// @version      2024-02-25
// @description  Add real yandex map link for grave coordinates
// @author       You
// @match        https://ritual-archive.ru/permission-view/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=ritual-archive.ru
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    function getParams(url) {
        var regex = /([^=&?]+)=([^&#]*)/g, params = {}, parts, key, value;
        while((parts = regex.exec(url)) != null) {
            key = parts[1];
            value = parts[2];
            var isArray = /\[\]$/.test(key);
            if(isArray) {
                params[key] = params[key] || [];
                params[key].push(value);
            }
            else {
                params[key] = value;
            }
        }
        return params;
    }
    function parseCoordinates(coord) {
        let arr = coord.split(',');
        return {
            lat:arr[1],
            lon:arr[0]
        };
    }
    var $ = window.jQuery;

    let mapLink = $('a[href="https://yandex.ru/maps/"]');
    if ( $(mapLink).length > 0 ) {
        let mapImg = $(mapLink).find( $('img') );
        if ( $(mapImg).length > 0 ) {
            let mapSrc = $(mapImg).attr('src');
            let mapParams = getParams(mapSrc);
            let coords = parseCoordinates(mapParams['pt']);
            let newLink = 'https://yandex.ru/maps/54/yekaterinburg/?ll='+coords.lon+','+coords.lat+'&mode=search&sll='+coords.lon+','+coords.lat+'&text='+coords.lat+','+coords.lon+'&z=18';
            $('a[data-fancybox="map"]').after('<a target="_blank" href="'+newLink+'">Yandex Map</a>');
        }
    }
})();