IITC plugin: Copy portal ID to the clipboard

Add copy portal id button to portal info panel

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @id             iitc-plugin-copy-portal-id@odrick
// @name           IITC plugin: Copy portal ID to the clipboard
// @author Odrick
// @category       Portal info
// @license MIT
// @version        0.0.1
// @description    Add copy portal id button to portal info panel
// @include        https://*.ingress.com/intel*
// @include        http://*.ingress.com/intel*
// @match          https://*.ingress.com/intel*
// @match          http://*.ingress.com/intel*
// @include        https://*.ingress.com/mission/*
// @include        http://*.ingress.com/mission/*
// @match          https://*.ingress.com/mission/*
// @match          http://*.ingress.com/mission/*
// @grant          none
// @namespace https://greasyfork.org/users/410740
// ==/UserScript==

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

    plugin_info.buildName = 'Copy portal id button';
    plugin_info.dateTimeVersion = '201201101000500';
    plugin_info.pluginId = 'iitc-plugin-copy-portal-id@odrick';

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

    window.plugin.copyPortalId.copyId = function(id) {
        var val = id + '';

        var textArea = document.createElement("textarea");
        textArea.value = val;
        textArea.style.position="fixed";
        document.body.appendChild(textArea);
        textArea.focus();
        textArea.select();

        try {
            var successful = document.execCommand('copy');

            if(successful) {
                var hint = document.createElement("div");
                hint.innerHTML = "Copied " + val;
                document.body.appendChild(hint);
                hint.style.position = "fixed";
                hint.style.display = "block";
                hint.style.left = "50%";
                hint.style.top = "50%";
                hint.style.transform = "translate(-50%, -50%)";
                hint.style.zIndex = 100500;
                hint.style.padding = "4px";
                hint.style.background = "#fff";
                hint.style.color = "#000";

                setTimeout(function() {
                    document.body.removeChild(hint);
                }, 1000)
            }
        }
        catch (err) {
        }

        document.body.removeChild(textArea);
    }

    window.plugin.copyPortalId.handlePortalSelect = function(data) {
        setTimeout(function() {
            if(document.getElementById("copy-portal-id-button")) {
                return;
            }

            $('<aside id="copy-portal-id-button"><a onclick="window.plugin.copyPortalId.copyId(\'' + data.guid + '\');return false;">Copy ID</a></aside>').appendTo($(".linkdetails"))
        }, 0);
    };

    function setup() {
        window.addHook('portalDetailsUpdated', window.plugin.copyPortalId.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);