Skip to content

Instantly share code, notes, and snippets.

@xufan6
Last active August 29, 2015 14:06
Show Gist options
  • Save xufan6/35ad6a0f7bc1f50515b2 to your computer and use it in GitHub Desktop.
Save xufan6/35ad6a0f7bc1f50515b2 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @id iitc-plugin-sh-enl-target-drawer@Breezewish
// @name IITC plugin: Draw Shanghai Enlightened Target Portals
// @description Draw target portals by SH ENL
// @author Breezewish
// @category Layer
// @version 0.0.4.20140619.203600
// @updateURL https://gist.githubusercontent.com/breeswish/7e8e0d8628a4615afe59/raw/iitc-plugin-sh-enl-target-drawer.meta.js
// @downloadURL https://gist.githubusercontent.com/breeswish/7e8e0d8628a4615afe59/raw/iitc-plugin-sh-enl-target-drawer.user.js
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel*
// @match https://www.ingress.com/intel*
// @match http://www.ingress.com/intel*
// @grant none
// ==/UserScript==
// ==UserScript==
// @id iitc-plugin-sh-enl-target-drawer@Breezewish
// @name IITC plugin: Draw Shanghai Enlightened Target Portals
// @description Draw target portals by SH ENL
// @author Breezewish
// @category Layer
// @version 0.0.4.20140619.203600
// @updateURL https://gist.githubusercontent.com/breeswish/7e8e0d8628a4615afe59/raw/iitc-plugin-sh-enl-target-drawer.meta.js
// @downloadURL https://gist.githubusercontent.com/breeswish/7e8e0d8628a4615afe59/raw/iitc-plugin-sh-enl-target-drawer.user.js
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel*
// @match https://www.ingress.com/intel*
// @match http://www.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 ////////////////////////////////////////////////////////
// use own namespace for plugin
window.plugin.enltarget = function() {};
var jsonp_url = [
'https://rawgit.com/breeswish/29e79cab8d34ed9d1f57/raw/ingress-sh-enl-marker-guardian.js'
];
var marker_url = 'https://dn-iicc.qbox.me/mark_[type].png';
var marker_types = ['red', 'orange', 'green', 'gray'];
var markers = {};
window.plugin.enltarget.draw = window.plugin.enltarget.draw_guardian;
window.plugin.enltarget.draw_guardian = function(portals) {
portals.forEach(function(po) {
var icon, ug;
var delta_days = Math.floor((new Date().getTime() - po.time) / 1000 / 60 / 60 / 24);
if (delta_days <= 60) {
icon = markers.green;
ug = 0;
} else if (delta_days <= 75) {
icon = markers.orange;
ug = 1;
} else if (delta_days < 90) {
icon = markers.red;
ug = 2;
} else if (delta_days <= 120) {
icon = markers.green;
ug = 0;
} else if (delta_days <= 135) {
icon = markers.orange;
ug = 1;
} else if (delta_days < 150) {
icon = markers.red;
ug = 2;
} else {
icon = markers.gray;
ug = -1;
}
var marker = L.marker([po.lat, po.lng], {icon: new icon({html: delta_days})});
marker.setZIndexOffset((ug + 1) * 1000 + delta_days);
marker.addTo(window.plugin.enltarget.layerGroups.guardian);
marker.on('click', function() {
window.renderPortalDetails(po.guid);
});
marker.on('dblclick', function() {
window.renderPortalDetails(po.guid);
window.map.setView(L.latLng(po.lat, po.lng), 17);
})
});
}
function loadScript(src)
{
jQuery.getScript(src);
}
var setup = function() {
$('<style>\
.leaflet-shtg-icon {background:transparent;border:none;}\
.leaflet-shtg-icon .icon-text{position:relative;top:-40px;font-size:12px;width:25px;text-align:center;color:#FFF;text-shadow:1px 1px 2px #000;}\
</style>').appendTo('head');
marker_types.forEach(function(type) {
var Icon = L.Icon.extend({
options: {
iconUrl: marker_url.replace('[type]', type),
shadowUrl: 'http://leafletjs.com/dist/images/marker-shadow.png',
html: '',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41],
className: 'leaflet-shtg-icon'
},
createIcon: function () {
var div = document.createElement('div');
var img = this._createImg(this.options['iconUrl']);
var numdiv = document.createElement('div');
numdiv.setAttribute('class', 'icon-text');
numdiv.innerHTML = this.options['html'] || '';
div.appendChild(img);
div.appendChild(numdiv);
this._setIconStyles(div, 'icon');
return div;
},
createShadow: function (oldIcon) {
return this._createIcon('shadow', oldIcon);
}
});
markers[type] = Icon;
});
window.plugin.enltarget.layerGroups = {
guardian: new L.LayerGroup()
}
window.addLayerGroup('[SH-ENL] Guardian Portals', window.plugin.enltarget.layerGroups.guardian, true);
for (var i = 0; i < jsonp_url.length; ++i) {
loadScript(jsonp_url[i]);
}
}
// 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