Skip to content

Instantly share code, notes, and snippets.

@lostsnow
Last active July 16, 2019 03:36
Show Gist options
  • Select an option

  • Save lostsnow/fe684d0fee4b2fdbbf57713fcc0b2b38 to your computer and use it in GitHub Desktop.

Select an option

Save lostsnow/fe684d0fee4b2fdbbf57713fcc0b2b38 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @id com.iitcplugins.autorefresh
// @name IITC plugin: Auto-refresh Map
// @category Misc
// @version 1.3.2.1
// @namespace https://iitcplugins.com/
// @description Automatically refreshes map data every 60 seconds. To change time, modify the window.plugin.autoRefresh.timeout in milliseconds you wish to use. (20000 is 20 seconds)
// @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
// ==/UserScript==
function wrapper(plugin_info) {
// ensure plugin framework is there, even if iitc is not yet loaded
if(typeof window.plugin !== 'function') window.plugin = function() {};
// PLUGIN START ////////////////////////////////////////////////////////
window.plugin.autoRefresh = function() {};
window.plugin.autoRefresh.timeout = 20000;
window.plugin.autoRefresh.autoRefreshMap = function(){
if (!localStorage.autoRefresh) {
// no more tracking
console.warning('Auto-refreshing stopped');
return;
}
console.log("Auto-refreshing map in " + (window.plugin.autoRefresh.timeout / 1000) + " seconds");
mapDataRequest.cache._cache = {};
mapDataRequest.cache_cacheCharSize = 0;
mapDataRequest.cache._interval = undefined;
setTimeout(function() {window.idleReset(); mapDataRequest.start();}, window.plugin.autoRefresh.timeout + Math.random()*1000);
};
window.plugin.autoRefresh.toggleRefresh = function(){
if (localStorage.autoRefresh) {
window.plugin.autoRefresh.stopRefreshing();
} else {
window.plugin.autoRefresh.startRefreshing();
}
};
window.plugin.autoRefresh.startRefreshing = function(){
if (localStorage.autoRefresh) return;
localStorage.autoRefresh = true;
window.plugin.autoRefresh.toggle = $('#autoRefresh-toggle');
window.plugin.autoRefresh.toggle.text('Stop auto-refreshing map');
window.addHook('mapDataRefreshEnd', window.plugin.autoRefresh.autoRefreshMap);
window.mapDataRequest.start();
};
window.plugin.autoRefresh.stopRefreshing = function(){
if (!localStorage.autoRefresh) return;
delete localStorage.autoRefresh;
window.plugin.autoRefresh.toggle.text("Auto-refresh map every " + (window.plugin.autoRefresh.timeout / 1000) + " seconds");
window.removeHook('mapDataRefreshEnd', window.plugin.autoRefresh.autoRefreshMap);
};
var setup = function() {
$('#toolbox').append(' <a onclick="plugin.autoRefresh.toggleRefresh()" id="autoRefresh-toggle">Auto-refresh map every ' + (window.plugin.autoRefresh.timeout / 1000) + ' seconds</a>');
window.plugin.autoRefresh.toggle = $('#autoRefresh-toggle');
if (localStorage.autoRefresh) {
window.plugin.autoRefresh.toggle.text('Stop auto-refreshing map');
window.addHook('mapDataRefreshEnd', window.plugin.autoRefresh.autoRefreshMap);
}
};
// 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)+');'));
var doc = (document.body || document.head || document.documentElement)
doc.appendChild(script);
doc.appendChild(trackingScript);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment