// ==UserScript== // @id iitc-plugin-portal-buttons // @name IITC plugin: Portal Buttons // @category 圖層 // @version 0.1.1.20170210.164403 // @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @updateURL https://raw.githubusercontent.com/ifchen0/IITC_TW/master/build/Release/plugins/portal-buttons.meta.js // @downloadURL https://raw.githubusercontent.com/ifchen0/IITC_TW/master/build/Release/plugins/portal-buttons.user.js // @description Adds some buttons to show/hide portals on the map // @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== //Made by jnmllr 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 AUTHORS: writing a plugin outside of the IITC build environment? if so, delete these lines!! //(leaving them in place might break the 'About IITC' page or break update checks) plugin_info.buildName = 'Release'; plugin_info.dateTimeVersion = '20170210.164403'; plugin_info.pluginId = 'portal-buttons'; //END PLUGIN AUTHORS NOTE // PLUGIN START //////////////////////////////////////////////////////// window.plugin.PortalButtons = function() {}; window.plugin.PortalButtons.loadExternals = function() { console.log('Loading EasyButton JS now'); (function(){ // This is for grouping buttons into a bar // takes an array of `L.easyButton`s and // then the usual `.addTo(map)` L.Control.EasyBar = L.Control.extend({ options: { position: 'topleft', // part of leaflet's defaults id: null, // an id to tag the Bar with leafletClasses: true // use leaflet classes? }, initialize: function(buttons, options){ if(options){ L.Util.setOptions( this, options ); } this._buildContainer(); this._buttons = []; for(var i = 0; i < buttons.length; i++){ buttons[i]._bar = this; buttons[i]._container = buttons[i].button; this._buttons.push(buttons[i]); this.container.appendChild(buttons[i].button); } }, _buildContainer: function(){ this._container = this.container = L.DomUtil.create('div', ''); this.options.leafletClasses && L.DomUtil.addClass(this.container, 'leaflet-bar easy-button-container leaflet-control'); this.options.id && (this.container.id = this.options.id); }, enable: function(){ L.DomUtil.addClass(this.container, 'enabled'); L.DomUtil.removeClass(this.container, 'disabled'); this.container.setAttribute('aria-hidden', 'false'); return this; }, disable: function(){ L.DomUtil.addClass(this.container, 'disabled'); L.DomUtil.removeClass(this.container, 'enabled'); this.container.setAttribute('aria-hidden', 'true'); return this; }, onAdd: function () { return this.container; }, addTo: function (map) { this._map = map; for(var i = 0; i < this._buttons.length; i++){ this._buttons[i]._map = map; } var container = this._container = this.onAdd(map), pos = this.getPosition(), corner = map._controlCorners[pos]; L.DomUtil.addClass(container, 'leaflet-control'); if (pos.indexOf('bottom') !== -1) { corner.insertBefore(container, corner.firstChild); } else { corner.appendChild(container); } return this; } }); L.easyBar = function(){ var args = [L.Control.EasyBar]; for(var i = 0; i < arguments.length; i++){ args.push( arguments[i] ); } return new (Function.prototype.bind.apply(L.Control.EasyBar, args)); }; // L.EasyButton is the actual buttons // can be called without being grouped into a bar L.Control.EasyButton = L.Control.extend({ options: { position: 'topleft', // part of leaflet's defaults id: null, // an id to tag the button with type: 'replace', // [(replace|animate)] // replace swaps out elements // animate changes classes with all elements inserted states: [], // state names look like this // { // stateName: 'untracked', // onClick: function(){ handle_nav_manually(); }; // title: 'click to make inactive', // icon: 'fa-circle', // wrapped with // } leafletClasses: true // use leaflet styles for the button }, initialize: function(icon, onClick, title, id){ // clear the states manually this.options.states = []; // add id to options if(id != null){ this.options.id = id; } // storage between state functions this.storage = {}; // is the last item an object? if( typeof arguments[arguments.length-1] === 'object' ){ // if so, it should be the options L.Util.setOptions( this, arguments[arguments.length-1] ); } // if there aren't any states in options // use the early params if( this.options.states.length === 0 && typeof icon === 'string' && typeof onClick === 'function'){ // turn the options object into a state this.options.states.push({ icon: icon, onClick: onClick, title: typeof title === 'string' ? title : '' }); } // curate and move user's states into // the _states for internal use this._states = []; for(var i = 0; i < this.options.states.length; i++){ this._states.push( new State(this.options.states[i], this) ); } this._buildButton(); this._activateState(this._states[0]); }, _buildButton: function(){ this.button = L.DomUtil.create('a', ''); if (this.options.id ){ this.button.id = this.options.id; } if (this.options.leafletClasses){ L.DomUtil.addClass(this.button, 'leaflet-bar'); } // don't let double clicks get to the map L.DomEvent.addListener(this.button, 'dblclick', L.DomEvent.stop); // take care of normal clicks L.DomEvent.addListener(this.button,'click', function(e){ L.DomEvent.stop(e); this._currentState.onClick(this, this._map ? this._map : null ); this._map.getContainer().focus(); }, this); // prep the contents of the control if(this.options.type == 'replace'){ this.button.appendChild(this._currentState.icon); } else { for(var i=0;i"']/) ){ // // if so, the user should have put in html // // so move forward as such // tmpIcon = ambiguousIconString; // // then it wasn't html, so // // it's a class list, figure out what kind // } else { // ambiguousIconString = ambiguousIconString.replace(/(^\s*|\s*$)/g,''); // tmpIcon = L.DomUtil.create('span', ''); // if( ambiguousIconString.indexOf('fa-') === 0 ){ // L.DomUtil.addClass(tmpIcon, 'fa ' + ambiguousIconString) // } else if ( ambiguousIconString.indexOf('glyphicon-') === 0 ) { // L.DomUtil.addClass(tmpIcon, 'glyphicon ' + ambiguousIconString) // } else { // L.DomUtil.addClass(tmpIcon, /*rollwithit*/ ambiguousIconString) // } // // make this a string so that it's easy to set innerHTML below // tmpIcon = tmpIcon.outerHTML; // } tmpIcon = ambiguousIconString; return tmpIcon; } })(); console.log('done loading EasyButton JS'); window.plugin.PortalButtons.boot(); // $('head').append(''); $('head').append(''); }; window.plugin.PortalButtons.boot = function() { var showLayer = function (name, show) { for (i in window.layerChooser._layers) { // layer has .layer, .name and .overlay var layer = window.layerChooser._layers[i]; if (layer.name === name) { if (show) { if (!window.map.hasLayer(layer.layer)) { window.map.addLayer(layer.layer); } } else { if (window.map.hasLayer(layer.layer)) { window.map.removeLayer(layer.layer); } } } } } var showNone = function () { showLayer("顯示更多能量塔", false); showLayer("等級1能量塔", false); showLayer("等級2能量塔", false); showLayer("等級3能量塔", false); showLayer("等級4能量塔", false); showLayer("等級5能量塔", false); showLayer("等級6能量塔", false); showLayer("等級7能量塔", false); showLayer("等級8能量塔", false); }; var showAll = function () { showLayer("顯示更多能量塔", true); showLayer("等級1能量塔", true); showLayer("等級2能量塔", true); showLayer("等級3能量塔", true); showLayer("等級4能量塔", true); showLayer("等級5能量塔", true); showLayer("等級6能量塔", true); showLayer("等級7能量塔", true); showLayer("等級8能量塔", true); }; var show78 = function () { showLayer("顯示更多能量塔", false); showLayer("等級1能量塔", false); showLayer("等級2能量塔", false); showLayer("等級3能量塔", false); showLayer("等級4能量塔", false); showLayer("等級5能量塔", false); showLayer("等級6能量塔", false); showLayer("等級7能量塔", true); showLayer("等級8能量塔", true); }; var show8 = function () { showLayer("顯示更多能量塔", false); showLayer("等級1能量塔", false); showLayer("等級2能量塔", false); showLayer("等級3能量塔", false); showLayer("等級4能量塔", false); showLayer("等級5能量塔", false); showLayer("等級6能量塔", false); showLayer("等級7能量塔", false); showLayer("等級8能量塔", true); }; var optionsNone = { id: 'portal-buttons-none', position: 'topleft', type: 'replace', leafletClasses: true, states:[{ stateName: 'default', onClick: showNone, title: '隱藏所有能量塔', icon: 'X'//'' }] }; var optionsAll = { id: 'portal-buttons-all', position: 'topleft', type: 'replace', leafletClasses: true, states:[{ stateName: 'default', onClick: showAll, title: '顯示所有能量塔', icon: 'All'//'' }] }; var options78 = { id: 'portal-buttons-78', position: 'topleft', type: 'replace', leafletClasses: true, states:[{ stateName: 'default', onClick: show78, title: '顯示L7和L8能量塔', icon: '7+'//'' }] }; var options8 = { id: 'portal-buttons-8', position: 'topleft', type: 'replace', leafletClasses: true, states:[{ stateName: 'default', onClick: show8, title: '顯示L8能量塔', icon: '8'//'' }] }; var buttons = [L.easyButton(optionsAll), L.easyButton(options78), L.easyButton(options8), L.easyButton(optionsNone)]; L.easyBar(buttons).addTo(window.map); }; var setup = window.plugin.PortalButtons.loadExternals; // 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);