experimental plugin to show link direction. slowly animating dashes are shown at the source portal for links

performance is an issue when many links are displayed...
This commit is contained in:
Jon Atkins 2013-09-17 07:33:50 +01:00
parent aad3c77ff9
commit fb96a45e1c

View File

@ -0,0 +1,75 @@
// ==UserScript==
// @id iitc-plugin-link-show-direction
// @name IITC plugin: Show the direction of links on the map
// @category Tweaks
// @version 0.1.0.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL @@UPDATEURL@@
// @downloadURL @@DOWNLOADURL@@
// @description [@@BUILDNAME@@-@@BUILDDATE@@] Show the direction of links on the map, by adding short dashes to the line at the origin portal.
// @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==
@@PLUGINSTART@@
// PLUGIN START ////////////////////////////////////////////////////////
// use own namespace for plugin
window.plugin.linkShowDirection = function() {};
window.plugin.linkShowDirection.ANIMATE_UPDATE_TIME=2;
window.plugin.linkShowDirection.frames = [
'10,5,5,5,5,5,5,5,100%',
// '11,5,5,5,5,5,5,4,100%',
'12,5,5,5,5,5,5,3,100%',
// '13,5,5,5,5,5,5,2,100%',
'14,5,5,5,5,5,5,1,100%',
// '15,5,5,5,5,5,100%',
'10,1,5,5,5,5,5,5,100%',
// '10,2,5,5,5,5,5,5,100%',
'10,3,5,5,5,5,5,5,100%',
// '10,4,5,5,5,5,5,5,100%',
];
window.plugin.linkShowDirection.frame = 0;
window.plugin.linkShowDirection.animateLinks = function() {
window.plugin.linkShowDirection.frame ++;
window.plugin.linkShowDirection.frame %= window.plugin.linkShowDirection.frames.length;
$.each(links,function(guid,link) { window.plugin.linkShowDirection.addLinkStyle(link); });
// browsers don't render the SVG style changes until after the timer function has finished.
// this means if we start the next timeout in here a lot of the delay time will be taken by the browser itself
// re-rendering the screen. in the worst case, the timer will run out before the render completes, and fire immediately
// this would mean the user has no chance to interact with IITC
// to prevent this, create a short timer that then sets the timer for the next frame
setTimeout ( function() { setTimeout (window.plugin.linkShowDirection.animateLinks, window.plugin.linkShowDirection.ANIMATE_UPDATE_TIME*1000); }, 10);
}
window.plugin.linkShowDirection.addLinkStyle = function(link) {
link.setStyle ({dashArray: window.plugin.linkShowDirection.frames[window.plugin.linkShowDirection.frame]});
}
window.plugin.linkShowDirection.setup = function() {
addHook ('linkAdded', function(data) { window.plugin.linkShowDirection.addLinkStyle (data.link); });
// only start the animation timer of the paths support SVG
if (L.Path.SVG) {
setTimeout (window.plugin.linkShowDirection.animateLinks, window.plugin.linkShowDirection.ANIMATE_UPDATE_TIME*1000);
}
};
var setup = window.plugin.linkShowDirection.setup;
// PLUGIN END //////////////////////////////////////////////////////////
@@PLUGINEND@@