Imperia Online Espionage Extensions

try to take over the world!

  1. // ==UserScript==
  2. // @name Imperia Online Espionage Extensions
  3. // @namespace imperia_espionage
  4. // @version 1.2
  5. // @description try to take over the world!
  6. // @author ChoMPi
  7. // @match http://*.imperiaonline.org/imperia/game_v6/game/village.php*
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // ==/UserScript==
  11. /* jshint -W097 */
  12. 'use strict';
  13.  
  14. function GetSpyRowID(element)
  15. {
  16. return $(element).next().attr('id').replace('hidden-tr-', '');
  17. }
  18.  
  19. function GetSpyNotes()
  20. {
  21. if (typeof localStorage.imperia_spy_notes != 'undefined') {
  22. GM_setValue('imperia_spy_notes', localStorage.imperia_spy_notes);
  23. delete localStorage.imperia_spy_notes;
  24. }
  25. var notes = GM_getValue('imperia_spy_notes', null);
  26. if (notes == null)
  27. return {};
  28. return JSON.parse(notes);
  29. }
  30.  
  31. function GetSpyNote(id)
  32. {
  33. var notes = GetSpyNotes();
  34. if (typeof notes[id] != 'undefined') {
  35. return notes[id];
  36. }
  37. return '';
  38. }
  39.  
  40. function SaveSpyNote(id, note)
  41. {
  42. var notes = GetSpyNotes();
  43. notes[id] = note;
  44. GM_setValue('imperia_spy_notes', JSON.stringify(notes));
  45. }
  46.  
  47. function OnWindowEspionage()
  48. {
  49. var opCenter = $('#operation-center .spy-wrapper');
  50. var dataGrid = $('.data-grid', opCenter);
  51. ProcessEspionageData(dataGrid);
  52. }
  53.  
  54. function LoadEspionageData(data, appendTo)
  55. {
  56. var content = $(data).find('#messageboxEspionageTabs').get(1);
  57. content = $(content).html();
  58. content = $('<div></div>').html(content.replace("<![CDATA[S", "").replace("]]>", ""));
  59. var dataGrid = content.find('.data-grid');
  60. $('tr', dataGrid).first().remove();
  61. ProcessEspionageData(dataGrid);
  62. dataGrid.find('tr').each(function(i, e)
  63. {
  64. appendTo.append($(e));
  65. });
  66. }
  67.  
  68. function ProcessEspionageData(dataGrid)
  69. {
  70. if (dataGrid.length > 0)
  71. {
  72. dataGrid.find('tr.stripe').each(function(i, e)
  73. {
  74. var id = GetSpyRowID(e);
  75. var noteText = GetSpyNote(id);
  76. var lastAttack = GetLastAttackString(id);
  77. if (lastAttack != '')
  78. {
  79. var attackField = $('<div style="font-size:12px; padding-top:3px; color: #632626;">Last attack order: ' + lastAttack + ' ago</div>');
  80. $('td:eq(1)', e).append(attackField);
  81. }
  82. var noteField = $('<div style="font-size:12px; padding-top:3px; color: #675E49; ' + (noteText == '' ? 'display:none;' : '') + '">' + noteText + '</div>');
  83. $('td:eq(1)', e).append(noteField);
  84.  
  85. var form = $('<form onSubmit="return false;" style="display:none;"><textarea rows="2" cols="40"></textarea><br><input class="button" type="submit" value="Save" /></form>');
  86. $('td:eq(1)', e).append(form);
  87. var button = $('<a href="javascript:void(0);" id="' + id + '" class="button icons rename-bookmark" title="Set Note"><span></span></a>');
  88. $('td.actions div', e).append(button);
  89. form.submit(function()
  90. {
  91. SaveSpyNote(id, $('textarea', form).val());
  92. noteField.html($('textarea', form).val());
  93. form.fadeOut('fast', function()
  94. {
  95. if (noteField.html() != '')
  96. noteField.fadeIn('fast');
  97. });
  98. return false;
  99. });
  100. button.click(function()
  101. {
  102. if (form.is(':visible')) {
  103. form.fadeOut('fast', function() {
  104. if (noteField.html() != '') {
  105. noteField.fadeIn('fast');
  106. }
  107. });
  108. } else {
  109. $('textarea', form).val(GetSpyNote(id));
  110. noteField.fadeOut('fast', function() {
  111. form.fadeIn('fast');
  112. });
  113. }
  114. });
  115. });
  116. }
  117. }
  118.  
  119. function GetLastAttacks()
  120. {
  121. if (typeof localStorage.imperia_last_attacks != 'undefined') {
  122. GM_setValue('imperia_last_attacks', localStorage.imperia_last_attacks);
  123. delete localStorage.imperia_last_attacks;
  124. }
  125. var attacks = GM_getValue('imperia_last_attacks', null);
  126. if (attacks == null)
  127. return {};
  128. return JSON.parse(attacks);
  129. }
  130.  
  131. function GetLastAttack(id)
  132. {
  133. var attacks = GetLastAttacks();
  134. if (typeof attacks[id] != 'undefined') {
  135. return parseInt(attacks[id]);
  136. }
  137. return 0;
  138. }
  139.  
  140. function GetLastAttackString(id)
  141. {
  142. var attackTime = GetLastAttack(id);
  143. if (attackTime > 0) {
  144. return timeSince(attackTime);
  145. }
  146. return '';
  147. }
  148.  
  149. function SaveLastAttack(id, time)
  150. {
  151. var attacks = GetLastAttacks();
  152. attacks[id] = time;
  153. GM_setValue('imperia_last_attacks', JSON.stringify(attacks));
  154. }
  155.  
  156. function OnDoAttack(requestData, response)
  157. {
  158. var id;
  159. var userid = requestData.match(/<e><k>dUserId<\/k><v>S(\d+)<\/v><\/e>/)[1];
  160. var provinceid = requestData.match(/<e><k>dProvinceId<\/k><v>S(\d+)<\/v><\/e>/);
  161. var name = requestData.match(/<e><k>dName<\/k><v>S([\_\-\.a-zA-Z0-9]*)<\/v><\/e>/)[1];
  162.  
  163. if (provinceid == null) {
  164. return;
  165. }
  166. // Check if it's NPC or player
  167. if (name == '' || name.substring(0, 3) == 'NPC') {
  168. id = userid + '-' + provinceid[1];
  169. } else {
  170. id = userid + '-' + name;
  171. }
  172. // Check the response for error
  173. if (response.match(/\<cmd cmd\=\"as\" id\=\"errorContainerOperationCenter\" prop\=\"innerHTML\"\>/)) {
  174. return;
  175. }
  176. SaveLastAttack(id, new Date().getTime());
  177. }
  178.  
  179. function OnSpyReport(id)
  180. {
  181. var wind = $('#spy-report-' + id);
  182. var simulatorLinks = $('.icon-simulator').parent().find('a');
  183. simulatorLinks.each(function(i, e) {
  184. // javascript:void(xajax_viewOperationCenter(container.open({saveName:'operation-center', title:'Command Center'}), {tab: 'simulators', subTab: 2, side: 'bottom', simulatorType: 1, spyReportId: 510619}))
  185. //$(e).attr('href', "javascript:void(0)");
  186. $(e).click(function() {
  187. container.open({saveName:'simulation-' + id, title:'Simulators'});
  188. $.post(location.protocol + "//" + location.host + "/imperia/game_v6/game/xajax_loader.php", {
  189. xjxfun: "viewOperationCenter",
  190. xjxr: Date.now(),
  191. xjxargs: ["Soperation-center", "<xjxobj><e><k>tab</k><v>Ssimulators</v></e><e><k>subTab</k><v>N2</v></e><e><k>side</k><v>Sbottom</v></e><e><k>simulatorType</k><v>N1</v></e><e><k>spyReportId</k><v>N" + id + "</v></e><e><k>vexok</k><v>Btrue</v></e></xjxobj>"],
  192. },
  193. function(data) {
  194. var cont = $('#messageboxsimulation-' + id);
  195. var content = $(data).find('xjx').find('cmd').get(2);
  196. var contentHTML = $(content).html();
  197. contentHTML = contentHTML.replace("<![CDATA[S", "").replace("]]>", "");
  198. cont.html(contentHTML);
  199. },
  200. "xml");
  201. });
  202. });
  203. }
  204.  
  205. function addXMLRequestCallback(callback)
  206. {
  207. if (typeof XMLHttpRequest.newCallbacks == 'undefined')
  208. {
  209. XMLHttpRequest.newCallbacks = [callback];
  210. }
  211. else
  212. {
  213. XMLHttpRequest.newCallbacks.push(callback);
  214. return;
  215. }
  216. XMLHttpRequest.oldSend = XMLHttpRequest.prototype.send;
  217. // override the native send()
  218. XMLHttpRequest.prototype.send = function()
  219. {
  220. var self = this;
  221. this.addEventListener("readystatechange", function()
  222. {
  223. if (self.readyState == 4 && self.status == 200) {
  224. for (var i = 0; i < XMLHttpRequest.newCallbacks.length; i++)
  225. {
  226. XMLHttpRequest.newCallbacks[i](self);
  227. }
  228. }
  229. }, false);
  230. this.requestData = (arguments.length > 0) ? decodeURIComponent(arguments[0]) : null;
  231. // call the native send()
  232. XMLHttpRequest.oldSend.apply(this, arguments);
  233. }
  234. }
  235.  
  236. function timeSince(date)
  237. {
  238. var seconds = Math.floor((new Date() - date) / 1000);
  239. var minutes = Math.floor(seconds / 60);
  240. var hours = Math.floor(seconds / 3600);
  241. var days = Math.floor(seconds / 86400);
  242. var months = Math.floor(seconds / 2592000);
  243. var years = Math.floor(seconds / 31536000);
  244.  
  245. if (seconds < 60) {
  246. return Math.floor(seconds) + " seconds";
  247. }
  248. else if (minutes < 60) {
  249. return minutes + ' minute' + (minutes > 1 ? 's' : '');
  250. }
  251. else if (hours < 24) {
  252. return hours + ' hour' + (hours > 1 ? 's' : '');
  253. }
  254. else if (days < 30) {
  255. return days + ' day' + (days > 1 ? 's' : '');
  256. }
  257. else if (months < 12) {
  258. return months + ' month' + (months > 1 ? 's' : '');
  259. }
  260. else {
  261. return years + ' year' + (years > 1 ? 's' : '');
  262. }
  263. }
  264.  
  265. function Init()
  266. {
  267. addXMLRequestCallback(function(xhr) {
  268. if (xhr.requestData != null) {
  269. // Check for the espionage window
  270. if (xhr.requestData.indexOf('xjxfun=viewOperationCenter') > -1 && xhr.requestData.indexOf('dontprocess=1') == -1) {
  271. if (xhr.response.indexOf('tab-espionage active') > -1) {
  272. OnWindowEspionage();
  273. }
  274. }
  275. // Check for attack
  276. if (xhr.requestData.indexOf('xjxfun=doAttack') > -1) {
  277. if (xhr.requestData != null) {
  278. OnDoAttack(xhr.requestData, xhr.response);
  279. }
  280. }
  281. // Check for spy
  282. if (xhr.requestData.indexOf('xjxfun=doSpy') > -1) {
  283. var patt = new RegExp(/<e><k>spy_mission_id<\/k><v>N(\d+)<\/v><\/e>/g);
  284. var id = patt.exec(xhr.requestData);
  285. if (typeof id[1] != 'undefined') {
  286. //OnSpyReport(parseInt(id[1]));
  287. }
  288. }
  289. }
  290. });
  291. }
  292.  
  293. function hookFunction(object, functionName, callback) {
  294. (function(originalFunction) {
  295. object[functionName] = function () {
  296. var returnValue = originalFunction.apply(this, arguments);
  297.  
  298. callback.apply(this, arguments);
  299.  
  300. return returnValue;
  301. };
  302. }(object[functionName]));
  303. }
  304.  
  305. $(document).ready(function()
  306. {
  307. function InitCheck()
  308. {
  309. if (typeof io.showUI != 'undefined')
  310. {
  311. hookFunction(io, 'showUI', function() {
  312. Init();
  313. });
  314. }
  315. else
  316. {
  317. setTimeout(InitCheck, 500);
  318. }
  319. }
  320. InitCheck();
  321. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址