Skip to content

Instantly share code, notes, and snippets.

@johnd0e
Last active March 3, 2020 10:39
Show Gist options
  • Save johnd0e/1894bb43e386ac683c45e5bdea590653 to your computer and use it in GitHub Desktop.
Save johnd0e/1894bb43e386ac683c45e5bdea590653 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @id zoom-level
// @name IITC plugin: Zoom level
// @description Show current zoom level on map
// @category Info
// @version 0.4
// @author jd
// @namespace https://gist.github.com/johnd0e
// @homepageURL https://gist.github.com/johnd0e/1894bb43e386ac683c45e5bdea590653
// @supportURL https://gist.github.com/johnd0e/1894bb43e386ac683c45e5bdea590653#new_comment_field
// @downloadURL https://gist.github.com/johnd0e/1894bb43e386ac683c45e5bdea590653/raw/zoom-level.user.js
// @match https://intel.ingress.com/*
// @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://gist.github.com/isnot/db545fd5cc314163f9b828f16ed63d64
const inZoom = true;
function setup () {
let zoomLevel;
if (inZoom && window.map.zoomControl) {
const inEl = window.map.zoomControl.getContainer().querySelector('a.leaflet-control-zoom-in');
if (inEl.isConnected) {
zoomLevel = $(inEl).css('font-size', 'smaller');
}
}
if (!zoomLevel) {
$('<style>')
.html('#iitc-plugin-zoomLevel {' +
'position:fixed; bottom:0; right:0; min-width:20px;' +
(window.isSmartphone()
? 'padding:1px; margin:3px; margin-right:0; text-align:center;' +
'color:#663300; background:#ffd1d1; opacity:0.5;'
: 'padding:4px 0.2em; margin:0px; color:#000; background:#fff;') +
'}')
.appendTo('head');
const container = $('<div title="Map Zoom Level" id="iitc-plugin-zoomLevel">z</div>')
.appendTo('#updatestatus');
zoomLevel = $('<span>').appendTo(container);
}
window.map.on('viewreset zoomanim zoom', function (e) {
let level = e.zoom; // zoomanim
if (!level) {
level = e.target.getZoom();
if (Math.ceil(level) !== level) { // pinch zoom
level = level.toFixed(1);
}
}
zoomLevel.html(level);
})
};
setup.priority = 'low'; // to be loaded after pan-control plugin
// 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