-
Notifications
You must be signed in to change notification settings - Fork 1
/
writhem-api.user.js
117 lines (102 loc) · 4.84 KB
/
writhem-api.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// ==UserScript==
// @id iitc-plugin-writhem-api@pironic
// @name iitc: writhem-api hooks
// @version 0.0.3
// @namespace https://github.com/breunigs/ingress-intel-total-conversion
// @updateURL ingress.writhem.com/writhem-api.user.js
// @downloadURL ingress.writhem.com/writhem-api.user.js
// @description Will send all the logs received from google's rpc to writhem's server for further processing
// @include https://www.ingress.com/intel*
// @match https://www.ingress.com/intel*
// ==/UserScript==
function wrapper() {
// 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.writhemAPI = function() {};
window.plugin.writhemAPI.url = "http://ingress.writhem.com/api/";
window.plugin.writhemAPI.apikey = getURLParam('key');
if (window.plugin.writhemAPI.apikey.length > 1) {
window.plugin.writhemAPI.enabled = true;
} else {
window.plugin.writhemAPI.enabled = false;
}
var setup = function() {
window.plugin.writhemAPI.setupCallback();
window.plugin.writhemAPI.setupOverloads();
console.log("WritheM API Loaded");
}
window.plugin.writhemAPI.setupCallback = function() {
if (window.plugin.writhemAPI.enabled) {
$('#sidebar > #gamestat').after('<div id="writhemStatus"><a onclick="window.plugin.writhemAPI.enableToggle()">Disable WritheM API</a></div> ');
} else {
var msg = '<form name="form1" method="get">';
msg += '<input default="key" name="key" type="text" size=32>';
msg += '<button text="go" type="submit">login</button> ';
msg += '</form>';
$('#sidebar > #gamestat').after('<div id="writhemStatus">'+msg+'</div> ');
}
}
window.plugin.writhemAPI.setupOverloads = function() {
window.MAX_IDLE_TIME = 0; // never stop updating the map.
window.isIdle = function() {
if (MAX_IDLE_TIME == 0) return false;
return window.idleTime >= MAX_IDLE_TIME;
}
// intercept and inject my own functionality into the various methods.
// this will allow me to hijack the data for my own evil intent.
window.plugin.writhemAPI.originalHandlePublic = window.chat.handlePublic;
window.chat.handlePublic = function(data, textStatus, jqXHR) {
// intercept the data, send to our db.
window.plugin.writhemAPI.handleData(data);
window.plugin.writhemAPI.originalHandlePublic(data, textStatus, jqXHR);
}
window.plugin.writhemAPI.originalHandleFaction = window.chat.handleFaction;
window.chat.handleFaction = function(data, textStatus, jqXHR) {
// intercept the data, send to our db.
window.plugin.writhemAPI.handleData(data);
window.plugin.writhemAPI.originalHandleFaction(data, textStatus, jqXHR);
}
}
window.plugin.writhemAPI.handleData = function(data) {
if(!data || !data.result)
return console.warn('writhem handleData error. Waiting for next auto-refresh.');
if(data.result.length === 0) return;
if (window.plugin.writhemAPI.enabled) {
var dataPkg = {
"key":window.plugin.writhemAPI.apikey,
"package":data
};
$.post(window.plugin.writhemAPI.url, dataPkg)
.done(function(response) {
$('#portaldetails').html(response);
console.log(response);
});
}
return;
}
window.plugin.writhemAPI.enableToggle = function() {
if (window.plugin.writhemAPI.enabled) {
window.plugin.writhemAPI.enabled = false;
$('#writhemStatus').html('<a onclick="window.plugin.writhemAPI.enableToggle()">Enable WritheM API</a>');
} else {
window.plugin.writhemAPI.enabled = true;
$('#writhemStatus').html('<a onclick="window.plugin.writhemAPI.enableToggle()">Disable WritheM API</a>');
}
console.log("WritheM API is now: " + window.plugin.writhemAPI.enabled);
}
// PLUGIN END //////////////////////////////////////////////////////////
if(window.iitcLoaded && typeof setup === 'function') {
setup();
} else {
if(window.bootPlugins)
window.bootPlugins.push(setup);
else
window.bootPlugins = [setup];
}
} // 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);