Guest User

Untitled

a guest
Mar 1st, 2017
436
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name Pre Deffing Pack (PDP): Intelligent Tagger (IT) and Find Enemy Offence (FEO)
  3. // @version 2.3
  4. // @author Warre
  5. // @homepageURL https://swtools.programmingtuts.nl/
  6. // @description IT: Fastest and most advanced tagger on tribalwars.nl !
  7. // @description FEO: Find enemy offence and use it in your advantage !
  8. // @include https://*.tribalwars.nl/*
  9. // @exclude https://*.tribalwars.nl/guest.php*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. /** Changelog
  14. * 1.0: - Initiele versie
  15. - Eerste keuring door support
  16. * 1.1: - Verbeteren en logischer ordenen van de code
  17. - Illegaal verklaarde functies herwerkt
  18. - Tweede keuring door support
  19. * 1.2: - Bugfixes
  20. - Verbeteringen van functionaliteit
  21. - Stam acces controle voor FEO verbeterd
  22. - Eerste stamrelease
  23. * 1.3: - Massaal inladen van berichten mogelijk gemaakt
  24. - Bugfixes voor andere werelden
  25. * 2.0: - AF release
  26. - Aanpassingen voor SWtools (login system/database)
  27. - Bugfixes
  28. * 2.1: - Bugfixes http -> https
  29. - Bugfix notitie icoontjes die verdwenen
  30. - Bugfix OSaanvragen tijden
  31. * 2.2: - Verandering van server (twmerge -> sanderscripts)
  32. * 2.3: - Varandering van server (sanderscript -> programmingtuts)
  33. - bugfix bij het exporteren van incommings ging er iets mis met de dorpslink (de tijd kwam er bij te staan)
  34. - bugfix wanneer de vijand in zijn dorpen coords gebruikte, waardoor je meerdere coords kreeg in de notatie, werkte er niks meer juist (tagger niet, dubbelen niet, database niet)
  35. **/
  36.  
  37. function PDPScriptCode() {
  38.  
  39. /********************************
  40. ** GENERALS **
  41. ********************************/
  42.  
  43. // SWtools keycode //
  44. var keycode = 'uRlDr7dsvvXcLdvNQyiyCTRq';
  45.  
  46. // game_data //
  47. var world = game_data.world;
  48. var allyid = game_data.player.ally;
  49. var playerid = game_data.player.id;
  50.  
  51. // Standard Settings //
  52. // Thx to Tuam for this function
  53. function get_WSettings(){
  54. var units_available = [], unit_speed = [], unit_population = [];
  55. $.ajax({
  56. url: 'https://'+location.host+'/interface.php?func=get_unit_info',
  57. success: function (xml) {
  58. $(xml).find('config').children().each(function(k,v){
  59. units_available.push($(this).prop('nodeName'));
  60. unit_speed.push($(this).find('speed').text());
  61. unit_population.push($(this).find('pop').text());
  62. });
  63. $.ajax({
  64. url: 'https://'+location.host+'/interface.php?func=get_building_info',
  65. success: function (xml2) {
  66. var church = ($(xml2).find('church').length>0?true:false);
  67. var militia = ($(xml).find('militia').length>0?true:false);
  68. var archer = (units_available.indexOf('archer')!=-1?true:false);
  69. $.ajax({
  70. url: 'https://'+location.host+'/interface.php?func=get_config',
  71. success: function (xml3) {
  72. var speed = parseInt($(xml3).find('speed').text())*parseInt($(xml3).find('unit_speed').text());
  73. var start_night = 0, end_night = 0;
  74. if ($(xml3).find('night active').text() == '1') {
  75. start_night = $(xml3).find('start_hour').text();
  76. end_night = $(xml3).find('end_hour').text();
  77. }
  78. var edelmax = $(xml3).find('max_dist').text();
  79. world_settings = {
  80. 'units' : units_available,
  81. 'unit_spd' : unit_speed,
  82. 'unit_pop' : unit_population,
  83. 'church' : church,
  84. 'militia' : militia,
  85. 'archer' : archer,
  86. 'speed' : speed,
  87. 'n_start' : start_night,
  88. 'n_end' : end_night,
  89. 'edelmax' : edelmax,
  90. 'version' : '1.0'
  91. };
  92. localStorage.setItem('WWorldSettings_'+world, JSON.stringify(world_settings));
  93. }
  94. });
  95. }
  96. });
  97. }
  98. });
  99. }
  100. if (!localStorage.getItem('WWorldSettings_'+world)) get_WSettings();
  101. else WS = JSON.parse(localStorage.getItem('WWorldSettings_'+world));
  102. if (WS.version != '1.0') get_WSettings();
  103.  
  104. // IT //
  105. var units = ['Scouts', 'Lc', 'Zc', 'Bijl', 'Zwaard', 'Ram/Kata', '**EDEL**'];
  106. var unitsimgs = ['spy', 'light', 'heavy', 'axe', 'sword', 'ram', 'snob'];
  107. var edelmax = parseInt(WS.edelmax);
  108. var unitspeed = [];
  109. for (i=0;i<unitsimgs.length;i++) {
  110. for (j=0;j<WS.units.length;j++) {
  111. if (unitsimgs[i] == WS.units[j]) {
  112. unitspeed.push(WS.unit_spd[j]);
  113. }
  114. }
  115. }
  116.  
  117. // caching //
  118. var $incommings_tableTR = $('#incomings_table').find('tr');
  119. var $div_filters = $('div.overview_filters');
  120. var $div_filtersINPUT = $div_filters.find('input[type="text"]');
  121. var $div_filtersTDL = $div_filters.find('td:last');
  122. var $overview_filters = $('div.overview_filters');
  123. var $footer_link = $('#linkContainer').find('a:last');
  124.  
  125. /********************************
  126. ** SETTINGS **
  127. ********************************/
  128.  
  129. if (localStorage.getItem('PDP_Settings_'+world) == null) {
  130. PDP_DefaultSettings = {
  131. fake_pop: 9000,
  132. clear_build_time: 14,
  133. deffs_needed : [0,2,3,4,5,6,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,11,11,11,11,11,12,12,12,12,12]
  134. };
  135. localStorage.setItem('PDP_Settings_'+world, JSON.stringify(PDP_DefaultSettings));
  136. }
  137. var PDP_Settings = JSON.parse(localStorage.getItem('PDP_Settings_'+world));
  138.  
  139. if (localStorage.getItem('FEO_reports_'+world+'_'+playerid) == null) {
  140. FEO_DefaultRaps = {
  141. ids: [],
  142. timestamps: []
  143. };
  144. localStorage.setItem('FEO_reports_'+world+'_'+playerid, JSON.stringify(FEO_DefaultRaps));
  145. }
  146. var FEO_Reports = JSON.parse(localStorage.getItem('FEO_reports_'+world+'_'+playerid));
  147.  
  148. // holiday mode //
  149. var h_mode = '';
  150. if (game_data.player.sitter != '0') h_mode = '&t='+game_data.player.id;
  151.  
  152. /********************************
  153. ** USERSCRIPT **
  154. ********************************/
  155.  
  156. /** ==Functions== **/
  157. // General functions //
  158. function IT_FadeOutMessage(message, length, clickclose, stayVisible, close, width) {
  159. if (!clickclose) {$('.IT_message').on('click', function(){$('.IT_message').fadeOut(100, function(){$('.IT_message').attr('style', 'display:none;')})});}
  160. if (!stayVisible) {setInterval(function(){$('.IT_message').fadeOut(1000, function(){$('.IT_message').attr('style', 'display:none;')})}, length);}
  161. if (close) {close = '<br><br><br><a href="javascript: $(\'.IT_message\').remove();void(0);" style="float:right;">&raquo; Sluiten &laquo;</a>';} else {close = '';}
  162. var style = 'position:fixed;overflow:auto;top:100px;max-height:'+(window.outerHeight-300)+'px;width:'+width+'px;left:'+(window.outerWidth/2-(width/2))+'px;background-color:#e8d4a9;border:2px solid #804000;padding:10px;text-align:center;font-size:12px;z-index:15000;box-shadow:0 0 50px 0px #000000;';
  163. $('body').append('<div class="IT_message" style="'+style+'">'+ message + close + '</div>');
  164. }
  165.  
  166. // IT functions //
  167. function SaveTimestamp() {
  168. var curTimestampSave = new Date().getTime();
  169. localStorage.setItem('IT_savedTimestamp_'+world+'_'+playerid, curTimestampSave);
  170. }
  171.  
  172. function getMin(str) {
  173. var p = str.split(':'),
  174. s = 0, m = 1;
  175.  
  176. while (p.length > 0) {
  177. s += m * parseInt(p.pop(), 10);
  178. m *= 60;
  179. }
  180.  
  181. return s/60;
  182. }
  183.  
  184. function getDis (targetC, originC) {
  185. targetC = targetC.split('|');
  186. originC = originC.split('|');
  187. return Math.sqrt(((originC[0]-targetC[0])*(originC[0]-targetC[0])+(originC[1]-targetC[1])*(originC[1]-targetC[1])));
  188. }
  189.  
  190. function zeropad(n) {
  191. n = Math.floor(n);
  192. return n > 9 ? n : '0' + n;
  193. }
  194.  
  195. function formatDuration(m) {
  196. return zeropad(m/60)+':'+zeropad(m%60)+':'+zeropad(Math.round(m%1 * 60));
  197. }
  198.  
  199. function OpenFirst(id) {
  200. IT_FadeOutMessage("Eerste bevel wordt automatisch geopent.", 2000, false, false, false);
  201. location.href = '/game.php?village='+game_data.village.id+'&id='+id+'&type=other&screen=info_command'+h_mode;
  202. }
  203.  
  204. function ColorBackGround(id) {
  205. $('span.quickedit[data-id="'+id+'"]').closest('tr').children().css('background-color', '#e0f289');
  206. }
  207.  
  208. function sendAjax(id, val) {
  209. var IT_post_url = game_data.link_base_pure + 'info_command&ajaxaction=edit_other_comment&id='+id+'&h='+game_data.csrf;
  210. $.ajax({
  211. url: IT_post_url,
  212. type: 'POST',
  213. data: {text: val},
  214. success: function(){
  215. $('span.quickedit[data-id="'+id+'"]').find('span.quickedit-label').text(val);
  216. ColorBackGround(id);
  217. }
  218. });
  219. }
  220.  
  221. function CheckTribeInfo(id, player) {
  222. var tribeinfo = JSON.parse(localStorage.getItem('IT_tribeinfo_'+world+'_'+allyid));
  223. if (tribeinfo != null) {
  224. var playerss = tribeinfo.players;
  225. for (var g=0;g<playerss.length;g++) { // for loop voor tribe players
  226. if (player == playerss[g]) { // controle of het een aanval van een speler van de stam is of niet
  227. if (player == game_data.player.name) { // controle of het aanval van jezelf is
  228. return 'own';
  229. } else {
  230. return 'tribe';
  231. }
  232. }
  233. }
  234. }
  235. }
  236.  
  237. function rename(id, yn, pl, unit, coord, dis, front) {
  238. if (yn != 'multiid') {
  239. var val = '';
  240. var TribeInfo = CheckTribeInfo(id, pl);
  241. if (TribeInfo == 'own') {
  242. val = 'MARKEREN EIGEN';
  243. } else if (TribeInfo == 'tribe') {
  244. val = 'MARKEREN STAM ('+pl+')';
  245. } else if (yn == 'other') {
  246. val = 'MARKEREN '+unit+' ('+coord+') '+pl+' F'+Math.round(dis);
  247. } else if (yn == 'rename') {
  248. val = front+' '+unit+' ('+coord+') '+pl+' F'+Math.round(dis);
  249. }
  250.  
  251. if (val != '') {
  252. sendAjax(id, val);
  253. }
  254. } else {
  255. for (var i=0;i<id.length;i++) {
  256. if (i == id.length-1) var val = 'IT_0';
  257. else var val = 'IT_'+id[i+1];
  258. sendAjax(id[i], val);
  259. }
  260. OpenFirst(id[0]);
  261. }
  262. }
  263.  
  264. function uniek(input) {
  265. var output = [];
  266. input.sort(); var prev;
  267. for (var i=0;i<input.length;i++) {
  268. if (input[i] !== prev) {
  269. output.push(input[i]);
  270. }
  271. prev = input[i];
  272. }
  273. return output;
  274. }
  275.  
  276. // FEO functions //
  277. function getServertimeTimestamp(small) {
  278. var timestr = ($('#serverDate').text()+' '+$('#serverTime').text()).split(' ');
  279. // date
  280. var d = timestr[0].split('/');
  281. var D = d[1]+' '+d[0]+', '+d[2];
  282. // time
  283. var T = timestr[1];
  284. // result
  285. if (small) var timestamp = (Date.parse(D+' '+T))/1000;
  286. else var timestamp = Date.parse(D+' '+T);
  287. return timestamp;
  288. }
  289.  
  290. function formatTimeFromTimestamp(unixTimestamp) {
  291. function pad(number) {
  292. var str = '' + number;
  293. while (str.length < 2) {
  294. str = '0' + str;
  295. }
  296. return str;
  297. }
  298.  
  299. var dt = new Date(unixTimestamp * 1);
  300. var day = dt.getDate();
  301. var month = dt.getMonth() + 1;
  302. var year = String(dt.getFullYear()).slice(2);
  303. var hours = dt.getHours();
  304. var minutes = dt.getMinutes();
  305. var seconds = dt.getSeconds();
  306.  
  307. return pad(day) + '.' + pad(month) + '.' + pad(year) + ' ' + pad(hours) + ":" + pad(minutes) + ":" + pad(seconds);
  308. }
  309.  
  310. function twTimeToTimestamp(timestr) {
  311. // 02.12.13 21:26:22:500
  312. if (timestr.match(/\:/g).length == 3) {
  313. timestr = timestr.split(/:(?!.*:)/)[0]; // remove milliseconds
  314. }
  315.  
  316. timestr = timestr.split(' ');
  317. // date
  318. var d = timestr[0].split('.');
  319. var D = d[1]+' '+d[0]+', 20'+d[2];
  320. // time
  321. var T = timestr[1];
  322. // result
  323. var timestamp = Date.parse(D+' '+T);
  324. return timestamp;
  325. }
  326.  
  327. function addFEOtoRow() {
  328. $('#report_list').find('tr').not(':contains("Onderwerp")').not(':contains("alles selecteren")').not(':contains("Filter")').each(function() {
  329. if ($(this).find('#FEO_span').length == 0) {
  330. var raps_id = $(this).find('span.quickedit').eq(0).attr('data-id');
  331. if (FEO_Reports.ids.indexOf(raps_id) == -1) {
  332. // add td ( V = &#10004; - X = &#10008;)
  333. $(this).find('td:eq(2)').after('<td FEO_remove="remove" style="font-size:14px;text-align:center;"><span id="FEO_span" class="FEO_span" style="color:red;">&#10008;</span></td>');
  334. // change tr
  335. $(this).attr('FEO_class', 'not_done');
  336. } else {
  337. // add td ( V = &#10004; - X = &#10008;)
  338. $(this).find('td:eq(2)').after('<td FEO_remove="remove" style="font-size:14px;text-align:center;"><span id="FEO_span" class="FEO_span" style="color:green;">&#10004;</span></td>');
  339. // change tr
  340. $(this).attr('FEO_class', 'done');
  341. }
  342. }
  343. });
  344. }
  345.  
  346. function changeDone(element) {
  347. // changing table
  348. element.attr('FEO_class', 'done')
  349. element.find('span#FEO_span').css('color', 'green');
  350. element.find('span#FEO_span').html('&#10004;');
  351. ColorBackGround(element.find('span.quickedit').attr('data-id'));
  352.  
  353. // changing localstorage
  354. FEO_Reports.ids.push(element.find('span.quickedit').attr('data-id'));
  355. FEO_Reports.timestamps.push(getServertimeTimestamp(true));
  356. localStorage.setItem('FEO_reports_'+world+'_'+playerid, JSON.stringify(FEO_Reports));
  357.  
  358. // check for last
  359. if ($('#report_list').find('tr[FEO_class="not_done"]').length == 0) {
  360. IT_FadeOutMessage("<b>Berichten inlezen voltooid !</b>", 5000, true, false, false, 400);
  361. }
  362. }
  363.  
  364. function SendInfo(ajax, html, element) {
  365. // get info
  366. var $FEO_past_result = $('#FEO_past_result');
  367.  
  368. if (ajax) {
  369. var $info_attTR = $(html).find('#attack_info_att').find('tr');
  370. var Time = twTimeToTimestamp($.trim($(html).find('td:contains("Gevechtstijd")').next('td').text()));
  371. var att_troops = $(html).find('#attack_info_att_units tr:eq(1) td.unit-item');
  372. var att_troops_left = $(html).find('#attack_info_att_units tr:eq(2) td.unit-item');
  373. } else {
  374. var $info_attTR = $('#attack_info_att').find('tr');
  375. var Time = twTimeToTimestamp($.trim($('td:contains("Gevechtstijd")').next('td').text()));
  376. var att_troops = $('#attack_info_att_units tr:eq(1) td.unit-item');
  377. var att_troops_left = $('#attack_info_att_units tr:eq(2) td.unit-item');
  378. }
  379.  
  380. var VillageID = $info_attTR.eq(1).find('td').eq(1).find('a').attr('href').match(/&id=\d+/).toString().match(/\d+/);
  381. var Coords = $info_attTR.eq(1).find('td').eq(1).find('a').text().match(/\d+\|\d+/);
  382. var Attacker_ID = $info_attTR.eq(0).find('th').eq(1).find('a').attr('href').match(/&id=\d+/).toString().match(/\d+/);
  383. var Attacker = $.trim($info_attTR.eq(0).find('th').eq(1).find('a').eq(0).text());
  384. var Tribe = $info_attTR.eq(0).find('th').eq(1).find('a').attr('title');
  385.  
  386. var Troops = [];
  387. var Troops_Left = [];
  388. for (var i=0;i<att_troops.length;i++) {
  389. Troops.push(att_troops.eq(i).text());
  390. Troops_Left.push(att_troops.eq(i).text()-att_troops_left.eq(i).text());
  391. }
  392.  
  393. // ajax
  394. var url = 'https://swtools.programmingtuts.nl/PDP/SendInfo.php?game_data='+encodeURIComponent(JSON.stringify(game_data))+'&VillageID='+VillageID+'&Coords='+Coords+'&Attacker='+Attacker+'&Attacker_ID='+Attacker_ID+'&Tribe='+Tribe+'&Time='+Time+'&Troops='+Troops+'&Troops_Left='+Troops_Left+'&keycode='+keycode;
  395. //alert(url);
  396. $.ajax({
  397. url: url,
  398. dataType: 'jsonp',
  399. success: function (data) {
  400. if (ajax) {
  401. if (data['return']) {
  402. changeDone(element);
  403. } else {
  404. alert('FEO: error code 1');
  405. }
  406. } else {
  407. // changing localstorage
  408. FEO_Reports.ids.push($('span.quickedit').eq(0).attr('data-id'));
  409. FEO_Reports.timestamps.push(getServertimeTimestamp(true));
  410. localStorage.setItem('FEO_reports_'+world+'_'+playerid, JSON.stringify(FEO_Reports));
  411. $FEO_past_result.append(data.msg);
  412. }
  413. },
  414. error: function (xhr, status, err) {
  415. if (ajax) {
  416. alert('FEO: error code 2');
  417. } else {
  418. $FEO_past_result.append('FEO: error');
  419. }
  420. }
  421. })
  422. }
  423.  
  424. function DeleteInfo(Coords) {
  425. var conf = confirm("FEO: zeker verwijderen ?");
  426. if (conf == true) {
  427. // ajax
  428. var url = 'https://swtools.programmingtuts.nl/PDP/DeleteInfo.php?game_data='+encodeURIComponent(JSON.stringify(game_data))+'&Coords='+Coords+'&keycode='+keycode;
  429. $.ajax({
  430. url: url,
  431. dataType: 'jsonp',
  432. success: function (data) {
  433. alert('FEO: '+data.msg);
  434. },
  435. error: function (xhr, status, err) {
  436. alert('FEO: error');
  437. }
  438. })
  439. } else {
  440. alert('FEO: verwijderen geannuleerd');
  441. }
  442. }
  443.  
  444. function FEO_rename(id, kind, digit) {
  445. var PrevVal = $.trim($('span.quickedit[data-id="'+id+'"]').find('span.quickedit-label').text());
  446. if (kind == '%') {
  447. if (!PrevVal.match(/\[\d+%\]/)) {
  448. var NewVal = PrevVal+' ['+digit+'%]';
  449. } else {
  450. var NewVal = PrevVal.replace(/\[\d+%\]/, '['+digit+'%]');
  451. }
  452. } else if (kind == 'x') {
  453. if (!PrevVal.match(/\[\d+x\]/)) {
  454. var NewVal = PrevVal+' ['+digit+'x]';
  455. } else {
  456. var NewVal = PrevVal.replace(/\[\d+x\]/, '['+digit+'x]');
  457. }
  458. }
  459. sendAjax(id, NewVal);
  460. }
  461.  
  462. // OSaanvragen functions //
  463. function makeTimestamp(timestr) {
  464. // vandaag om 16:49:08 uur
  465. // op 21.08. om 05:04:11 uur
  466. var pos = timestr.indexOf(':');
  467. var T = timestr.substr(pos - 2, 8); //+','+MS;
  468.  
  469. var Serverdate = $('#serverDate').text().split('/');
  470. Serverdate = Serverdate[1] + ' ' + Serverdate[0] + ', ' + Serverdate[2];
  471. var Serverdate = new Date(Date.parse(Serverdate + ' ' + T));
  472.  
  473. if (timestr.match('vandaag')) {
  474. var D = Serverdate;
  475. } else if (timestr.match('morgen')) {
  476. var D = Serverdate;
  477. D.setDate(D.getDate() + 1);
  478. } else {
  479. var pos = timestr.indexOf('.');
  480. var d = timestr.substr(pos - 2, 5).split('.');
  481. d = d[1] + '/' + d[0] + '/' + Serverdate.getFullYear() + ' ' + T;
  482. var D = new Date(Date.parse(d));
  483. }
  484. return D.getTime()/1000;
  485. }
  486.  
  487. function makeTime(OneCommand, timestr) {
  488. // vandaag om 16:49:08 uur
  489. // op 21.08. om 05:04:11 uur
  490. var T = timestr.match(/\d+\:\d+\:\d+/);
  491. var ServerDate = $('#serverDate').text().split('/');
  492. var daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
  493.  
  494. if (timestr.match('vandaag')) {
  495. var D = ServerDate[0]+'.'+ServerDate[1]+'.';
  496. } else if (timestr.match('morgen')) {
  497. var tomorrow = parseInt(ServerDate[0], 10) + 1;
  498. if (tomorrow > daysInMonth[ServerDate[1]]) {
  499. tomorrow = 1;
  500. var m = parseInt(ServerDate[1], 10) + 1;
  501. } else {
  502. var m = ServerDate[1];
  503. }
  504. var D = tomorrow+'.'+m+'.';
  505. } else {
  506. var D = timestr.match(/\d+\.\d+\./);
  507. }
  508.  
  509. if (OneCommand) {
  510. T = T.toString().split(':');
  511. return D+ServerDate[2]+' '+T[0]+':'+T[1];
  512. } else {
  513. return 'VOOR '+D+' om '+T;
  514. }
  515. }
  516.  
  517. function getInfoFromVillage(id, WS_UP, callback) {
  518. $.ajax({
  519. url: 'https://'+location.host+'/game.php?village='+id+'&screen=overview',
  520. datatype: 'html',
  521. async: false,
  522. success: function(html) {
  523. // inc atts
  524. var Inc_Atts = $(html).find('#show_incoming_units').find('img[src*="command/attack.png"]').length;
  525.  
  526. //wall
  527. var Wall = html.split('"wall":"')[1].split('"')[0];
  528.  
  529. // own_deffs
  530. var pop = 0;
  531. $(html).find('#show_units').find('.unit_link').each(function () {
  532. var unit = $(this).find('img').attr('src').split('unit_')[1].split('.png')[0];
  533. var unit_index = WS.units.indexOf(unit);
  534.  
  535. var number = $(this).next('strong').text();
  536.  
  537. var addPOP = number * WS_UP[unit_index];
  538.  
  539. pop = pop + addPOP;
  540. });
  541. var Own_Deffs = Math.round(pop / 20400 * 100) / 100;
  542.  
  543. // inc deffs
  544. var Inc_Deffs = $(html).find('#show_incoming_units').find('img[src*="command/support.png"]').length;
  545.  
  546. // church
  547. var Wchurch, church;
  548. if (WS.church) {
  549. Wchurch = true;
  550. church = ($(html).find('#show_effects div.widget_content td.effect_tooltip').text().match(/Niet gelovig/)) ? false : true;
  551. } else {
  552. Wchurch = false;
  553. }
  554.  
  555. //callback
  556. callback([Inc_Atts, Wall, Own_Deffs, Inc_Deffs, Wchurch, church]);
  557. },
  558. error: function () {
  559. callback(['error', 'error', 'error', 'error', 'error', 'error']);
  560. }
  561. });
  562. }
  563.  
  564. /** ==Pages== **/
  565. // On all pages //
  566. if ($('img[title="Binnenkomende aanvallen"]')) {
  567. var linkandimg = '<a style="vertical-align: middle" href="/game.php?village='+game_data.village.id+'&subtype=attacks&mode=incomings&group=0&page=-1&screen=overview_villages'+h_mode+'">';
  568. linkandimg += '<img src="https://swtools.programmingtuts.nl/PDP/images/att_red.png" FEO_remove="remove" title="Binnenkomende aanvallen voor taggen" style="vertical-align: -2px" alt="" class=""/>';
  569. $('img[title="Binnenkomende aanvallen"]').parent('a').before(linkandimg);
  570. }
  571.  
  572. var tribeinfo = JSON.parse(localStorage.getItem('IT_tribeinfo_'+world+'_'+allyid));
  573. var huidigetimestamp = new Date().getTime();
  574. if (tribeinfo == null || parseInt(tribeinfo.timestamp+604800000) < huidigetimestamp) {
  575. var tribe = {timestamp: 0, tribename: '', players: []};
  576. var url = 'https://'+world+'.tribalwars.nl/game.php?mode=members&screen=ally'+h_mode;
  577. $.ajax({
  578. url: url,
  579. dataType: 'html',
  580. async: false,
  581. success: function (html) {
  582. tribe.timestamp = new Date().getTime();
  583. tribe.tribename = $.trim($(html).find('#content_value').find('h2').eq(0).text());
  584. var players = $(html).find('#ally_content').find('a[href$="&screen=info_player"]');
  585. for (i=0;i<players.length;i++) {
  586. tribe.players.push(players.eq(i).text());
  587. }
  588. localStorage.setItem('IT_tribeinfo_'+world+'_'+allyid, JSON.stringify(tribe));
  589. },
  590. error: function (xhr, status, err) {
  591. alert('Fout in Intelligent_Tagger.\nEr is mogelijk iets mis gegaan bij de controle voor incomings van stamgenoten of jezelf.\nEr zal gewoon getagd worden zonder hier rekening mee te houden.');
  592. }
  593. })
  594. }
  595.  
  596. // Incomings Overview page //
  597. if (game_data.screen == 'overview_villages' && $('th:contains("Filter binnenkomende bevelen")').length != 0) {
  598. // Add next page (Thx to .Arrogant)
  599. $(".paged-nav-item").last().after('<a id="LoadNextPage" href="#">[FEO: Volgende pagina laden]</a>');
  600. var currentPageNumber = location.href.match(/page=\d+/);
  601. var newPageNumber = location.href.match(/page=\d+/) > 0 ? 0 : 1;
  602. $("#LoadNextPage").on('click', function(){
  603. if (newPageNumber == currentPageNumber) {
  604. newPageNumber++
  605. }
  606. var nextpage = location.href.replace(/page=\d+/, "page="+newPageNumber);
  607. $.ajax({
  608. url: nextpage,
  609. success: function (result) {
  610. $(".overview_table .nowrap").last().after($("#incomings_table .nowrap", result));
  611. var headerColumn = $('.overview_table').find('th:contains("Bevel")');
  612. var newCount = $('.overview_table').find('tr.nowrap').length;
  613. headerColumn.text(headerColumn.text().replace(parseInt($.trim(headerColumn.text()).match(/\d+/)), newCount))
  614. },
  615. error: function() {
  616. alert('De volgende pagina kon niet geladen worden');
  617. }
  618. })
  619. $("#paged_view_content .vis tr:first-child a:contains('"+(newPageNumber + 1)+"')").length > 0 ? $("#paged_view_content .vis tr:first-child a:contains('"+(newPageNumber + 1)+"')").replaceWith('<strong>'+$("#paged_view_content .vis tr:first-child a:contains('"+(newPageNumber + 1)+"')").html()+'</strong>') : '';
  620. if(parseInt($("#paged_view_content .vis tr:first-child select option:last").text()) - 1 == newPageNumber || $('a.paged-nav-item').length == 1) {
  621. $("#paged_view_content .vis tr:first-child a.paged-nav-item").replaceWith('<strong>'+$("#paged_view_content .vis tr:first-child a.paged-nav-item").html()+'</strong>')
  622. $("#LoadNextPage").remove();
  623. }
  624. newPageNumber++;
  625. });
  626.  
  627. // place icons
  628. for (var i=1;i<$incommings_tableTR.length-1;i++) {
  629. $incommings_tableTR.eq(i).find('td').eq(0).find('img').not(':first').remove(); // remove other images
  630. var incName = $incommings_tableTR.eq(i).find('.quickedit-label:first').text();
  631. for (j=0;j<units.length;j++) {
  632. if (units[j].match('EDEL')) var match = /\*\*EDEL\*\*/;
  633. else var match = units[j];
  634. if (incName.match(match)) {
  635. $incommings_tableTR.eq(i).find('td').eq(0).find('img:first').attr('src', 'https://cdn.tribalwars.net/graphic/unit/tiny/'+unitsimgs[j]+'.png');
  636. }
  637. }
  638. }
  639.  
  640. // Expand Filters //
  641. // drop down info
  642. var doel = {name:[], coord:[], c:[]};
  643. var herkomst = {name:[], coord: [], c:[]};
  644. var speler = [];
  645. for (var i=1;i<$incommings_tableTR.length-1;i++) {
  646. var doel_text = $.trim($incommings_tableTR.eq(i).find('td').eq(1).text());
  647. var doel_split = doel_text.split(/\(\d+\|\d+\)/);
  648. doel.name.push(doel_split[0]);
  649. doel.coord.push(doel_text.match(/\d{1,3}\|\d{1,3}/g).slice(-1)[0].toString());
  650. doel.c.push(doel_split[1]);
  651.  
  652. var herkomst_text = $.trim($incommings_tableTR.eq(i).find('td').eq(2).text());
  653. var herkomst_split = herkomst_text.split(/\(\d+\|\d+\)/);
  654. herkomst.name.push(herkomst_split[0]);
  655. herkomst.coord.push(herkomst_text.match(/\d{1,3}\|\d{1,3}/g).slice(-1)[0].toString());
  656. herkomst.c.push(herkomst_split[1]);
  657.  
  658. var speler_text = $.trim($incommings_tableTR.eq(i).find('td').eq(3).text());
  659. speler.push(speler_text);
  660. }
  661.  
  662. // making uniek
  663. doel.name = uniek(doel.name);
  664. doel.coord = uniek(doel.coord);
  665. doel.c = uniek(doel.c);
  666. herkomst.name = uniek(herkomst.name);
  667. herkomst.coord = uniek(herkomst.coord);
  668. herkomst.c = uniek(herkomst.c);
  669. speler = uniek(speler);
  670.  
  671. // prepare drop downs
  672. var label_opties = ['aanval', 'markeren', 'ok', 'dodge ', 'dodged', 'bijstacken', 'gevraagd', 'dubbel', 'fake', 'dodge eigen os'];
  673. var label_dropdown = '&nbsp;&nbsp;<select id="label_dropdown" style="width:130px;"><option></option>';
  674. for (var i=0;i<label_opties.length;i++){label_dropdown += '<option value="'+label_opties[i]+'">'+label_opties[i]+'</option>';}
  675. label_dropdown += '</select>';
  676.  
  677. var doel_dropdown = '&nbsp;&nbsp;<select id="doel_dropdown" style="width:130px;"><option></option>';
  678. doel_dropdown += '<optgroup label="Dorpsnaam">';
  679. for (var i=0;i<doel.name.length;i++){doel_dropdown += '<option value="'+doel.name[i]+'">'+doel.name[i]+'</option>';}
  680. doel_dropdown += '<optgroup label="Coords">';
  681. for (var i=0;i<doel.coord.length;i++){doel_dropdown += '<option value="'+doel.coord[i]+'">'+doel.coord[i]+'</option>';}
  682. doel_dropdown += '<optgroup label="Continent">';
  683. for (var i=0;i<doel.c.length;i++){doel_dropdown += '<option value="'+doel.c[i]+'">'+doel.c[i]+'</option>';}
  684. doel_dropdown += '</select>';
  685.  
  686. var herkomst_dropdown = '&nbsp;&nbsp;<select id="herkomst_dropdown" style="width:130px;"><option></option>';
  687. herkomst_dropdown += '<optgroup label="Dorpsnaam">';
  688. for (var i=0;i<herkomst.name.length;i++){herkomst_dropdown += '<option value="'+herkomst.name[i]+'">'+herkomst.name[i]+'</option>';}
  689. herkomst_dropdown += '<optgroup label="Coords">';
  690. for (var i=0;i<herkomst.coord.length;i++){herkomst_dropdown += '<option value="'+herkomst.coord[i]+'">'+herkomst.coord[i]+'</option>';}
  691. herkomst_dropdown += '<optgroup label="Continent">';
  692. for (var i=0;i<herkomst.c.length;i++){herkomst_dropdown += '<option value="'+herkomst.c[i]+'">'+herkomst.c[i]+'</option>';}
  693. herkomst_dropdown += '</select>';
  694.  
  695. var speler_dropdown = '&nbsp;&nbsp;<select id="herkomst_dropdown" style="width:130px;"><option></option>';
  696. for (var i=0;i<speler.length;i++){speler_dropdown += '<option value="'+speler[i]+'">'+speler[i]+'</option>';}
  697. speler_dropdown += '</select>';
  698.  
  699. // add drop downs
  700. $div_filtersINPUT.eq(0).after(label_dropdown);
  701. $div_filtersINPUT.eq(1).after(doel_dropdown);
  702. $div_filtersINPUT.eq(2).after(herkomst_dropdown);
  703. $div_filtersINPUT.eq(3).after(speler_dropdown);
  704.  
  705. // remove filters
  706. $div_filtersTDL.removeAttr('class');
  707. $div_filtersTDL.find('input').attr('id', 'saveandreload');
  708. $div_filtersTDL.append('<input type="submit" id="removefilters" value="Verwijder filters" class="btn" style="float:right;"/>');
  709. $('#removefilters').on('click', function(){
  710. $('.overview_filters_delete').click();
  711. });
  712.  
  713. // dorp down actions
  714. $div_filters.find('option').on('click', function() {
  715. var $this = $(this);
  716. $this.closest('select').prev('input').val($this.val());
  717. $('#saveandreload').click();
  718. });
  719.  
  720. // adding menu //
  721. $('.overview_filters_manage').html('&raquo; Filters en PDP tonen of verbergen');
  722.  
  723. $overview_filters.attr('style', 'margin-bottom: 160px');
  724. $overview_filters.find('table:eq(0)').attr('align', 'left');
  725. var PDP_table = '<table class="vis center" align="left" style="margin-left:20px;"><tr><th title="Pre Deffing Pack" colspan="4"><center>Pre Deffing Pack</center></th></tr>';
  726. PDP_table += '<tr>';
  727. PDP_table += '<th title="Intelligent Tagger"><center>IT</center></th><th title="Find Enemy Offence"><center>FEO</center></th><th title="Ondersteuning aanvragen"><center>OSaanvragen</center></th><th title="Instellingen"><center>Settings</center></th>';
  728. PDP_table += '</tr><tr>';
  729. PDP_table += '<td><input type="button" class="IT_button btn" id="IT_taggen" title="Gewoon taggen" value="Taggen"></td>';
  730. PDP_table += '<td><input type="button" class="btn" id="FEO_database" title="Check de database voor info.\nVorige info wordt niet geupdate!" value="Check database"></td>';
  731. PDP_table += '<td><input type="button" class="btn" id="PDP_select_all" title="Selecteer alle incommings op deze pagina" value="Alles selecteren"></td>';
  732. PDP_table += '<td><input type="button" class="btn" id="PDP_Settings" title="Open instellingen menu" value="Instellingen"></td>';
  733. PDP_table += '</tr><tr>';
  734. PDP_table += '<td><input type="button" class="IT_button btn" id="IT_hmtaggen" title="Handmatig taggen" value="Handmatig"></td>';
  735. PDP_table += '<td><input type="button" class="btn" id="FEO_dubbel" title="Check voor meerdere incommings uit zelfde dorp.\nVorige info wordt geupdate!" value="Check dubbel"></td>';
  736. PDP_table += '<td><input type="button" class="PDP_Export btn" id="PDP_Export" title="Exporteer de geselecteerde incommings" value="Incommings exporteren"></td>';
  737. PDP_table += '<td></td></tr><tr><td><input type="button" class="IT_button btn" id="IT_rename" title="Herbenoem bevelen" value="Rename"></td>';
  738. PDP_table += '<td><input type="button" class="btn" id="FEO_request" title="Haal coords van OFF dorpen op per speler." value="Ophalen coords"></td>';
  739. PDP_table += '<td></td><td></td></tr><tr></center></table>';
  740. $overview_filters.append(PDP_table);
  741.  
  742. // Settings
  743. $('#PDP_Settings').on('click', function(){
  744. var settings_prompt = '<span class="PDPS_content"><h2>Pre Deffing Pack: Instellingen</h2><table class="vis" style="width:100%;border-collapse:separate;border-spacing:2px;text-align:left;">';
  745. settings_prompt += '<tr><th colspan="2" style="padding:3px;text-align:center;">Find Enemy Offence [FEO]</th></tr>';
  746. settings_prompt += '<tr><td style="padding:3px;" title="Wordt gebruikt om te bepalen of het een fake of een clear is."><b>Fake populatie:</b></td><td style="padding:3px;"><input type="text" id="FEO_fake_pop" value="'+PDP_Settings.fake_pop+'" style="width:98%"></td></tr>';
  747. settings_prompt += '<tr><td style="padding:3px;" title="Wordt gebruikt om procenten uit te rekenen."><b>Clear bouwtijd (in dagen):</b></td><td style="padding:3px;"><input type="text" id="FEO_clear_build_time" value="'+PDP_Settings.clear_build_time+'" style="width:98%"></td></tr>';
  748. settings_prompt += '<tr><td colspan="2" style="height:15px;"></td></tr>';
  749. settings_prompt += '<tr><th colspan="2" style="padding:3px;text-align:center;">OS aanvragen</th></tr>';
  750. settings_prompt += '<tr><th style="text-align:center;">Incommings</th><th style="text-align:center;">Deffs nodig</th></tr>';
  751. for (var key in PDP_Settings.deffs_needed) {
  752. settings_prompt += '<tr class="OSA_row"><td style="text-align:center;">'+key+'</td><td style="text-align:center;"><input type="text" size="4" class="DN_nr" style="text-align:center;" onclick="this.select();" value="'+PDP_Settings.deffs_needed[key]+'"></td></tr>';
  753. }
  754. settings_prompt += '<tr><td colspan="2" style="padding:3px;text-align:center;"><a href="#" class="add_OS_row"><img src="https://nl34.tribalwars.nl/graphic/plus.png"></a></td></tr>';
  755. settings_prompt += '</table><br><input type="button" id="PDP_save" value="Opslaan"> | <input type="button" id="PDP_close" value="Annuleren">';
  756. settings_prompt += '<br><br><input type="button" id="PDP_standard" value="Standaard herstellen" title="Herstel de instellingen naar de standaard."> | <input type="button" id="PDPS_import" value="Importeren"> | <input type="button" id="PDPS_export" value="Exporteren"><br><br></span>';
  757. IT_FadeOutMessage(settings_prompt, 0, false, true, false, 400);
  758.  
  759. $('.add_OS_row').on('click', function() {
  760. $(this).closest('tr').before('<tr class="OSA_row"><td style="text-align:center;">'+$('.OSA_row').length+'</td><td style="text-align:center;"><input type="text" size="4" class="DN_nr" style="text-align:center;" onclick="this.select();" value=""></td></tr>');
  761. });
  762. $('#PDP_close').on('click', function(){$('.IT_message').remove();});
  763. $('#PDP_save').on('click', function(){
  764. DN_arr = [];
  765. $('.DN_nr').each(function() {
  766. DN_arr.push($(this).val());
  767. });
  768.  
  769. PDP_Settings = {
  770. fake_pop: $('#FEO_fake_pop').val(),
  771. clear_build_time: $('#FEO_clear_build_time').val(),
  772. deffs_needed: DN_arr
  773. };
  774. localStorage.setItem('PDP_Settings_'+world, JSON.stringify(PDP_Settings));
  775. $('.IT_message').remove();
  776. location.reload();
  777. });
  778. $('#PDP_standard').on('click', function(){
  779. var conf = confirm('Ben je zeker dat je de standaard instellingen terug wilt zetten ?');
  780. if (conf) {
  781. PDP_Settings = {
  782. fake_pop: 9000,
  783. clear_build_time: 14,
  784. deffs_needed : [0,2,3,4,5,6,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,11,11,11,11,11,12,12,12,12,12]
  785. };
  786. localStorage.setItem('PDP_Settings_'+world, JSON.stringify(PDP_Settings));
  787. $('.IT_message').remove();
  788. location.reload();
  789. }
  790. });
  791. $('#PDPS_import').on('click', function() {
  792. $('.PDPS_content').html('<h2>Instellingen importeren</h2><textarea cols="40" rows="20" id="PDPS_area" onclick="this.select();"></textarea><br><br><input type="button" id="do_PDPS_import" value="Importeren"> | <input type="button" id="go_back" value="Ga terug">');
  793.  
  794. $('#do_PDPS_import').on('click', function() {
  795. PDP_Settings = JSON.parse($('#PDPS_area').val());
  796. localStorage.setItem('PDP_Settings_'+world, JSON.stringify(PDP_Settings));
  797. $('.IT_message').remove();
  798. location.reload();
  799. });
  800.  
  801. $('#go_back').on('click', function() {
  802. $('.IT_message').remove();
  803. $('#PDP_Settings').click();
  804. });
  805. });
  806. $('#PDPS_export').on('click', function() {
  807. $('.PDPS_content').html('<h2>Instellingen exporteren</h2><textarea cols="40" rows="20" onclick="this.select();">'+JSON.stringify(JSON.parse(localStorage.getItem('PDP_Settings_'+world)))+'</textarea><br><br><input type="button" id="go_back" value="Ga terug">');
  808.  
  809. $('#go_back').on('click', function() {
  810. $('.IT_message').remove();
  811. $('#PDP_Settings').click();
  812. });
  813. });
  814. });
  815.  
  816. // IT //
  817. $incommings_tableTR.last().prev('tr').attr('IT-class','lastattack'); // marklastattack
  818. $incommings_tableTR.last().prev('tr:contains("Aanval")').attr('IT-classA','lastattackAanval'); // marklastattack Aanval
  819. $incommings_tableTR.last().prev('tr:contains("aanval")').attr('IT-classA','lastattackAanval'); // marklastattack aanval
  820.  
  821. $('.IT_button').on('click', function(){Pre_Tagging($(this).attr('id'));});
  822.  
  823. function Pre_Tagging(action) {
  824. if (action == 'IT_taggen' || action == 'IT_hmtaggen') {
  825. if($('input[name="filters[target_comment]"]').val() == 'Aanval' || $('input[name="filters[target_comment]"]').val() == 'aanval') {
  826. if (location.href.match(/screen=overview_villages/) && location.href.match(/mode=incomings/) && location.href.match(/subtype=attacks/) && location.href.match(/group=0/) && location.href.match(/page=-1/)) {
  827. if ($('#incomings_table').length > 0) {
  828. IT_FadeOutMessage("Je zit op de juiste pagina en de filter is juist ingesteld.<br>Het taggen kan beginnen !", 5000, false, false, false, 400);
  829. Tagging(action);
  830. } else {
  831. IT_FadeOutMessage("Er zijn geen incommings te vinden op deze pagina.", 2000, false, false, false, 400);
  832. }
  833. } else {
  834. IT_FadeOutMessage("Je zit niet op de juiste pagina.<br>Je wordt automatisch doorgestuurd.", 1500, false, false, false, 400);
  835. location.href = '/game.php?village='+game_data.village.id+'&subtype=attacks&mode=incomings&group=0&page=-1&screen=overview_villages'+h_mode;
  836. }
  837. } else {
  838. IT_FadeOutMessage("De filter is niet ingesteld op 'Aanval'.<br>De filter zal worden ingesteld op 'Aanval'.", 1500, false, false, false, 400);
  839. $('input[name="filters[target_comment]"]').val('Aanval');
  840. $('input[name="filters[target_name]"]').val('');
  841. $('input[name="filters[origin_name]"]').val('');
  842. $('input[name="filters[origin_player]"]').val('');
  843. $('#saveandreload').click();
  844. }
  845. } else if (action == 'IT_rename') {
  846. Tagging(action);
  847. }
  848. }
  849.  
  850. function Tagging(action) {
  851. if (action == 'IT_taggen') {
  852. var curTimestamp = new Date().getTime();
  853. var savedTimestamp = localStorage.getItem('IT_savedTimestamp_'+world+'_'+playerid);
  854. var calc = Math.ceil((curTimestamp - savedTimestamp)/60000);
  855. var mingeledengestuurd = prompt("Hoe veel minuten maximaal geleden zijn de aanvallen gestuurd ?", calc+2);
  856. if (mingeledengestuurd.match(/[A-z]/)) { alert('Opgave mag alleen nummers bevatten !'); }
  857.  
  858. for (var i=1;i<$incommings_tableTR.length-1;i++) {
  859. var newattack = $incommings_tableTR.eq(i).find('td').eq(0).find('a').eq(0).text();
  860. if (newattack.match(/Aanval/)) {
  861. var id = $incommings_tableTR.eq(i).find('.quickedit:first').attr('data-id');
  862. var player = $.trim($incommings_tableTR.eq(i).find('td').eq(3).text());
  863.  
  864. var targettd = $incommings_tableTR.eq(i).find('td').eq(1);
  865. var targeta = targettd.find('a').eq(0).text();
  866. var targetC = targeta.match(/\d{1,3}\|\d{1,3}/g).slice(-1)[0].toString();
  867.  
  868. var origintd = $incommings_tableTR.eq(i).find('td').eq(2);
  869. var origina = origintd.find('a').eq(0).text();
  870. var originC = origina.match(/\d{1,3}\|\d{1,3}/g).slice(-1)[0].toString();
  871.  
  872. var distance = getDis(targetC, originC);
  873.  
  874. var aankomstin = $incommings_tableTR.eq(i).find('td:contains(" om ")').next().text();
  875.  
  876. var possible = [];
  877. for (var j=0;j<units.length;j++) {
  878. var runtime = distance*unitspeed[j];
  879. var ondergrens = getMin(aankomstin);
  880. var bovengrens = parseInt(ondergrens)+parseInt(mingeledengestuurd);
  881. var edelmaxtime = parseInt(edelmax)*parseInt(unitspeed[unitspeed.length-1]);
  882. if (j != units.length-1) { if (runtime>ondergrens && runtime<bovengrens) {possible.push(units[j]);}}
  883. else { if (runtime>ondergrens && runtime<bovengrens && runtime<edelmaxtime) {possible.push(units[j]);}}
  884. }
  885.  
  886. if (possible.length == 1) {
  887. rename(id, 'other', player, possible[0], originC, distance);
  888. } else {
  889. rename(id, 'onlyTribeCheck', player);
  890. }
  891. }
  892.  
  893. if (i == $incommings_tableTR.length-2) {
  894. IT_FadeOutMessage("<b>Bevelen benoemen klaar !</b>", 5000, true, false, false, 400);
  895. }
  896. } // end for loop
  897. SaveTimestamp();
  898. } else if (action == 'IT_hmtaggen') {
  899. var ids = [];
  900. for (var i=1;i<$incommings_tableTR.length-1;i++) {
  901. var newattack = $incommings_tableTR.eq(i).find('td').eq(0).find('a').eq(0).text();
  902. if (newattack.match(/Aanval/)) {
  903. var attackid = $incommings_tableTR.eq(i).find('.quickedit:first').attr('data-id');
  904. ids.push(attackid);
  905. }
  906.  
  907. if (i == $incommings_tableTR.length-2) {
  908. IT_FadeOutMessage("<b>Bevelen benoemen klaar !</b>", 3000, false, false, false, 400);
  909. }
  910. }
  911. rename(ids, 'multiid');
  912. } else if (action == 'IT_rename') {
  913. var own_prompt = '<h2>Rename</h2><table class="vis" style="width:100%;border-collapse: separate;border-spacing: 2px;text-align:left;">';
  914. own_prompt += '<tr><td style="padding:3px;"><b>Vervang:</b></td><td style="padding:3px;"><input type="text" id="replace" value="Aanval" style="width:98%"></td></tr>';
  915. own_prompt += '<tr><td style="padding:3px;"><b>Voorvoegsel:</b></td><td style="padding:3px;"><input type="text" id="front" value="MARKEREN" style="width:98%"></td></tr>';
  916. own_prompt += '<tr><td style="padding:3px;"><b>Tag:</b></td><td style="padding:3px;"><input type="text" id="tag" value="Ram/Kata" style="width:98%"></td></tr>';
  917. own_prompt += '</table><br><input type="button" id="go" value="OK" style="float:left;"><input type="button" id="cancel" value="Annuleren" style="float:right;">';
  918. IT_FadeOutMessage(own_prompt, 5000, false, true, false, 400);
  919.  
  920. $('#cancel').on('click', function(){$('.IT_message').remove();});
  921. $('#go').on('click', function(){
  922. var replace = $('#replace').val(), front = $('#front').val(), tag= $('#tag').val();
  923. $('.IT_message').remove();
  924.  
  925. for (var i=1;i<$incommings_tableTR.length-1;i++) {
  926. var newattack = $incommings_tableTR.eq(i).find('td').eq(0).find('a').eq(0).text();
  927. if (newattack.match(replace)) {
  928. var id = $incommings_tableTR.eq(i).find('.quickedit:first').attr('data-id');
  929. var player = $.trim($incommings_tableTR.eq(i).find('td').eq(3).text());
  930.  
  931. var targettd = $incommings_tableTR.eq(i).find('td').eq(1);
  932. var targeta = targettd.find('a').eq(0).text();
  933. var targetC = targeta.match(/\d{1,3}\|\d{1,3}/g).slice(-1)[0].toString();
  934.  
  935. var origintd = $incommings_tableTR.eq(i).find('td').eq(2);
  936. var origina = origintd.find('a').eq(0).text();
  937. var originC = origina.match(/\d{1,3}\|\d{1,3}/g).slice(-1)[0].toString();
  938.  
  939. var distance = getDis(targetC, originC);
  940.  
  941. rename(id, 'rename', player, tag, originC, distance, front);
  942. }
  943.  
  944. if (i == $incommings_tableTR.length-2) {
  945. IT_FadeOutMessage("<b>Bevelen benoemen klaar !</b>", 3000, false, false, false, 400);
  946. }
  947. } // end for loop
  948. });
  949. }
  950. } // einde tagging
  951.  
  952.  
  953. // FEO //
  954. // Check database
  955. $('#FEO_database').on('click', function() {
  956. //info for ajax
  957. var total_build_time = PDP_Settings.clear_build_time*24*60*60*1000;
  958.  
  959. // ajax
  960. var url = 'https://swtools.programmingtuts.nl/PDP/GetInfo.php?info=allCoordsFull&game_data='+encodeURIComponent(JSON.stringify(game_data))+'&total_build_time='+total_build_time+'&servertime='+getServertimeTimestamp()+'&keycode='+keycode;
  961. //alert(url);
  962. $.ajax({
  963. url: url,
  964. dataType: 'jsonp',
  965. success: function (data) {
  966. if (typeof data.Coords != "undefined") {
  967. // get data
  968. var DB_Coords = data.Coords;
  969. var DB_Procent = data.Procent;
  970.  
  971. for (var i=1;i<$incommings_tableTR.length-1;i++) {
  972. // get id
  973. var id = $incommings_tableTR.eq(i).find('.quickedit:first').attr('data-id');
  974. // proces renaming
  975. var Herkomst_Td = $incommings_tableTR.eq(i).find('td').eq(2);
  976. var Herkomst_Coords = Herkomst_Td.text().match(/\d{1,3}\|\d{1,3}/g).slice(-1)[0];
  977. for (var j=0;j<DB_Coords.length;j++) {
  978. if (Herkomst_Coords == DB_Coords[j]) {
  979. // rename with info
  980. FEO_rename(id, '%', DB_Procent[j]);
  981. }
  982. }
  983.  
  984. if (i == $incommings_tableTR.length-2) {
  985. IT_FadeOutMessage("<b>Bevelen benoemen klaar !</b>", 3000, false, false, false, 400);
  986. }
  987. }
  988. }
  989. $footer_link.after('<span style="float:right;padding-right:20px;">FEO: '+data.msg+'</span>');
  990. },
  991. error: function (xhr, status, err) {
  992. $footer_link.after('<span style="float:right;padding-right:20px;">FEO: error</span>');
  993. }
  994. })
  995. });
  996.  
  997. // Check dubbel
  998. $('#FEO_dubbel').on('click', function() {
  999. // get attack villages
  1000. var att_villages = [];
  1001. for (var i=1;i<$incommings_tableTR.length-1;i++) {
  1002. var att_vil = $incommings_tableTR.eq(i).find('td').eq(2).text().match(/\d{1,3}\|\d{1,3}/g).slice(-1)[0].toString();
  1003. att_villages.push(att_vil);
  1004. }
  1005. // sort and count
  1006. var FEO = {coord: [],count: []}; var prev;
  1007. att_villages.sort();
  1008. for (var i = 0; i < att_villages.length; i++) {
  1009. if (att_villages[i] !== prev) {
  1010. FEO.coord.push(att_villages[i]);
  1011. FEO.count.push(1);
  1012. } else {
  1013. FEO.count[FEO.count.length-1]++;
  1014. }
  1015. prev = att_villages[i];
  1016. }
  1017.  
  1018. // only dubbel
  1019. var FEO2 = {coord: [],count: []};
  1020. for (var i=0;i<FEO.coord.length;i++) {
  1021. if(FEO.count[i] != 1) {
  1022. FEO2.coord.push(FEO.coord[i]);
  1023. FEO2.count.push(FEO.count[i]);
  1024. }
  1025. }
  1026.  
  1027. for (var i=1;i<$incommings_tableTR.length-1;i++) {
  1028. var id = $incommings_tableTR.eq(i).find('.quickedit:first').attr('data-id');
  1029. for (var j=0;j<FEO2.coord.length;j++) {
  1030. var Herkomst_Td = $incommings_tableTR.eq(i).find('td').eq(2);
  1031. var Herkomst_Coords = Herkomst_Td.text().match(/\d{1,3}\|\d{1,3}/g).slice(-1)[0];
  1032. if (Herkomst_Coords == FEO2.coord[j]) {
  1033. // rename with info
  1034. FEO_rename(id, 'x', FEO2.count[j]);
  1035. }
  1036. }
  1037.  
  1038. if (i == $incommings_tableTR.length-2) {
  1039. IT_FadeOutMessage("<b>Bevelen benoemen klaar !</b>", 3000, false, false, false, 400);
  1040. }
  1041. }
  1042. $footer_link.after('<span style="float:right;padding-right:20px;">FEO: dubbele controleren</span>');
  1043. });
  1044.  
  1045. // request
  1046. $('#FEO_request').on('click', function(){
  1047. // ajax
  1048. var url = 'https://swtools.programmingtuts.nl/PDP/GetInfo.php?info=Players&game_data='+encodeURIComponent(JSON.stringify(game_data))+'&keycode='+keycode;
  1049. //alert(url);
  1050. $.ajax({
  1051. url: url,
  1052. dataType: 'jsonp',
  1053. success: function (data) {
  1054. if (typeof data.Players != "undefined") {
  1055. // get data
  1056. var DB_Players = data.Players;
  1057. var DB_Num = data.Num;
  1058.  
  1059. // prepare data
  1060. DB_Players.sort();
  1061. for(var i=1;i<DB_Players.length;){
  1062. if(DB_Players[i-1] == DB_Players[i]){
  1063. DB_Players.splice(i, 1);
  1064. } else {
  1065. i++;
  1066. }
  1067. }
  1068.  
  1069. // output data
  1070. var request_prompt = '<h2>FEO: Ophalen Coords</h2>Totaal in database: '+DB_Num+'<br><br>';
  1071. request_prompt += 'Door hieronder een speler te kiezen en op ophalen te klikken kan je een lijst met coords ophalen van alle off dorpen van deze speler in de database.<br><br>';
  1072. request_prompt += '<b>Kies speler: </b><select id="FEO_requestCoords">';
  1073. for (var i=0;i<DB_Players.length;i++) request_prompt += '<option value="'+DB_Players[i]+'">'+DB_Players[i]+'</option>';
  1074. request_prompt += '</select>';
  1075. request_prompt += '<br><br><input type="button" id="FEO_get" value="Ophalen" style="float:left;"><input type="button" id="FEO_close" value="Annuleren" style="float:right;">';
  1076. IT_FadeOutMessage(request_prompt, 0, false, true, false, 400);
  1077.  
  1078. // click functions
  1079. $('#FEO_close').on('click', function(){$('.IT_message').remove();});
  1080. $('#FEO_get').on('click', function(){
  1081. // ajax
  1082. var name = $('#FEO_requestCoords').val();
  1083. var url = 'https://swtools.programmingtuts.nl/PDP/GetInfo.php?info=PlayerCoords&game_data='+encodeURIComponent(JSON.stringify(game_data))+'&name='+name+'&keycode='+keycode;
  1084. //alert(url);
  1085. $.ajax({
  1086. url: url,
  1087. dataType: 'jsonp',
  1088. success: function (data) {
  1089. // get data
  1090. var DB_Coords = data.Coords;
  1091. var DB_Num_Player = data.Num_Player;
  1092.  
  1093. // output data
  1094. var add = '<br><br><b>'+name+':</b> '+DB_Num_Player+' dorpen<br><textarea id="FEO_requestCoords_output" onclick="this.select();" rows="25">';
  1095. for (var i=0;i<DB_Coords.length;i++) if(i==DB_Coords.length-1) {add += DB_Coords[i]} else{ add += DB_Coords[i]+'\n'};
  1096. add += '</textarea>';
  1097. $('#FEO_requestCoords').after(add);
  1098.  
  1099. $footer_link.after('<span style="float:right;padding-right:20px;">FEO: '+data.msg+'</span>');
  1100. },
  1101. error: function (xhr, status, err) {
  1102. $footer_link.after('<span style="float:right;padding-right:20px;">FEO: error</span>');
  1103. }
  1104. })
  1105. });
  1106. }
  1107. $footer_link.after('<span style="float:right;padding-right:20px;">FEO: '+data.msg+'</span>');
  1108. },
  1109. error: function (xhr, status, err) {
  1110. $footer_link.after('<span style="float:right;padding-right:20px;">FEO: error</span>');
  1111. }
  1112. })
  1113. });
  1114.  
  1115. var WS_UP = WS.unit_pop; // fix for getting access to WS - ontherwise cannot convert error
  1116. $('#PDP_select_all').on('click', function(){$('.selectAll').click();});
  1117. $('.PDP_Export').on('click', function() {
  1118. $('.IT_message').remove();
  1119. IT_FadeOutMessage('<span id="PDP_content"><h3>Export instellingen</h3><img src="https://swtools.programmingtuts.nl/PDP/images/load-icon.GIF" height="50"></span>', 0, false, true, true, 700);
  1120.  
  1121. var info = {coords: [], ids: [], atts: [], timestamps: []};
  1122. $('#incomings_table').find('tr').not(':contains("Bevel")').not(':contains("selecteren")').each(function() {
  1123. if ($(this).find('input[type="checkbox"]').prop('checked') && $(this).find('img[src*="attack.png"]').length != 0) {
  1124. var $a = $(this).find('a[href$="&screen=overview"]');
  1125. var target = $a.text().match(/\d{1,3}\|\d{1,3}/g).slice(-1)[0]; // returns array, no idea why
  1126. var targetID = $a.attr('href').match(/\d+/);
  1127. var arrival = $(this).find('td:contains(" uur")').text(); // makeTimestamp(
  1128.  
  1129. var index = info.coords.indexOf(target);
  1130. if (index == -1) {
  1131. info.coords.push(target);
  1132. info.ids.push(targetID);
  1133. info.atts.push(1);
  1134. info.timestamps.push(arrival);
  1135. } else {
  1136. info.atts[index]++;
  1137. }
  1138. }
  1139. });
  1140.  
  1141.  
  1142. var control = '<span id="export_control_span"><h3>Export instellingen</h3><table id="export_control" class="vis" style="margin:auto;"><thead>';
  1143. control += '<tr><th></th><th colspan="3">Dorpsinfo</th><th colspan="2">Aanvallen</th><th colspan="2">Verdediging</th><th></th><th></th></tr>';
  1144. control += '<tr><th>Nr.</th><th>Dorp <img id="openVillages" src="/graphic/arrow_down_padd.png" style="cursor:pointer;" title="Open alle dorpslinks"></th><th>Muur</th><th><img src="http://dsnl.innogamescdn.com/8.28/22567/graphic/buildings/church.png" alt="Gelovig" title="Gelovig"></th><th>Geselecteerd</th><th>totaal</th><th>in dorp</th><th>binnenkomend</th><th>Aanvragen</th><th></th></thead><tbody>';
  1145. var totalSelectedAtts = 0, totalAtts = 0, totalInVillage = 0, totalIncDeffs =0, totalDeffs = 0;
  1146. if (info.coords.length == 0) {
  1147. control += '<tr class="PDP_row" style="height:40px;"><td colspan="10">Geen geselecteerde aanvallen gevonden</td></tr>';
  1148. } else {
  1149. for (var key in info.coords) {
  1150. getInfoFromVillage(info.ids[key], WS_UP, function(VillageInfo) {
  1151. // create rows
  1152. var need = (info.atts[key] < PDP_Settings.deffs_needed.length) ? ((Math.ceil(PDP_Settings.deffs_needed[info.atts[key]]-VillageInfo[2]) < 0) ? 0 : Math.ceil(PDP_Settings.deffs_needed[info.atts[key]]-VillageInfo[2])) : 'x';
  1153. var drag = '<div style="width: 11px; height:11px; background-image: url(http://dsnl.innogamescdn.com/8.24/21113/graphic/sorthandle.png?8838f); cursor:pointer" class="PDP_handle" title="Hier kun je de ordening van de lijst wijzigen door ze aan te klikken met de muis en dan te slepen."></div>';
  1154. control += '<tr class="PDP_row"><td>'+(parseInt(key)+1)+'</td><td><a href="/game.php?village='+info.ids[key]+'&screen=overview&PDPnr='+(parseInt(key)+1)+'" target="_blank" class="PDP_overviewLink" data-attid="'+info.timestamps[key]+'">'+info.coords[key]+'</a></td><td>'+VillageInfo[1]+'</td><td>';
  1155. if (VillageInfo[4]) {
  1156. if (VillageInfo[5]) {
  1157. control += '<span style="color:green;">&#10004;</span>';
  1158. } else {
  1159. control += '<span style="color:red;">&#10008;</span>';
  1160. }
  1161. } else {
  1162. control += 'nvt';
  1163. }
  1164. control += '</td><td>'+info.atts[key]+'</td><td>'+VillageInfo[0]+'</td><td>'+VillageInfo[2]+'</td><td>'+VillageInfo[3]+'</td><td><input type="text" class="deffs_input" size="4" value="'+need+'" onclick="this.select();" style="margin-left:5px;margin-right:5px;text-align:center;"></td><td>'+drag+'</td></tr>';
  1165.  
  1166. // counters
  1167. totalSelectedAtts = totalSelectedAtts + info.atts[key];
  1168. totalAtts = totalAtts + VillageInfo[0];
  1169. totalInVillage = totalInVillage + VillageInfo[2];
  1170. totalIncDeffs = totalIncDeffs + VillageInfo[3];
  1171. if (need != 'x') {totalDeffs = totalDeffs + need}
  1172. });
  1173. }
  1174. }
  1175. control += '</tbody><tr><th colspan="4">'+info.coords.length+' dorpen</th><th>'+totalSelectedAtts+'</th><th>'+totalAtts+'</th><th>'+Math.round(totalInVillage*100)/100+'</th><th>'+totalIncDeffs+'</th><th id="totalDeffs">'+totalDeffs+'</th><th></th></tr>';
  1176. control += '</table><br><input type="button" id="PDP_export2" class="btn" value="Exporteren"></span>';
  1177. $('#PDP_content').html(control);
  1178. $('#export_control').find('th,td').attr('style', 'text-align:center;padding-left:5px;padding-right:5px;'); // CSS
  1179.  
  1180. // dragging
  1181. // Return a helper with preserved width of cells
  1182. var fixHelper = function(e, ui) {
  1183. ui.children().each(function() {
  1184. $(this).width($(this).width());
  1185. });
  1186. return ui;
  1187. };
  1188.  
  1189. $('#export_control tbody').sortable({
  1190. handle: '.PDP_handle',
  1191. axis: 'y',
  1192. helper: fixHelper
  1193. })
  1194.  
  1195. $('#openVillages').on('click', function() {
  1196. $('.PDP_overviewLink').each(function() {
  1197. window.open($(this).attr('href'), '_blank');
  1198. });
  1199. });
  1200.  
  1201. $('.deffs_input').on('keyup', function() {
  1202. var counter = 0;
  1203. $('.deffs_input').each(function() {
  1204. counter = counter + parseInt($(this).val());
  1205. });
  1206.  
  1207. $('#totalDeffs').text(counter);
  1208. });
  1209.  
  1210. $('#PDP_export2').on('click', function() {
  1211. var data = {coords: [], deffs: [], timestamps: []};
  1212. var totalDeffs2 = 0;
  1213. $('.PDP_row').each(function() {
  1214. data.coords.push($(this).find('.PDP_overviewLink').text());
  1215. data.deffs.push($(this).find('.deffs_input').val());
  1216. data.timestamps.push($(this).find('.PDP_overviewLink').attr('data-attid'));
  1217. totalDeffs2 = totalDeffs2 + parseInt($(this).find('.deffs_input').val());
  1218. });
  1219.  
  1220. var total_table = '<table id="export" class="vis" style="margin:auto;"><th colspan="2">Totalen</th><tr><td>Aantal dorpen:</td><td>'+info.coords.length+'</td></tr>';
  1221. total_table += '<tr><td>Geselecteerde aanvallen:</td><td>'+totalSelectedAtts+'</td></tr><tr><td>Alle aanvallen:</td><td>'+totalAtts+'</td></tr>';
  1222. total_table += '<tr><td>Def dorpen in het dorp:</td><td>'+Math.round(totalInVillage*100)/100+'</td></tr><tr><td>Binnenkomden def dorpen</td><td>'+totalIncDeffs+'</td></tr><tr><td>Benodigd aantal def dorpen:</td><td>'+totalDeffs2+'</td></tr></table>';
  1223.  
  1224. var EOS = '', E1C = '', count = 1;
  1225. for (var key in data.coords) {
  1226. if (data.deffs[key] != 0) {
  1227. EOS += '#'+count+' '+data.coords[key]+' [b]-> '+data.deffs[key]+' def dorp(en) nodig[/b] -> '+makeTime(false, data.timestamps[key])+'\n';
  1228. E1C += data.coords[key]+' '+data.deffs[key]+' '+makeTime(true, data.timestamps[key])+'\n';
  1229. count++;
  1230. }
  1231. }
  1232.  
  1233. $('#PDP_content').find('span#export_control_span').attr('style', 'display: none;');
  1234. $('#PDP_content').append('<span id="export_span"><h3>Export info</h3>'+total_table+'<br><input type="button" class="go_back btn" value="Terug"><br><br><h4>Export OS aanvraag</h4><textarea cols="70" rows="15" onclick="this.select();">'+EOS+'</textarea><br><br><h4>Export voor <a href="http://tuam.nl/scripts/1Command.php">1Command</a></h4><textarea cols="70" rows="15" onclick="this.select();">'+E1C+'</textarea></span>');
  1235. $('#export').find('th').attr('style', 'text-align:center;padding-left:5px;padding-right:5px;'); // CSS
  1236. $('#export').find('td').attr('style', 'text-align:left;padding-left:5px;padding-right:5px;'); // CSS
  1237.  
  1238. $('.go_back').on('click', function() {
  1239. $('#PDP_content').find('span#export_span').remove();
  1240. $('#PDP_content').find('span#export_control_span').removeAttr('style');
  1241. });
  1242. });
  1243. });
  1244. }
  1245.  
  1246. // Info command page //
  1247. if (game_data.screen == 'info_command' && !location.href.match(/type=own/)) {
  1248. //styling
  1249. $('#content_value table:first').attr('style', 'width:600px;');
  1250.  
  1251. // nodige info
  1252. var player = $('td:contains("Speler:")').next('td').find('a').eq(0).text();
  1253. var originC = $('td:contains("Dorp:")').next('td').find('span').eq(0).find('a').eq(0).text().match(/\d{1,3}\|\d{1,3}/g).slice(-1)[0].toString();
  1254. var targetC = $('td:contains("Dorp:"):last').next('td').find('span').eq(0).find('a').eq(0).text().match(/\d{1,3}\|\d{1,3}/g).slice(-1)[0].toString();
  1255. var distance = getDis(targetC, originC);
  1256.  
  1257. if (player != game_data.player.name) {
  1258. // afstand tonen
  1259. $('td:contains("Dorp:"):last').parent().after('<tr><td colspan="2">Loopafstand:</td><td>'+(Math.round(distance*100)/100)+' velden</td></tr>');
  1260.  
  1261. var aankomstin = $('td:contains("Aankomst in:")').next('td').text();
  1262. var possible = {tag: [], runtime:[]};
  1263. for (var i=0;i<units.length;i++) {
  1264. var runtime = distance * unitspeed[i];
  1265. var ondergrens = getMin(aankomstin);
  1266. var edelmaxtime = parseInt(edelmax)*parseInt(unitspeed[6]);
  1267. if (i != 6) { if (runtime > ondergrens) {possible.tag.push(units[i]);possible.runtime.push(runtime);}}
  1268. else { if (runtime > ondergrens && runtime<edelmaxtime) {possible.tag.push(units[i]);possible.runtime.push(runtime);}}
  1269. }
  1270.  
  1271. var tagtable = '<table id="IT_tagtable" class="vis" style="margin-top: 10px;width:600px;"><tr><th>Eenheid</th><th>Looptijd</th><th>Verschil</th><th>Benoemen</th></tr>';
  1272. for (var i=0;i<possible.tag.length;i++) {
  1273. var tag = 'MARKEREN '+possible.tag[i]+' ('+originC+') '+player+' F'+Math.round(distance);
  1274. var verschil = (possible.runtime[i])-(getMin(aankomstin));
  1275. tagtable += '<tr>';
  1276. tagtable += '<td>'+possible.tag[i]+'</td>';
  1277. tagtable += '<td>'+formatDuration(possible.runtime[i])+'</td>';
  1278. tagtable += '<td>'+formatDuration(verschil)+'</td>';
  1279. tagtable += '<td><input type="text" value="'+tag+'" style="width: 300px;"/><input type="button" class="okbutton" title="'+possible.tag[i]+'" value="OK"/></td></tr>';
  1280. }
  1281. tagtable += '</table>';
  1282. $('table.vis:contains("Herkomst")').after(tagtable);
  1283.  
  1284. $('input.okbutton').on('click', function(){
  1285. var id = location.href.match(/id=\d+/).toString().match(/\d+/);
  1286. var val = $(this).prev('input').val();
  1287. sendAjax(id, val);
  1288. $(':focus').blur(); // else opera shortcuts wont work
  1289. });
  1290.  
  1291. // next untagged incomming
  1292. var $rename_icon = $('.rename-icon');
  1293. var nextid = $.trim($('span.quickedit:first').find('span.quickedit-label').text()).split('IT_')[1];
  1294. if (nextid) {
  1295. if (nextid == '0') {
  1296. var nextattack_url = 'https://'+game_data.world+'.tribalwars.nl/game.php?village='+game_data.village.id+'&mode=incomings&subtype=attacks&group=0&page=-1&screen=overview_villages'+h_mode;
  1297. $rename_icon.after('<span style="float:right;"><a id="goto"href="'+nextattack_url+'">Naar overzicht</a></span>');
  1298. } else {
  1299. var nextattack_url = 'https://'+game_data.world+'.tribalwars.nl/game.php?village='+game_data.village.id+'&id='+nextid+'&type=other&screen=info_command'+h_mode;
  1300. $rename_icon.after('<span style="float:right;"><a id="goto" href="'+nextattack_url+'">Volgend bevel</a></span>');
  1301. }
  1302. $('input.okbutton').on('click', function(){location.href = nextattack_url;});
  1303. }
  1304. }
  1305. }
  1306.  
  1307. // Map page //
  1308. if (game_data.screen == 'map') {
  1309. $('a:contains("Wereldkaart tonen")').after('<br><a href="#" id="FEO_ShowOnMap">&raquo; FEO off dorpen tonen</a>');
  1310. var FEO_click = 0;
  1311. $('#FEO_ShowOnMap').on('click', function(){
  1312. if (FEO_click%2 == 0){
  1313. FEO_ShowOnMap();
  1314. FEO_click++;
  1315. } else {
  1316. FEO_DontShowOnMap();
  1317. FEO_click++;
  1318. }
  1319. });
  1320.  
  1321. function FEO_DontShowOnMap() {
  1322. var FEO_Map = TWMap;
  1323. FEO_Map.mapHandler.spawnSector = FEO_Map.mapHandler.FEOspawnSector;
  1324. spawnSectorReplacer = FEO_Map.mapHandler.spawnSector;
  1325. FEO_Map.reload();
  1326. }
  1327.  
  1328. function FEO_ShowOnMap() {
  1329. // Getting off coords
  1330. var total_build_time = PDP_Settings.clear_build_time*24*60*60*1000;
  1331. var url = 'https://swtools.programmingtuts.nl/PDP/GetInfo.php?info=allCoordsFull&game_data='+encodeURIComponent(JSON.stringify(game_data))+'&total_build_time='+total_build_time+'&servertime='+getServertimeTimestamp()+'&keycode='+keycode;
  1332. $.ajax({
  1333. url: url,
  1334. dataType: 'jsonp',
  1335. success: function (data) {
  1336. if (typeof data.Coords != "undefined") {
  1337. var DB_Coords = data.Coords;
  1338. var DB_Procent = data.Procent;
  1339. if (DB_Coords.length > 0) {
  1340. var FEO_Map = TWMap;
  1341. function spawnSectorReplacer(data, sector) {
  1342. FEO_Map.mapHandler.FEOspawnSector(data, sector);
  1343. var beginX = sector.x - data.x;
  1344. var endX = beginX + FEO_Map.mapSubSectorSize;
  1345. var beginY = sector.y - data.y;
  1346. var endY = beginY + FEO_Map.mapSubSectorSize;
  1347. for (var x in data.tiles) {
  1348. var x = parseInt(x, 10);
  1349. if (x < beginX || x >= endX) {
  1350. continue;
  1351. }
  1352. for (var y in data.tiles[x]) {
  1353. var y = parseInt(y, 10);
  1354. if (y < beginY || y >= endY) {
  1355. continue;
  1356. }
  1357. var xCoord = data.x + x;
  1358. var yCoord = data.y + y;
  1359. var v = FEO_Map.villages[(xCoord) * 1000 + yCoord];
  1360. if (v) {
  1361. for(var i=0;i<DB_Coords.length;i++) {
  1362. if (DB_Coords[i] == (xCoord + "|" + yCoord)) {
  1363. var img = document.createElement('div');
  1364. img.style.position = 'absolute';
  1365. img.style.zIndex = '50';
  1366. img.style.width = (FEO_Map.map.scale[0]-1).toString() + 'px';
  1367. img.style.height = (FEO_Map.map.scale[1]-1).toString() + 'px';
  1368. img.style.backgroundPosition = 'center bottom';
  1369. img.id = 'FEO_img_' + ((xCoord)*1000+yCoord).toString();
  1370. img.innerHTML = '<span style="color:white;background-color:black;position:absolute;bottom:0;left:12px;font-size:10px;">'+DB_Procent[i]+'%</span>';
  1371. sector.appendElement(img, x - beginX, y - beginY);
  1372. }
  1373. }
  1374. }
  1375. }
  1376. }
  1377. }
  1378. FEO_Map.mapHandler.FEOspawnSector = FEO_Map.mapHandler.spawnSector;
  1379. FEO_Map.mapHandler.spawnSector = spawnSectorReplacer;
  1380. FEO_Map.reload();
  1381. }
  1382. }
  1383. $footer_link.after('<span style="float:right;padding-right:20px;">FEO: '+data.msg+'</span>');
  1384. },
  1385. error: function (xhr, status, err) {
  1386. $footer_link.after('<span style="float:right;padding-right:20px;">FEO: error</span>');
  1387. }
  1388. })
  1389. }
  1390. }
  1391.  
  1392. // Villageinfo page //
  1393. if (game_data.screen == 'info_village') {
  1394. //info for ajax
  1395. var total_build_time = PDP_Settings.clear_build_time*24*60*60*1000;
  1396. var Coords = $('table.vis:contains("rdinaten")').find('td:contains("rdinaten")').next('td').text();
  1397.  
  1398. // ajax
  1399. var url = 'https://swtools.programmingtuts.nl/PDP/GetInfo.php?info=oneCoord&game_data='+encodeURIComponent(JSON.stringify(game_data))+'&total_build_time='+total_build_time+'&servertime='+getServertimeTimestamp()+'&Coords='+Coords+'&keycode='+keycode;
  1400. $.ajax({
  1401. url: url,
  1402. dataType: 'jsonp',
  1403. success: function (data) {
  1404. if (typeof data.DB_Troops != "undefined") {
  1405. // Troops table
  1406. var Troops = '<table>';
  1407. var Troops_Lost = '<table>';
  1408. var Troops_Left = '<table>';
  1409. var DB_Troops = data.DB_Troops.split(',');
  1410. var DB_Troops_Left = data.DB_Troops_Left.split(',');
  1411. for (var i=0;i<DB_Troops.length;i++) {
  1412. if (DB_Troops[i] != 0) {
  1413. Troops += ' <td style="width:34px;text-align:center;">'+DB_Troops[i]+'</td>';
  1414. } else {
  1415. Troops += ' <td style="width:34px;text-align:center;color:#B19661;">'+DB_Troops[i]+'</td>';
  1416. }
  1417.  
  1418. if (parseInt(DB_Troops[i]-DB_Troops_Left[i]) != 0) {
  1419. Troops_Lost += ' <td style="width:34px;text-align:center;">'+parseInt(DB_Troops[i]-DB_Troops_Left[i])+'</td>';
  1420. } else {
  1421. Troops_Lost += ' <td style="width:34px;text-align:center;color:#B19661;">'+parseInt(DB_Troops[i]-DB_Troops_Left[i])+'</td>';
  1422. }
  1423.  
  1424. if (DB_Troops_Left[i] != 0) {
  1425. Troops_Left += ' <td style="width:34px;text-align:center;">'+DB_Troops_Left[i]+'</td>';
  1426. } else {
  1427. Troops_Left += ' <td style="width:34px;text-align:center;color:#B19661;">'+DB_Troops_Left[i]+'</td>';
  1428. }
  1429. }
  1430. Troops += '</table>';
  1431. Troops_Lost += '</table>';
  1432. Troops_Left += '</table>';
  1433.  
  1434. var curTime = getServertimeTimestamp();
  1435. var Time_dif = parseInt((curTime-data.DB_Time)/1000/60/60/24); // in dagen
  1436.  
  1437. // building table
  1438. var imgs = 'spear sword axe archer spy light marcher heavy ram catapult knight snob'.split(' ');
  1439. var table = '<table id="FEO_table" class="vis" style="margin-top:15px;"><tr><th colspan="2">Find Enemy Offence [FEO]</th></tr>';
  1440. table += '<tr><td>Laatste aanval:</td><td>'+formatTimeFromTimestamp(data.DB_Time)+' ('+Time_dif+' dagen geleden)</td></tr>';
  1441. table += '<tr><td></td><td><table>';
  1442. for (var a in imgs) table += '<td style="width:34px;"><img id="'+imgs[a]+'" src="http://cdn.tribalwars.net/graphic/unit/unit_'+imgs[a]+'.png" style="display: block;margin-left: auto;margin-right: auto;"></td>';
  1443. table += '</table></td></tr>';
  1444. table += '<tr><td>Troepen aantal:</td><td>'+Troops+'</td></tr>';
  1445. table += '<tr><td>Troepen verloren:</td><td>'+Troops_Lost+'</td></tr>';
  1446. table += '<tr><td>Troepen over:</td><td>'+Troops_Left+'</td></tr>';
  1447. table += '<tr><td>Procent vol:</td><td>'+data.Procent_Start+'% + '+data.Procent_Add+'% = <b>'+data.Procent_End+'%</b></td></tr>';
  1448. table += '<tr><td>Delete info:</td><td><a href="#" id="FEO_delete" title="Verwijder aanvalsdorp uit database"><span style="color:red;font-size:16px;">&#10007;</span> info verwijderen</a></td></tr>';
  1449. $('table.vis:contains("Notities:")').after(table);
  1450.  
  1451. $('#FEO_delete').on('click', function() {
  1452. var Coords = $('table.vis:contains("rdinaten") td:contains("rdinaten")').next('td').text();
  1453. DeleteInfo(Coords);
  1454. });
  1455. }
  1456. $footer_link.after('<span style="float:right;padding-right:20px;">FEO: '+data.msg+'</span>');
  1457. },
  1458. error: function (xhr, status, err) {
  1459. $footer_link.after('<span style="float:right;padding-right:20px;">FEO: error</span>');
  1460. }
  1461. })
  1462. }
  1463.  
  1464. // Report page //
  1465. if (game_data.screen == 'report') {
  1466. if (!location.href.match(/view=/) && game_data.mode == 'defense') {
  1467. // load next page
  1468. $('.paged-nav-item').last().after('<a id="LoadNextPage" href="#" FEO_remove="remove">[FEO: Volgende pagina laden]</a>');
  1469. var x = $('input[name="page_size"]').val();
  1470. var count = x;
  1471. if (location.href.match(/from=/)) {
  1472. var current = location.href.match(/from=\d+/).toString().match(/\d+/);
  1473. } else {
  1474. var current = 0;
  1475. }
  1476.  
  1477. $('#LoadNextPage').on('click', function(){
  1478. var next = parseInt(current) + parseInt(x);
  1479. var nextPage = game_data.link_base_pure + 'report&mode=defense&from=' + next;
  1480. $.ajax({
  1481. url: nextPage,
  1482. async: false,
  1483. success: function (result) {
  1484. // add rows
  1485. var rows = $(result).find('#report_list').find('tr').not(':contains("Onderwerp")').not(':contains("alles selecteren")');
  1486. $('#report_list').find('tr').not(':contains("alles selecteren")').last().after(rows);
  1487.  
  1488. // current
  1489. current = parseInt(current) + parseInt(x);
  1490.  
  1491. // change to strong
  1492. $('a.paged-nav-item[href*="&from='+ next + '&"]').replaceWith('<strong>'+$('a.paged-nav-item[href*="from='+ next + '"]').html()+'</strong>');
  1493.  
  1494. // show amount
  1495. count = parseInt(count) + parseInt(x);
  1496. $('.amountReports').html(count);
  1497.  
  1498. // reload FEO
  1499. addFEOtoRow();
  1500. },
  1501. error: function() {
  1502. alert('De volgende pagina kon niet worden geladen');
  1503. }
  1504. })
  1505. });
  1506.  
  1507. // add link
  1508. $('a:contains("» Filter")').after('<span FEO_remove="remove" style="float:right;"><b>Pagina bevat <span class="amountReports">'+ count +'</span> berichten |</b> <a href="#" class="read_reports">&laquo; FEO berichten inlezen &raquo;</a></span>');
  1509.  
  1510. // expand table
  1511. // add th
  1512. $('#report_list').find('tr').not(':contains("Filter")').find('th:contains("Ontvangen")').after('<th FEO_remove="remove" style="font-size:10px;">FEO</th>');
  1513.  
  1514. addFEOtoRow();
  1515.  
  1516. $('.read_reports').on('click', function() {
  1517. IT_FadeOutMessage("<b>Berichten inlezen gestart !</b><br>Dit kan even duren...", 5000, true, false, false, 400);
  1518. $('#report_list').find('tr[FEO_class="not_done"]').each(function(index) {
  1519. $this = $(this);
  1520. var raps_id = $this.find('span.quickedit').eq(0).attr('data-id');
  1521.  
  1522. $.ajax({
  1523. url: game_data.link_base_pure + 'report&mode=defense&view=' + raps_id,
  1524. type: 'html',
  1525. async: false,
  1526. success: function(html){
  1527. // generating result
  1528. var player_td = $(html).find('#attack_info_att').find('tr').eq(0).find('th').eq(1);
  1529. var Attacker = $.trim(player_td.find('a').eq(0).text());
  1530. var Tribe = player_td.find('a').attr('title');
  1531. if ($(html).find('#content_value').text().match(/heeft gewonnen/) && Attacker != game_data.player.name && Tribe != tribeinfo.tribename) {
  1532. var unit_bev = [1,1,1,1,2,4,5,6,5,8,10,100];
  1533. var att_pop_count = 0;
  1534. var att_troops = $(html).find('#attack_info_att_units tr:eq(1)').find('td.unit-item');
  1535. for (var i=0;i<att_troops.length;i++) {
  1536. att_pop_count = att_pop_count+(parseInt(att_troops.eq(i).text())*unit_bev[i]);
  1537. }
  1538.  
  1539. if (att_pop_count > PDP_Settings.fake_pop) {
  1540. SendInfo(true, html, $this);
  1541. } else {
  1542. changeDone($this);
  1543. }
  1544. } else {
  1545. changeDone($this);
  1546. }
  1547. }
  1548. });
  1549. });
  1550. });
  1551.  
  1552. } else if (location.href.match(/view=/)) {
  1553. // create result
  1554. $('h2:contains("Berichten")').append('<span id="FEO_result" style="padding-left:60px;font-size:7pt;font-weight:normal;">FEO: <span id="FEO_past_result"></span> [<a href="#" id="FEO_delete"><span title="Verwijder aanvalsdorp uit database" style="color:red;font-size:12px;">&#10007;</span></a>]</span>');
  1555. var $FEO_past_result = $('#FEO_past_result');
  1556.  
  1557. // generating result
  1558. var player_td = $('#attack_info_att').find('tr').eq(0).find('th').eq(1);
  1559. var Attacker = $.trim(player_td.find('a').eq(0).text());
  1560. var Tribe = player_td.find('a').attr('title');
  1561. if ($('#content_value').text().match(/heeft gewonnen/) && Attacker != game_data.player.name && Tribe != tribeinfo.tribename) {
  1562. var unit_bev = [1,1,1,1,2,4,5,6,5,8,10,100];
  1563. var att_pop_count = 0;
  1564. var att_troops = $('#attack_info_att_units tr:eq(1)').find('td.unit-item');
  1565. for (var i=0;i<att_troops.length;i++) {
  1566. att_pop_count = att_pop_count+(parseInt(att_troops.eq(i).text())*unit_bev[i]);
  1567. }
  1568.  
  1569. if (att_pop_count > PDP_Settings.fake_pop) {
  1570. SendInfo(false);
  1571. } else {
  1572. $FEO_past_result.append('geen clear, niet opgeslagen');
  1573. }
  1574. } else {
  1575. $FEO_past_result.append('eigen/stam/geen aanval');
  1576. }
  1577.  
  1578. $('#FEO_delete').on('click', function() {
  1579. var Coords = $('.village_anchor').eq(0).find('a').eq(0).text().match(/\d{1,3}\|\d{1,3}/g).slice(-1)[0];
  1580. DeleteInfo(Coords);
  1581. });
  1582. }
  1583. }
  1584.  
  1585. // Village Overview page //
  1586. if (game_data.screen == 'overview') {
  1587. if (location.href.match('PDPnr=')) {
  1588. var nr = location.href.split('PDPnr=')[1];
  1589. document.title = 'PDP: ' + nr;
  1590. }
  1591.  
  1592. }
  1593. }
  1594.  
  1595. // Inject script in the page
  1596. (function () {
  1597. var script = document.createElement("script");
  1598. script.textContent = "(" + PDPScriptCode + ")()";
  1599. document.body.appendChild(script);
  1600. })();// ==UserScript==
  1601. // @name New Userscript
  1602. // @namespace http://tampermonkey.net/
  1603. // @version 0.1
  1604. // @description try to take over the world!
  1605. // @author You
  1606. // @match http://pastebin.com/fVAdwMTs
  1607. // @grant none
  1608. // ==/UserScript==
  1609.  
  1610. (function() {
  1611. 'use strict';
  1612.  
  1613. // Your code here...
  1614. })();
RAW Paste Data