Last active
April 15, 2019 09:31
-
-
Save johnd0e/1571ce71a5b15ce71026afa6db5a7e29 to your computer and use it in GitHub Desktop.
IITC plugin: Tidy Links custom / https://cdn.staticaly.com/gist/johnd0e/1571ce71a5b15ce71026afa6db5a7e29/raw/custom-tidy-links.user.js?env=dev
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== | |
// @name IITC plugin: Tidy Links custom | |
// @category Custom | |
// @version 0.1.0 | |
// @description Customization of iitc Tidy Links plugin | |
// @author jd | |
// @namespace https://gist.github.com/johnd0e | |
// @homepageURL https://gist.github.com/johnd0e/1571ce71a5b15ce71026afa6db5a7e29 | |
// @supportURL https://gist.github.com/johnd0e/1571ce71a5b15ce71026afa6db5a7e29#new_comment_field | |
// @updateURL https://gist.github.com/johnd0e/1571ce71a5b15ce71026afa6db5a7e29/raw/custom-tidy-links.user.js | |
// @downloadURL https://gist.github.com/johnd0e/1571ce71a5b15ce71026afa6db5a7e29/raw/custom-tidy-links.user.js | |
// @include https://intel.ingress.com/intel* | |
// @grant none | |
// ==/UserScript== | |
'use strict'; | |
if (typeof window.plugin !== 'function') { window.plugin = function () {}; } | |
(function wrapper (plugin_info) { | |
// PLUGIN START //////////////////////////////////////////////////////// | |
var tidyLinks; | |
function setOverflow (isOveflowed) { | |
var l = tidyLinks.layer; | |
if (isOveflowed) { | |
if (l._overflow !== 'dismissed' || l.isTooltipOpen()) { | |
l._overflow = true; | |
l.openTooltip(); | |
} | |
l._overflow = l._overflow || true; // to keep 'dismissed' state | |
} else { | |
l | |
.closeTooltip() | |
._overflow = false; | |
} | |
} | |
function updateOverflow () { | |
tidyLinks.layer._overflow = 'mapDataRefresh'; | |
tidyLinks.layer.openTooltip(); | |
} | |
function updateOverflowPosition () { tidyLinks.layer.openTooltip(); } | |
var msg = { | |
default: 'Tidy Links: too many portals!', | |
mapDataRefresh: 'Tidy Links: waiting for data...', | |
dismissed: 'dismissed' | |
}; | |
function customize () { | |
// overflow tooltip: follow map center, show update status, reposition with smooth motion | |
tidyLinks.layer | |
// recreate tooltip | |
.bindTooltip(function (l) { return msg[l._overflow] || msg.default; }, { // dynamic content | |
className: 'tidy-links-error', | |
direction: 'center', | |
interactive: true // for 'click' listener | |
}) | |
.on('tooltipopen', function (e) { | |
tidyLinks.layer._overflow = 'mapDataRefresh'; | |
map.on('zoomend moveend', updateOverflowPosition); | |
window.addHook('mapDataRefreshStart', updateOverflow); | |
setTimeout(function () { // open immediately, move with transition | |
$(e.tooltip.getElement()).css('transition','all 0.5s'); | |
}); | |
}) | |
.on('tooltipclose', function (e) { | |
map.off('zoomend moveend', updateOverflowPosition); | |
window.removeHook('mapDataRefreshStart', updateOverflow); | |
$(e.tooltip.getElement()).css('transition','inherit'); | |
}) | |
// dismiss overflow tooltip to stop reappearing on every map update | |
.on('click',function (e) { | |
var l = e.target; | |
//var target = e.originalEvent.target; | |
//if (target.classList.contains('tidy-links-error')) { | |
e.target._overflow = 'dismissed'; | |
l.openTooltip(); | |
setTimeout(function () { l.closeTooltip(); }, 500); | |
//} | |
}) | |
// overwrite with our improved function | |
tidyLinks.setOverflow = setOverflow; | |
if (map.hasLayer(tidyLinks.layer)) { | |
tidyLinks.layer.fire('remove').fire('add'); | |
} | |
} | |
function setup () { | |
tidyLinks = window.plugin.tidyLinks; | |
if (!tidyLinks) { return; } | |
window.addHook('iitcLoaded', customize); | |
} | |
// PLUGIN END ////////////////////////////////////////////////////////// | |
// add the script info data to the function as a property | |
setup.info = plugin_info; | |
if (typeof GM_info === 'object') { | |
var s = GM_info.script; | |
setup.info.script = { version: s.version, name: s.name, description: s.description }; | |
} | |
if (!window.bootPlugins) { window.bootPlugins = []; } | |
window.bootPlugins.push(setup); | |
if (window.iitcLoaded && typeof setup === 'function') { setup(); } | |
}({})); // wrapper end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment