// ==UserScript== // @author Loskir // @id dt-replace-portal@Loskir // @name Draw Tools Replace Portal // @description Quickly replace one portal with another in Draw Tools // @category Info // @version 1.0.7 // @updateURL https://raw.githubusercontent.com/IITC-CE/Community-plugins/master/dist/Loskir/dt-replace-portal.meta.js // @downloadURL https://raw.githubusercontent.com/IITC-CE/Community-plugins/master/dist/Loskir/dt-replace-portal.user.js // @depends draw-tools@breunigs // @match https://intel.ingress.com/* // @grant none // ==/UserScript== function wrapper(plugin_info) { //PLUGIN AUTHORS: writing a plugin outside of the IITC build environment? if so, delete these lines!! //(leaving them in place might break the 'About IITC' page or break update checks) //plugin_info.buildName = 'iitc'; //plugin_info.dateTimeVersion = '20170108.21732'; //plugin_info.pluginId = 'dtreplace'; //END PLUGIN AUTHORS NOTE // PLUGIN START //////////////////////////////////////////////////////// var firstPortalLink, secondPortalLink; var setup = (function (window, undefined) { 'use strict'; var plugin, actions, firstPortal, secondPortal; if (typeof window.plugin !== 'function') window.plugin = function () { }; window.plugin.dtreplace = function () { }; plugin = window.plugin.dtreplace; plugin.setup = setup; return plugin.setup; function toggleMenu() { if (actions.classList.contains("active")) actions.classList.remove("active"); else actions.classList.add("active"); } function clear() { firstPortal = false; secondPortal = false; if (firstPortalLink.classList.contains('highlighted')) firstPortalLink.classList.remove('highlighted'); if (secondPortalLink.classList.contains('highlighted')) secondPortalLink.classList.remove('highlighted'); } function selectFirstPortal() { log('First portal selected'); firstPortal = getPortalSelected(); if (!firstPortal) return; if (!firstPortalLink.classList.contains('highlighted')) firstPortalLink.classList.add('highlighted'); } function selectSecondPortal() { log('Second portal selected'); secondPortal = getPortalSelected(); if (!secondPortal) return; if (!secondPortalLink.classList.contains('highlighted')) secondPortalLink.classList.add('highlighted'); draw(); } function draw() { const dt = window.plugin.drawTools if (!dt) { return alert('This plugin requires Draw Tools') } const fromLL = firstPortal.ll const toLL = secondPortal.ll dt.drawnItems.clearLayers() dt.import(JSON.parse(window.localStorage['plugin-draw-tools-layer'] .replace(new RegExp(`"lat":${fromLL.lat},"lng":${fromLL.lng}`, 'g'), `"lat":${toLL.lat},"lng":${toLL.lng}`))) dt.save() firstPortal = null secondPortal = null firstPortalLink.classList.remove('highlighted') secondPortalLink.classList.remove('highlighted') } function getPortalSelected() { if (!(selectedPortal && portals[selectedPortal])) return; return { guid: selectedPortal, ll: portals[selectedPortal].getLatLng() }; } function log(message) { console.log('Draw Tools Replace: ' + message); } function setup() { var parent, control, section, toolbar, button, clearLi, firstPortalLi, secondPortalLi, otherPortalLi, clearLink, /*firstPortalLink, secondPortalLink are visible globally*/ otherPortalLink; $('