Last active
July 2, 2020 02:24
-
-
Save johnd0e/fcfd9d365a9a4714b8f93ac0afb81b25 to your computer and use it in GitHub Desktop.
IITC plugin: Extra zoom: Load portals/links from higher zoom levels (click statusbar) [https://gist.github.com/johnd0e/fcfd9d365a9a4714b8f93ac0afb81b25/raw/extra-zoom.user.js]
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-extra-zoom | |
// @name IITC plugin: Extra zoom | |
// @description Load portals/links from higher zoom levels (click statusbar) | |
// Increases data zoom, in steps (limit: 4 levels) | |
// @category Info | |
// @version 0.3.3 | |
// @author jd | |
// @namespace https://gist.github.com/johnd0e | |
// @homepageURL https://gist.github.com/johnd0e/fcfd9d365a9a4714b8f93ac0afb81b25 | |
// @supportURL https://gist.github.com/johnd0e/fcfd9d365a9a4714b8f93ac0afb81b25#new_comment_field | |
// @updateURL https://gist.github.com/johnd0e/fcfd9d365a9a4714b8f93ac0afb81b25/raw/extra-zoom.meta.js | |
// @downloadURL https://gist.github.com/johnd0e/fcfd9d365a9a4714b8f93ac0afb81b25/raw/extra-zoom.user.js | |
// @include https://intel.ingress.com/intel* | |
// @grant none | |
// ==/UserScript== |
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-extra-zoom | |
// @name IITC plugin: Extra zoom | |
// @description Load portals/links from higher zoom levels (click statusbar) | |
// Increases data zoom, in steps (limit: 4 levels) | |
// @category Info | |
// @version 0.3.3 | |
// @author jd | |
// @namespace https://gist.github.com/johnd0e | |
// @homepageURL https://gist.github.com/johnd0e/fcfd9d365a9a4714b8f93ac0afb81b25 | |
// @supportURL https://gist.github.com/johnd0e/fcfd9d365a9a4714b8f93ac0afb81b25#new_comment_field | |
// @updateURL https://gist.github.com/johnd0e/fcfd9d365a9a4714b8f93ac0afb81b25/raw/extra-zoom.meta.js | |
// @downloadURL https://gist.github.com/johnd0e/fcfd9d365a9a4714b8f93ac0afb81b25/raw/extra-zoom.user.js | |
// @include https://intel.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 = function() {}; | |
// PLUGIN START //////////////////////////////////////////////////////// | |
// inspired by https://github.com/3ch01c/iitc-plugins/blob/master/superdata.user.js | |
// use own namespace for plugin | |
// window.plugin.extraZoom = function() {}; | |
const MAX_ZOOM_DIFF = 4; // resonable limit | |
const ZOOM_DEFAULT = undefined; // any false value | |
let extraZoom = ZOOM_DEFAULT; // 'virtual' data zoom value | |
let style; // to be changed in order to indicate overriden zoom state | |
let getDataZoom; // to store original window.getDataZoomForMapZoom | |
function set_zoom (value) { | |
extraZoom = value; | |
window.renderUpdateStatus(); | |
style.text(value ? '#loadlevel { color: red }' : ''); | |
} | |
function next_step () { | |
const zoom = window.map.getZoom(); | |
const last = extraZoom || zoom; | |
const max = zoom + MAX_ZOOM_DIFF; | |
for (let z=last; z<=max; z++) { | |
if (getDataZoom(z) > last) { | |
return z; | |
} | |
} | |
} | |
function toggle () { | |
const z = next_step(); | |
if (z) { | |
set_zoom(z); | |
window.mapDataRequest.start(); | |
} else if (extraZoom) { | |
set_zoom(ZOOM_DEFAULT); | |
} | |
} | |
function setup () { | |
$('#innerstatus').click(toggle); | |
style = $('<style>').prop('type', 'text/css').appendTo('head') | |
getDataZoom = window.getDataZoomForMapZoom; | |
window.getDataZoomForMapZoom = function (zoom) { | |
return extraZoom || getDataZoom(zoom); | |
}; | |
let prev; | |
window.map.on('zoomstart zoomend',function(e) { | |
// https://leafletjs.com/reference-1.3.4.html#map-zoomend | |
if (extraZoom) { | |
const zoom = e.target.getZoom(); | |
switch(e.type) { | |
case 'zoomstart': | |
// experimental: to not switch back if data zoom stays the same | |
prev = getDataZoom(zoom); | |
break; | |
case 'zoomend': | |
if (zoom < prev || zoom >= extraZoom) { | |
set_zoom(ZOOM_DEFAULT); // switch back to default view when zooming out | |
} | |
} | |
} | |
}); | |
} | |
// 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