add plugin basics and fix #31 by providing it as plugin

This commit is contained in:
Stefan Breunig 2013-02-09 13:52:10 +01:00
parent b9ec6328f8
commit 6b19e79e07
5 changed files with 100 additions and 6 deletions

View File

@ -176,6 +176,11 @@ function boot() {
window.PLAYER['nickMatcher'] = new RegExp('\\b('+n+')\\b', 'ig');
$('#sidebar').show();
if(window.bootPlugins)
$.each(window.bootPlugins, function(ind, ref) { ref(); });
window.iitcLoaded = true;
}
// this is the minified load.js script that allows us to easily load

View File

@ -65,6 +65,8 @@ document.getElementsByTagName('body')[0].innerHTML = ''
+ ' <input id="geosearch" placeholder="Search location…" type="text"/>'
+ ' <div id="portaldetails"></div>'
+ ' <input id="redeem" placeholder="Redeem code…" type="text"/>'
+ ' <div id="toolbox"></div>'
+ ' <div id="spacer"></div>'
+ ' <div id="updatestatus"></div>'
+ ' </div>';
+ '</div>';
@ -162,6 +164,9 @@ window.portals = {};
window.links = {};
window.fields = {};
// plugin framework. Plugins may load earlier than iitc, so dont
// overwrite data
if(typeof window.plugin !== 'function') window.plugin = function() {};
@@INJECTHERE@@

22
plugins/README.md Normal file
View File

@ -0,0 +1,22 @@
Plugins
=======
Install
-------
Plugins are installed the same way the total conversion script is. Please see there for specific instructions for your browser.
Available Plugins
-----------------
- [**Guess Player Level**](https://raw.github.com/breunigs/ingress-intel-total-conversion/gh-pages/plugins/guess-player-levels.user.js) looks for the highest placed resonator per player in the current view to guess the player level.
Hacking
-------
Plugins may be developed in the same way as the total conversion script. Plugins may provide features tailored to specific needs and are allowed to change things as they see fit. You can provide them separately oder submit a pull request to have them managed in this repository. There are currently no hooks that allow integration with the main script, but I will add those if the need arises. Simply open a bug report.
You can use the guess player level script as an example to get you started. Just update the names and the part between `// PLUGIN START` and `// PLUGIN END` and you should be able to develop your plugin. The other code ensures your plugin is executed after the main script.
If you happen the write general purpose functions for your plugin, consider adding them to the main script instead. For example, if you write a `getResoCountFromPortal(details)` function it may be very well added to `code/portal_info.js`.

View File

@ -0,0 +1,57 @@
// ==UserScript==
// @id iitc-plugin-guess-player-levels@breunigs
// @name iitc: guess player level
// @version 0.1
// @namespace https://github.com/breunigs/ingress-intel-total-conversion
// @updateURL https://raw.github.com/breunigs/ingress-intel-total-conversion/gh-pages/plugins/guess-player-levels.user.js
// @downloadURL https://raw.github.com/breunigs/ingress-intel-total-conversion/gh-pages/plugins/guess-player-levels.user.js
// @description Tries to determine player levels from the data available in the current view
// @include http://www.ingress.com/intel*
// @match http://www.ingress.com/intel*
// ==/UserScript==
function wrapper() {
console.log('hello from plugin');
if(typeof window.plugin !== 'function') window.plugin = function() {};
console.log('window.plugin now is:');
console.log(window.plugin);
window.plugin.guessPlayerLevels = function() {
var players = {};
$.each(window.portals, function(ind, portal) {
var r = portal.options.details.resonatorArray.resonators;
$.each(r, function(ind, reso) {
if(!reso) return true;
var p = reso.ownerGuid;
var l = reso.level;
if(!players[p] || players[p] < l) players[p] = l;
});
});
var playersNamed = {};
$.each(players, function(guid, level) {
playersNamed[getPlayerName(guid)] = level;
});
var s = '';
$.each(Object.keys(playersNamed).sort, function(ind, playerName) {
s += playerName + ': ' + level;
});
alert(s);
}
console.log('window.plugin.guessPlayerLevels now is:');
console.log(window.plugin.guessPlayerLevels);
} // wrapper end
// inject code into site context
var script = document.createElement('script');
script.appendChild(document.createTextNode('('+ wrapper +')();'));
(document.body || document.head || document.documentElement).appendChild(script);

View File

@ -35,12 +35,6 @@ body {
overflow-x:hidden;
}
#redeem {
/* cheap hack to prevent sidebar content being overlayed by the map
* status box */
margin-bottom: 55px;
}
.enl {
color: #03fe03 !important;
@ -489,6 +483,17 @@ aside:nth-child(odd) span {
width: 140px;
}
#toolbox {
padding: 4px;
font-size:90%;
}
#spacer {
/* cheap hack to prevent sidebar content being overlayed by the map
* status box */
height: 55px;
}
/* a common portal display takes this much space (prevents moving
* content when first selecting a portal) */