Last active
December 20, 2015 19:29
-
-
Save johannilsson/6183547 to your computer and use it in GitHub Desktop.
STHLM Traveling + IITC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @id iitc-plugin-sthlmtraveling@johannilsson | |
// @name IITC plugin: STHLM Traveling. | |
// @category Portal Info | |
// @version 0.0.1 | |
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion | |
// @description [johannilsson-2013-08-08-1546] Adds a link to the portal details to open and plan a trip to the portal using the app STHLM Traveling. | |
// @include https://www.ingress.com/intel* | |
// @include http://www.ingress.com/intel* | |
// @match https://www.ingress.com/intel* | |
// @match http://www.ingress.com/intel* | |
// @grant none | |
// ==/UserScript== | |
function wrapper() { | |
// ensure plugin framework is there, even if iitc is not yet loaded | |
if(typeof window.plugin !== 'function') window.plugin = function() {}; | |
// PLUGIN START //////////////////////////////////////////////////////// | |
// use own namespace for plugin | |
window.plugin.sthlmtraveling = function() {}; | |
window.plugin.sthlmtraveling.run = function() { | |
var portal = window.portals[window.selectedPortal]; | |
if (portal) { | |
var lat = portal['_latlng']['lat'] | |
var lng = portal['_latlng']['lng'] | |
var portalName = $('#portaldetails h3.title').text() | |
routeUri = 'journeyplanner://routes?start_point=MY_LOCATION&end_point=' + portalName + '&end_point_lat=' + lat + '&end_point_lng=' + lng + '&time=&isTimeDeparture=true' | |
window.location.href = routeUri | |
} | |
}; | |
var setup = function() { | |
$('#toolbox').append(' <a onclick="window.plugin.sthlmtraveling.run()" title="Plan journey to this portal">Plan journey</a>'); | |
} | |
// PLUGIN END ////////////////////////////////////////////////////////// | |
if(window.iitcLoaded && typeof setup === 'function') { | |
setup(); | |
} else { | |
if(window.bootPlugins) | |
window.bootPlugins.push(setup); | |
else | |
window.bootPlugins = [setup]; | |
} | |
} // wrapper end | |
// inject code into site context | |
var script = document.createElement('script'); | |
script.appendChild(document.createTextNode('('+ wrapper +')();')); | |
(document.body || document.head || document.documentElement).appendChild(script); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment