IITC plugin: Open portal in yandex maps

Add yandex map link to portal details

目前為 2021-11-22 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @id             iitc-plugin-portal-yandex-map-link@odrick
// @name           IITC plugin: Open portal in yandex maps
// @author Odrick
// @category       Portal info
// @license MIT
// @version        0.0.1
// @description    Add yandex map link to portal details
// @include        https://*.ingress.com/*
// @include        http://*.ingress.com/*
// @match          https://*.ingress.com/*
// @match          http://*.ingress.com/*
// @grant          none
// @namespace https://greasyfork.org/users/410740
// ==/UserScript==

function wrapper(plugin_info) {
    if(typeof window.plugin !== 'function') window.plugin = function() {};

    plugin_info.buildName = 'Portal link to yandex map';
    plugin_info.dateTimeVersion = '20211121100500';
    plugin_info.pluginId = 'iitc-plugin-portal-yandex-map-link@odrick';

    window.plugin.portalYandexMapLink = function() {};

    window.plugin.portalYandexMapLink.handlePortalSelect = function(data) {
        var portal = window.portals[data.guid];
        var location = portal.getLatLng();

        var url = 'https://yandex.ru/maps/?';
        url += 'll=' + location.lng + ',' + location.lat;
        url += '&mode=routes&rtt=auto&ruri=~&z=14';
        url += '&rtext=~' + location.lat + ',' + location.lng;

        setTimeout(function() {
            if(document.getElementById("portal-yandex-map-link")) {
                return;
            }

            $('<aside id="portal-yandex-map-link"><a href="' + encodeURI(url) + '" target="_blank">Yandex</a></aside>').appendTo($(".linkdetails"))
        }, 0);
    };

    function setup() {
        window.addHook('portalDetailsUpdated', window.plugin.portalYandexMapLink.handlePortalSelect);
    }

    setup.info = plugin_info;

    if (!window.bootPlugins) window.bootPlugins = [];
    window.bootPlugins.push(setup);
    if (window.iitcLoaded && typeof setup === 'function') setup();
}

var script = document.createElement('script');
var info = {};

if(typeof GM_info !== 'undefined' && GM_info && GM_info.script) {
    info.script = {
        version: GM_info.script.version,
        name: GM_info.script.name,
        description: GM_info.script.description
    };
}

var textContent = document.createTextNode('('+ wrapper +')('+ JSON.stringify(info) +')');
script.appendChild(textContent);
(document.body || document.head || document.documentElement).appendChild(script);