[iitc-plugins] show cross links count
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-cross-links-counter@isnot | |
// @name IITC plugin: cross-links-counter | |
// @category Tweak | |
// @version 0.1 | |
// @namespace https://github.com/isnot/ | |
// @author isnot | |
// @updateURL none | |
// @downloadURL none | |
// @description [iitc-plugins] show cross links count | |
// @include https://*.ingress.com/intel* | |
// @include http://*.ingress.com/intel* | |
// @match https://*.ingress.com/intel* | |
// @match http://*.ingress.com/intel* | |
// @grant none | |
// ==/UserScript== | |
function wrapper(plugin_info) { | |
// ensure plugin framework is there, even if iitc is not yet loaded | |
if (typeof window.plugin !== 'function') window.plugin = () => {}; | |
// PLUGIN START //////////////////////////////////////////////////////// | |
// use own namespace for plugin | |
window.plugin.crossLinksCounter = () => {}; | |
window.plugin.crossLinksCounter.startLoop = (interval = 5) => { | |
let iv = setInterval(() => { | |
if (typeof window.plugin.crossLinks.linkLayerGuids === 'object') { | |
const cnt = Object.keys(window.plugin.crossLinks.linkLayerGuids).length; | |
$('#plugin-crossLinksCounter').text(cnt); | |
} | |
}, interval * 1000); | |
}; | |
window.plugin.crossLinksCounter.control = () => { | |
$('#plugin-crossLinksCounter').toggle(); | |
}; | |
var setup = () => { | |
const content = '<div id="plugin-crossLinksCounter">-</div>'; | |
$('#map').append(content); | |
const control = "<a onclick='window.plugin.crossLinksCounter.control();' title='toggle show/hide cross links counter'>💡XLC</a>"; | |
$('#toolbox').append(control); | |
const style = '#plugin-crossLinksCounter {position:absolute; right:360px; top:10px; font-family:"Consolas","Courier New",monospace; z-index:1000; color:#993333; font-size:36px; text-shadow: 1px 1px 0 #eeeeee, 1px -1px 0 #eeeeee, -1px 1px 0 #eeeeee, -1px -1px 0 #eeeeee'; | |
$('<style>') | |
.prop('type', 'text/css') | |
.html(style) | |
.appendTo('head'); | |
addHook('iitcLoaded', () => { | |
if (window.plugin.crossLinks && window.plugin.crossLinks.linkLayerGuids) { | |
window.plugin.crossLinksCounter.startLoop(); | |
} | |
}); | |
}; | |
// PLUGIN END ////////////////////////////////////////////////////////// | |
setup.info = plugin_info; //add the script info data to the function as a property | |
if(!window.bootPlugins) window.bootPlugins = []; | |
window.bootPlugins.push(setup); | |
// if IITC has already booted, immediately run the 'setup' function | |
if(window.iitcLoaded && typeof setup === 'function') setup(); | |
} // wrapper end | |
// inject code into site context | |
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 }; | |
script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');')); | |
(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