· 4 years ago · Mar 04, 2021, 11:32 PM
1var backgroundColor = "#32313f";
2var borderColor = "#3e6147";
3var headerColor = "#202825";
4var titleColor = "#ffffdf";
5var dropboxToken='voeQxDKEfdAAAA';
6dropboxToken+="AAAAAAAWmeVbsqR6"
7dropboxToken+="fFyKdfA2gXF05UhE"
8dropboxToken+="t-ztkJqkFZY6PkMTzk"
9
10
11var speedWorld=getSpeedConstant().worldSpeed;
12var speedTroupes=getSpeedConstant().unitSpeed;
13
14
15
16var file_reports='https://dl.dropboxusercontent.com/s/qdydvdssbrfns92/test.txt?dl=0';
17var file_incomigs='https://dl.dropboxusercontent.com/s/0acfdzwwhhrcup1/test2.txt?dl=0';
18var file_users='https://dl.dropboxusercontent.com/s/y7idzygkmwm68k8/test3.txt?dl=0';
19var filename_reports="test.txt";
20var filename_incomings="test2.txt";
21var filename_users="test3.txt";
22
23// var speedWorld=3;
24// var speedTroupes=0.67;
25
26var nobleSpeed=2100*1000/(speedWorld*speedTroupes)//ms
27var ramSpeed=1800*1000/(speedWorld*speedTroupes)//ms
28var swordSpeed=1320*1000/(speedWorld*speedTroupes)//ms
29var axeSpeed=1080*1000/(speedWorld*speedTroupes)//ms
30
31//formula ((base time/100)/speedWorld) * stable time factor //https://forum.tribalwars.net/index.php?threads/next-lvl-of-barracks-unit-production-speed.54638/
32var axeTime=Math.round( ((1320/100.0)/speedWorld) * 15.58823529 ) *1000//milisec
33var lhTime=Math.round( ((1800/100.0)/speedWorld) * 20.88235294 ) *1000//milisec
34var ramTime=Math.round( ((4800/100.0)/speedWorld) * 27.84313725 ) *1000//milisec
35
36
37
38
39//verify acces users
40let response=httpGet(file_users);
41var tribemates=response.split("\n").map(e=>{return e.trim()})
42if(!tribemates.includes(game_data.player.name)){
43 UI.ErrorMessage("try later","slow")
44 throw new Error("you do not have acces");
45 // console.log("you do not have acces" )
46}
47if(game_data.locale!="en_DK" && game_data.world!="en118" )
48 throw new Error("it doesn't work");
49
50
51
52var engWord=[
53 "supports",
54 "today",
55 "tomorrow",
56 "on",
57 "attack"
58]
59var roWord=[
60 "sprijină",
61 "astăzi",
62 "mâine",
63 "data",
64 "atac"
65]
66var wordsTranslate=engWord
67
68var troopsPop = {
69 spear : 1,
70 sword : 1,
71 axe : 1,
72 archer : 1,
73 spy : 2,
74 light : 4,
75 marcher : 5,
76 heavy : 6,
77 ram : 5,
78 catapult : 8,
79 knight : 10,
80 snob : 100
81};
82
83 html = `
84 <div id="div_container" class="ui-widget-content" style="width:600px;background-color:${backgroundColor};cursor:move;z-index:50;">
85 <div class="close-btn" id="btn_close" onclick="closeWindow()" style="position:absolute;top:10px;right: 10px;"><b><a href=#><font color="${titleColor}">X</font></b></a></div>
86 <h2><center style="margin:10px"><u><font color="${titleColor}">Upload data</font></u></center></h2>
87 <table id="table_upload" class="" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor}">
88 <tr>
89 <td style="text-align:center; width:auto; background-color:${headerColor}">
90 <h2><center style="margin:10px"><u><font color="${titleColor}">reports</font></u></center></h2>
91 </td>
92 <td style="text-align:center; width:auto; background-color:${headerColor}">
93 <center style="margin:10px"><u><input class="btn" type="button" id="upload_reports" onclick="uploadReportsManual()" value="Upload manual"></center>
94 <center style="margin:10px"><u><input class="btn" type="button" id="upload_reports" onclick="uploadReports()" value="Upload auto"></center>
95
96 </td>
97
98 <td style="text-align:center; width:auto; background-color:${headerColor}">
99 <p><center style="margin:10px"><font color="${titleColor}" id="progress_reports">progress</font></center></p>
100 </td>
101 </tr>
102 <tr>
103 <td style="text-align:center; width:auto; background-color:${headerColor}">
104 <h2><center style="margin:10px"><u><font color="${titleColor}">incomings</font></u></center></h2>
105 </td>
106 <td style="text-align:center; width:auto; background-color:${headerColor}">
107 <center style="margin:10px"><u><input class="btn" type="button" id="upload_incomings" onclick="uploadIncomings()" value="Upload"></center>
108 </td>
109 <td style="text-align:center; width:auto; background-color:${headerColor}">
110 <p><center style="margin:10px" ><font color="${titleColor}" id="progress_incomings">progress</font></center></p>
111 </td>
112 </tr>
113 <tr>
114 <td style="text-align:center; width:auto; background-color:${headerColor}">
115 <h2><center style="margin:10px"><u><font color="${titleColor}">All info</font></u></center></h2>
116 </td>
117 <td style="text-align:center; width:auto; background-color:${headerColor}">
118 <center style="margin:10px"><u><input class="btn" type="button" onclick="uploadAll()" value="Upload all"></center>
119 </td>
120 <td style="text-align:center; width:auto; background-color:${headerColor}">
121 <p><center style="margin:10px" ><font color="${titleColor}" id="progress_all">progress</font></center></p>
122 </td>
123 </tr>
124 </table>
125 <h2><center style="margin:10px"><u><font color="${titleColor}">Search reports</font></u></center></h2>
126 <table id="table_upload" class="" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor}">
127 <tr>
128 <td style="text-align:center; width:auto; background-color:${headerColor}">
129 <center style="margin:10px"><u><input class="btn" type="button" onclick="loadReports()" value="Load reports"></center>
130 </td>
131 <td style="text-align:center; width:auto; background-color:${headerColor}">
132 <center style="margin:10px"><u><input style="text-align: center;" type="text" id="input_search" onclick="" placeholder="coord" ></center>
133 </td>
134 <td style="text-align:center; width:auto; background-color:${headerColor}">
135 <p><center style="margin:10px"><font color="${titleColor}" id="progress_search">status</font></center></p>
136 </td>
137 </tr>
138 </table>
139 <center style="margin:10px"><div id="report_view" style="background-color:#d2c09e"> report view <div><center>
140
141 </div>
142 `;
143 ////////////////////////////////////////add and remove window from page///////////////////////////////////////////
144 if(document.getElementById("incomings_table")==null){
145 $("#div_container").remove()
146 $("#contentContainer").eq(0).prepend(html);
147 $("#mobileContent").eq(0).prepend(html);
148
149 if(game_data.device=="desktop"){
150 $("#div_container").css("position","fixed");
151 $("#div_container").draggable();
152 }
153 }
154 function closeWindow(){
155 document.getElementById("div_container").remove();
156 list_href=[]
157 // window.location.reload();
158 }
159
160
161
162 function addWindow(){
163 $("#contentContainer").eq(0).prepend(html);
164 $("#mobileContent").eq(0).prepend(html);
165
166 if(game_data.device=="desktop"){
167 $("#div_container").css("position","fixed");
168 $("#div_container").draggable();
169 }
170 }
171
172 var loadReportsOk=false;
173 $("#input_search").on("input",function(){
174 if(loadReportsOk==false)
175 UI.ErrorMessage("upload reports first","fast")
176 })
177 $("#input_search").mouseout(function(){
178 if(loadReportsOk==false)
179 $("#input_search").val("");
180 })
181
182 if(document.getElementById("incomings_table")!=null){
183 window.setInterval(function(){
184
185 var rows= $(".row_a,.row_b")
186 console.log("check incomings")
187 for(let i=0;i<rows.length;i++)
188 {
189 let currentHour=rows[i].children[rows[i].children.length-1].innerText.split(":")
190 if(parseInt(currentHour[0])==0 && parseInt(currentHour[1])==0 && parseInt(currentHour[2])<20){
191 rows[i].remove();
192 }
193 // else{
194 // break;
195 // }
196 }
197 },10000)
198 }
199
200
201 function uploadAll(){
202 uploadReports(uploadIncomings);
203 }
204
205
206 /////////////////////////////////////////////////get all reports info//////////////////////////////////////////////////////////////////
207 function uploadReports(callback){
208 let list_href=[]
209 document.getElementById("progress_reports").innerText="get links..";
210
211 let nameHistoryReports=game_data.world +"HistoryReports"
212 var map_idReports=new Map();
213 var current_page=window.location.href;
214 if(localStorage.getItem(nameHistoryReports)==null){
215 localStorage.setItem(nameHistoryReports,JSON.stringify(Array.from(new Map().entries())))
216 }
217 else{
218 map_idReports=new Map(JSON.parse(localStorage.getItem(nameHistoryReports)));
219 Array.from(map_idReports.keys()).forEach(el=>{
220 let currentDate=new Date();
221 let reportDate=new Date(map_idReports.get(el))
222 if(currentDate.getTime()- reportDate.getTime() > 20*24*3600*1000){
223 console.log("remove: "+map_idReports.get(el))
224 map_idReports.delete(el)
225 }
226 })
227
228 }
229
230 $(document).on('click','.autoHideBox',function(){
231 UI.SuccessMessage("stop",2000)
232 list_href=[]
233 })
234
235
236 getPromiseListHref=getLinks(true,map_idReports);//only current folder
237 getPromiseListHref.then( result=>{
238 console.log(result)
239 list_href=result;
240 list_href=list_href.reverse();
241 console.log(list_href)
242 var list_data_reports=[]
243 var nr_reports=0;
244 var nr_reports_total=list_href.length
245 addWindow();
246 document.getElementById("progress_reports").innerText=nr_reports+"/"+nr_reports_total+" reports";
247 // UI.InfoMessage(nr_reports+"/"+nr_reports_total+" reports")
248 var current_url
249 function ajaxRequest (urls) {
250 var time= 0
251 if(urls.length>0)
252 current_url=urls.pop().href;
253 else
254 current_url="stop"
255 console.log("inside function "+urls.length)
256 if (urls.length >= 0 && current_url!= "stop") {
257 var start_ajax=new Date()
258 $.ajax({
259 method: 'GET',
260 url: current_url,
261 })
262 .done(function (result) {
263 document.body.innerHTML= result;
264 result=null
265 // addWindow();
266 var startReport=new Date().getTime();
267 let list=getDataReport(tribemates);
268 var stopReport=new Date().getTime();
269 console.log(stopReport-startReport)
270 console.log(list)
271 if(list==null ){
272 console.log("recaptcha, upload again")
273 UI.ErrorMessage("recaptcha, upload again","slow")
274 addWindow();
275 document.getElementById("progress_reports").innerText="recaptcha";
276 list_href=[]
277
278 }
279 else{
280 console.log("reports info "+list.length)
281 for(let j=0;j<list.length;j++){
282 list_data_reports.push({"coord":list[j].coord,"reportInfo":list[j].reportInfo});
283 }
284 // document.getElementById("progress_reports").innerText=nr_reports+"/"+nr_reports_total+" reports";
285 UI.SuccessMessage(nr_reports+"/"+nr_reports_total+" reports")
286
287 nr_reports++;
288 let idReport= parseInt(current_url.match(/view=(\d+)/)[1]);
289 let currentDate=new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate();
290 if(document.getElementsByClassName("unit-item unit-item-axe").length>0){
291 var time_report=document.getElementsByClassName("vis")[3].firstElementChild.children[1].children[1].innerText;
292 map_idReports.set(idReport,time_report)
293 }
294 else{
295 map_idReports.set(idReport,currentDate)
296 }
297 }
298 var stop_ajax=new Date();
299 var dif_time=stop_ajax.getTime()-start_ajax.getTime();
300 console.log("dif_time "+dif_time+" wait "+(200-dif_time))
301 window.setTimeout(function(){
302 ajaxRequest(list_href);
303 },200-dif_time)
304 });
305
306 }
307 else
308 {
309 ////////////////////////////////////extract data from dropbox/////////////////////////////////////////
310 console.log("inainte de a extrage date din dropbox")
311
312 $.ajax({
313 url: "https://content.dropboxapi.com/2/files/download",
314 method: 'POST',
315 dataType: "text",
316 headers: { 'Authorization': 'Bearer ' + dropboxToken,
317 'Dropbox-API-Arg': JSON.stringify({path: "/"+filename_reports})},
318
319 success: (data) => {
320 map_dropbox=new Map( JSON.parse( lzw_decode(data) ));
321
322 console.log("map_dropbox")
323 console.log(map_dropbox);
324 console.log("list_data_reports")
325 console.log(list_data_reports);
326
327
328 document.body.innerHTML= httpGet(current_page);
329 addWindow();
330 let nr_update=0;
331 let nr_write=0;
332 list_data_reports.forEach(function(el){
333 if(map_dropbox.has(el.coord)){//update el[0]=key
334 if(el.reportInfo.typeAttacker=="new_off"){
335 console.log("new_off, don't do anything")
336 }else{
337 console.log("coord exists in dropbox already")
338 let time_prev=new Date(map_dropbox.get(el.coord).time_report);
339 let time_current=new Date(el.reportInfo.time_report);
340 console.log(time_current-time_prev)
341 if(time_current-time_prev<48*3600*1000 && (el.reportInfo.typeAttacker=="def" )){//48 hours
342 console.log("a fost def_cat")
343 map_dropbox.set(el.coord,el.reportInfo)
344 nr_update++;
345 }
346 else if(time_current-time_prev>0 ){
347 console.log("update coord: "+el.coord+" in dropbox")
348 map_dropbox.set(el.coord,el.reportInfo)
349 nr_update++;
350 }
351
352 }
353 }
354 else{//write
355 console.log("write coord in dropbox")
356 map_dropbox.set(el.coord,el.reportInfo)
357 nr_write++;
358 }
359 })
360 UI.SuccessMessage("compressing database, wait few seconds",2000)
361
362 window.setTimeout(function(){
363 console.log(map_dropbox)
364 var nr_start=new Date().getTime()
365
366 var length_data=JSON.stringify(Array.from(map_dropbox.entries())).length;
367 var data=lzw_encode(JSON.stringify(Array.from(map_dropbox.entries())))
368 var length_data_compressed=data.length;
369
370 var nr_stop=new Date().getTime()
371 console.log("compressing data: "+(nr_stop-nr_start))
372 console.log("length before: "+length_data+" length after compression: "+length_data_compressed)
373 console.log("compression factor: "+(length_data/length_data_compressed) )
374 // var nr_start=new Date().getTime()
375 uploadFile(data,filename_reports,dropboxToken)
376 // var nr_stop=new Date().getTime()
377 // console.log("time upload "+(nr_stop-nr_start))
378
379 localStorage.setItem(nameHistoryReports,JSON.stringify(Array.from(map_idReports.entries())))
380 document.getElementById("progress_reports").innerText="done";
381 UI.SuccessMessage("upload reports done\n update: "+nr_update+" \nwrite: "+nr_write,4000)
382 },400)
383
384
385 }
386 }).done(function(){
387 if(typeof(callback)==="function" && current_url!="stop")
388 callback();
389
390 }).fail(function(){
391 // alert("error upload")
392 UI.ErrorMessage("upload again \n try after few minutes")
393
394 })
395
396 }
397 }
398 ajaxRequest(list_href);
399 }).catch(result=>{
400 console.log(result)
401 })
402 }
403
404 /////////////////////////////////////////////////get all reports info MANUAL//////////////////////////////////////////////////////////////////
405 function uploadReportsManual(){
406 let list_href=[]
407 let types=["off","new_off","def","def_cat",'def_spy',"spy","def??","none"]
408 document.getElementById("progress_reports").innerText="get links..";
409
410 let nameHistoryReports=game_data.world +"HistoryReports"
411 var map_idReports=new Map();
412 var current_page=window.location.href;
413 if(localStorage.getItem(nameHistoryReports)==null){
414 localStorage.setItem(nameHistoryReports,JSON.stringify(Array.from(new Map().entries())))
415 }
416 else{
417 map_idReports=new Map(JSON.parse(localStorage.getItem(nameHistoryReports)));
418 Array.from(map_idReports.keys()).forEach(el=>{
419 let currentDate=new Date();
420 let reportDate=new Date(map_idReports.get(el))
421 if(currentDate.getTime()- reportDate.getTime() > 20*24*3600*1000){
422 console.log("remove: "+map_idReports.get(el))
423 map_idReports.delete(el)
424 }
425 })
426
427 }
428
429 $(document).on('click','.autoHideBox',function(){
430 UI.SuccessMessage("stop",2000)
431 list_href=[]
432 })
433
434
435 getPromiseListHref=getLinks(true,map_idReports);//only current folder
436 getPromiseListHref.then( result=>{
437 console.log(result)
438 list_href=result;
439 list_href=list_href.reverse();
440 console.log(list_href)
441 var list_data_reports=[]
442 var nr_reports=0;
443 var nr_reports_total=list_href.length
444 addWindow();
445 document.getElementById("progress_reports").innerText=nr_reports+"/"+nr_reports_total+" reports";
446 // UI.InfoMessage(nr_reports+"/"+nr_reports_total+" reports")
447 var current_url
448 function ajaxRequest (urls) {
449 var time= 0
450 if(urls.length>0)
451 current_url=urls.pop().href;
452 else
453 current_url="stop"
454 console.log("inside function "+urls.length)
455 if (urls.length >= 0 && current_url!= "stop") {
456 var start_ajax=new Date()
457 $.ajax({
458 method: 'GET',
459 url: current_url,
460 })
461 .done(function (result) {
462 document.body.innerHTML= result;
463 result=null
464 // addWindow();
465 let list=getDataReport(tribemates);
466 console.log(list)
467 if(list==null ){
468 console.log("recaptcha, upload again")
469 UI.ErrorMessage("recaptcha, upload again","slow")
470 addWindow();
471 document.getElementById("progress_reports").innerText="recaptcha";
472 list_href=[]
473
474 }
475 else{
476 console.log("reports info "+list.length)
477 for(let j=0;j<list.length;j++){
478
479 if(document.getElementById("select_type_attacker")==null && !tribemates.includes(list[j].reportInfo.nameAttacker)){
480 let type=(list[j].reportInfo.typeAttacker!="?")?list[j].reportInfo.typeAttacker:"none"
481
482 console.log(type)
483 let htmlSelect='<select id="select_type_attacker" style="width: 100%">';
484 for(let k=types.length-1;k>=0;k--){
485 htmlSelect+='<option value="'+types[k]+'">'+types[k]+'</option>'
486 }
487 htmlSelect+='</select>';
488 $("#attack_info_att").append(htmlSelect)
489 document.getElementById("select_type_attacker").value=type
490 }
491 if(document.getElementById("select_type_defender")==null && !tribemates.includes(list[j].reportInfo.nameDefender)){
492 let type=(list[j].reportInfo.typeDefender!="?")?list[j].reportInfo.typeDefender:"none"
493 console.log(type)
494 let htmlSelect='<select id="select_type_defender" style="width: 100%">';
495 for(let k=types.length-1;k>=0;k--){
496 htmlSelect+='<option value="'+types[k]+'">'+types[k]+'</option>'
497 }
498 htmlSelect+='</select>';
499 $("#attack_info_def").append(htmlSelect)
500 document.getElementById("select_type_defender").value=type
501
502 }
503
504 }
505 // document.getElementById("progress_reports").innerText=nr_reports+"/"+nr_reports_total+" reports";
506 UI.SuccessMessage(nr_reports+"/"+nr_reports_total+" reports")
507
508 nr_reports++;
509 let idReport= parseInt(current_url.match(/view=(\d+)/)[1]);
510 let currentDate=new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate();
511 if(document.getElementsByClassName("unit-item unit-item-axe").length>0){
512 var time_report=document.getElementsByClassName("vis")[3].firstElementChild.children[1].children[1].innerText;
513 map_idReports.set(idReport,time_report)
514 }
515 else{
516 map_idReports.set(idReport,currentDate)
517 }
518 }
519 var stop_ajax=new Date();
520 var dif_time=stop_ajax.getTime()-start_ajax.getTime();
521 console.log("dif_time "+dif_time+" wait "+(200-dif_time))
522
523 window.onkeyup = function(e) {
524 console.log(e.which)
525 if(e.which==13 && current_url!= "stop"){
526 console.log("next")
527 window.onkeyup = function(e){}
528
529 for(let j=0;j<list.length;j++){
530 if(document.getElementById("select_type_attacker")!=null){
531 let type=document.getElementById("select_type_attacker").value
532 if(type!="none"){
533 list[j].reportInfo.typeAttacker=type
534 list_data_reports.push({"coord":list[j].coord,"reportInfo":list[j].reportInfo});
535 }
536 }
537 if(document.getElementById("select_type_defender")!=null){
538 let type=document.getElementById("select_type_defender").value
539 if(type!="none"){
540 list[j].reportInfo.typeDefender=type
541 list_data_reports.push({"coord":list[j].coord,"reportInfo":list[j].reportInfo});
542 }
543 }
544
545 }
546 console.log("new list")
547 console.log(list)
548 console.log("big list")
549 console.log(list_data_reports)
550
551 window.setTimeout(function(){
552 ajaxRequest(list_href);
553 },200-dif_time)
554 }
555 e.preventDefault()
556 }
557 });
558
559 }
560 else
561 {
562 ////////////////////////////////////extract data from dropbox/////////////////////////////////////////
563 console.log("inainte de a extrage date din dropbox")
564
565 $.ajax({
566 url: "https://content.dropboxapi.com/2/files/download",
567 method: 'POST',
568 dataType: "text",
569 headers: { 'Authorization': 'Bearer ' + dropboxToken,
570 'Dropbox-API-Arg': JSON.stringify({path: "/"+filename_reports})},
571
572 success: (data) => {
573 map_dropbox=new Map( JSON.parse( lzw_decode(data)));
574
575 console.log("map_dropbox")
576 console.log(map_dropbox);
577 console.log("list_data_reports")
578 console.log(list_data_reports);
579
580
581 document.body.innerHTML= httpGet(current_page);
582 addWindow();
583 let nr_update=0;
584 let nr_write=0;
585 list_data_reports.forEach(function(el){
586 if(map_dropbox.has(el.coord)){//update el[0]=key
587 if(el.reportInfo.typeAttacker=="new_off"){
588 console.log("new_off, don't do anything")
589 }else{
590 console.log("coord exists in dropbox already")
591 let time_prev=new Date(map_dropbox.get(el.coord).time_report);
592 let time_current=new Date(el.reportInfo.time_report);
593 console.log(time_current-time_prev)
594 if(time_current-time_prev<48*3600*1000 && (el.reportInfo.typeAttacker=="def" )){//48 hours
595 console.log("a fost def_cat")
596 map_dropbox.set(el.coord,el.reportInfo)
597 nr_update++;
598 }
599 else if(time_current-time_prev>0 ){
600 console.log("update coord: "+el.coord+" in dropbox")
601 map_dropbox.set(el.coord,el.reportInfo)
602 nr_update++;
603 }
604
605 }
606 }
607 else{//write
608 console.log("write coord in dropbox")
609 map_dropbox.set(el.coord,el.reportInfo)
610 nr_write++;
611 }
612 })
613 UI.SuccessMessage("compressing database, wait few seconds")
614 window.setTimeout(function(){
615 var data=lzw_encode(JSON.stringify(Array.from(map_dropbox.entries())))
616 console.log(map_dropbox)
617 console.log("hai ba")
618 uploadFile(data,filename_reports,dropboxToken)
619 localStorage.setItem(nameHistoryReports,JSON.stringify(Array.from(map_idReports.entries())))
620 document.getElementById("progress_reports").innerText="done";
621 UI.SuccessMessage("upload reports done\n update: "+nr_update+" \nwrite: "+nr_write,4000)
622 },400)
623
624
625 }
626 }).fail(function(){
627 // alert("error upload")
628 UI.ErrorMessage("upload again \n try after few minutes")
629
630 })
631
632 }
633 }
634 ajaxRequest(list_href);
635 }).catch(result=>{
636 console.log(result)
637 })
638 }
639 ///////////////////////////////////////////////////////////////////get all links////////////////////////////////////////////////////////////////
640 function getLinks(all,map_idReports){
641 // var currentPage=document.body.innerHTML;
642 return new Promise((resolve,reject)=>{
643 let list_pages=[]
644 let current_href=window.location.href;
645 if(current_href.includes("screen=report"))
646 all=false;
647 if(all){// all pages from all folders
648 let index=window.location.href.lastIndexOf("game.php")
649 let href= window.location.href.substr(0,index)+"game.php?"+"screen=report&mode=all&group_id=-1";
650 if(current_href.includes("t=")){
651 href+="&t="+current_href.split("t=")[1].split("&")[0];
652 }
653 list_pages.push(href)
654 document.body.innerHTML=httpGet(href)
655 }else{
656 list_pages.push(current_href)
657 }
658 if(document.getElementsByClassName("vis")[1].getElementsByTagName("select").length>0){
659 Array.from(document.getElementsByClassName("vis")[1].getElementsByTagName("select")[0]).forEach(function(item){
660 list_pages.push(item.value)
661 })
662 }
663 else if(document.getElementsByClassName("paged-nav-item").length>0){//all pages from the current folder
664 if(all==false){
665 let current_link=window.location.href;
666 list_pages.push(current_link);
667 }
668 Array.from(document.getElementsByClassName("paged-nav-item")).forEach(function(item){
669 list_pages.push(item.href);
670 })
671 }
672
673 console.log("list pages")
674 console.log(list_pages)
675
676 let list_href=[];
677 var indexIncoming=1;
678 var url_length=list_pages.length
679 function ajaxRequest (urls) {
680 let current_url
681
682 if(urls.length>0){
683 current_url=urls.pop()
684 }
685 else{
686 current_url="stop"
687 }
688 console.log("in functie in plm "+urls.length)
689 // console.log(current_url)
690 var start_ajax=new Date();
691 if (urls.length >= 0 && current_url!="stop") {
692 $.ajax({
693 url: current_url,
694 method: 'get',
695 success: (data) => {
696 document.body.innerHTML=data
697 let table_report= document.getElementById("report_list").firstElementChild.children;
698 let year=document.getElementById("serverDate").innerText.split("/")[2];
699 for(let i=1;i<table_report.length-1;i++){
700 let month_day=table_report[i].children[2].innerText;
701 let date_report=new Date(year+" "+month_day)
702 let current_date=new Date();
703 if(Math.abs(current_date-date_report)<19*24*3600*1000){//old
704
705 let img_icon=table_report[i].children[1].children[0].children.length;
706 if(img_icon>0){//wordsTranslate[0]=supports ///// || table_report[i].innerText.includes(wordsTranslate[0])
707 let obj={
708 id:table_report[i].getElementsByTagName("a")[0].getAttribute("data-id"),
709 href:table_report[i].getElementsByTagName("a")[0].href
710 }
711 if(!map_idReports.has(parseInt(obj.id)))
712 list_href.push(obj)
713 }
714 }
715 }
716
717
718 UI.InfoMessage("page "+indexIncoming+"/"+url_length)
719 indexIncoming++;
720 var stop_ajax=new Date();
721 var dif_time=stop_ajax.getTime()-start_ajax.getTime();
722 window.setTimeout(function(){
723 ajaxRequest (list_pages)
724 },200-dif_time)
725 }
726 })
727
728 }
729 else
730 {
731 UI.SuccessMessage("done",2000)
732 resolve(list_href)
733 }
734 }
735 if(list_pages.length>0)
736 ajaxRequest(list_pages);
737 else
738 reject("error??")
739
740 })
741
742 }
743
744 ////////////////////////////////////////////////////////////get data from report////////////////////////////////////////////////////////////////////
745
746 function getDataReport(tribemates){
747 var mapObject={};
748 var listObject=[];
749
750 // tribemates=[]
751 var reportInfo={};
752 try{
753 if($("#attack_info_att").length>0){
754 var attackInfo=$("#attack_info_att");
755 if(attackInfo.text().includes("deleted") || attackInfo.text().includes("---")){
756 console.log("error upload")
757 return 0;
758 }
759 var defenseInfo = $("#attack_info_def");
760 if(defenseInfo.text().includes("deleted") || defenseInfo.text().includes("---")){
761 console.log("error upload")
762 return 0;
763 }
764
765 var attackingPlayer = attackInfo.find('a[href*=info_player]');
766 var defendingPlayer = defenseInfo.find('a[href*=info_player]');
767 var attackingPlayerId=attackingPlayer.prop('href').match(/id=(\w+)/)[1];
768 var defendingPlayerId=defendingPlayer.prop('href').match(/id=(\w+)/)[1];
769 reportInfo.attackingPlayerId=attackingPlayerId;
770 reportInfo.defendingPlayerId=defendingPlayerId;
771 }
772 ///////////////////////////////////////////////////////////////////////////
773
774
775 if(document.getElementsByClassName("unit-item unit-item-axe").length>1)
776 {
777 var time_report=document.getElementsByClassName("vis")[3].firstElementChild.children[1].children[1].innerText;
778 // if(new Date()-new Date(time_report)>14*24*3600*1000)//report too old
779 // return listObject;
780 reportInfo.attackingArmy = attackInfo.find('#attack_info_att_units tr:nth-of-type(2) .unit-item').get().map((el) => { return { type: $(el).prop('class').match(/unit-item-([\w\-]+)/)[1], count: parseInt($(el).text().trim()) } })
781 reportInfo.attackingArmyLosses = attackInfo.find('#attack_info_att_units tr:nth-of-type(3) .unit-item').get().map((el) => { return { type: $(el).prop('class').match(/unit-item-([\w\-]+)/)[1], count: parseInt($(el).text().trim()) } })
782
783 reportInfo.time_report=time_report
784 var report=document.getElementsByClassName("vis")[3].innerHTML;
785 var index=report.indexOf('<div class="no-preview">');
786 report=report.substring(0,index);
787 // report=lzw_encode(report);
788 // reportInfo.report=report;
789
790 ///////////////////////////defender date////////////////////
791 var nameAttacker=document.getElementById("attack_info_att").children[0].children[0].children[1].innerText;
792 var coordAttacker=document.getElementsByClassName("village_anchor")[0].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
793 var nameDefender=document.getElementById("attack_info_def").children[0].children[0].children[1].innerText;
794 var coordDefender=document.getElementsByClassName("village_anchor")[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
795 reportInfo.nameAttacker=nameAttacker;
796 reportInfo.coordAttacker=coordAttacker;
797 reportInfo.nameDefender=nameDefender;
798 reportInfo.coordDefender=coordDefender;
799
800 if(reportInfo.attackingArmy[3].type=="archer"){
801 var spear_atac_total =reportInfo.attackingArmy[0].count
802 var sword_atac_total =reportInfo.attackingArmy[1].count
803 var axe_atac_total =reportInfo.attackingArmy[2].count
804 var archer_atac_total=reportInfo.attackingArmy[3].count
805 var spy_atac_total =reportInfo.attackingArmy[4].count*2
806 var light_atac_total =reportInfo.attackingArmy[5].count*4
807 var heavy_atac_total =reportInfo.attackingArmy[7].count*6
808 var ram_atac_total =reportInfo.attackingArmy[8].count*5
809 var cat_atac_total =reportInfo.attackingArmy[9].count*8
810 var noble=parseInt(document.getElementsByClassName("unit-item unit-item-snob")[0].innerText)*100;
811
812 var spear_atac_pierderi =reportInfo.attackingArmyLosses[0].count
813 var sword_atac_pierderi =reportInfo.attackingArmyLosses[1].count
814 var axe_atac_pierderi =reportInfo.attackingArmyLosses[2].count
815 var archer_atac_pierderi=reportInfo.attackingArmyLosses[3].count
816 var spy_atac_pierderi =reportInfo.attackingArmyLosses[4].count*2
817 var light_atac_pierderi =reportInfo.attackingArmyLosses[5].count*4
818 var heavy_atac_pierderi =reportInfo.attackingArmyLosses[7].count*6
819 var ram_atac_pierderi =reportInfo.attackingArmyLosses[8].count*5
820 var cat_atac_pierderi =reportInfo.attackingArmyLosses[9].count*8
821 }
822 else{
823 var spear_atac_total=reportInfo.attackingArmy[0].count
824 var sword_atac_total=reportInfo.attackingArmy[1].count
825 var axe_atac_total =reportInfo.attackingArmy[2].count
826 var spy_atac_total =reportInfo.attackingArmy[3].count*2
827 var light_atac_total=reportInfo.attackingArmy[4].count*4
828 var heavy_atac_total=reportInfo.attackingArmy[5].count*6
829 var ram_atac_total =reportInfo.attackingArmy[6].count*5
830 var cat_atac_total =reportInfo.attackingArmy[7].count*8
831 var noble=parseInt(document.getElementsByClassName("unit-item unit-item-snob")[0].innerText)*100;
832 var archer_atac_total=0;
833
834 var spear_atac_pierderi=reportInfo.attackingArmyLosses[0].count
835 var sword_atac_pierderi=reportInfo.attackingArmyLosses[1].count
836 var axe_atac_pierderi =reportInfo.attackingArmyLosses[2].count
837 var spy_atac_pierderi =reportInfo.attackingArmyLosses[3].count*2
838 var light_atac_pierderi=reportInfo.attackingArmyLosses[4].count*4
839 var heavy_atac_pierderi=reportInfo.attackingArmyLosses[5].count*6
840 var ram_atac_pierderi =reportInfo.attackingArmyLosses[6].count*5
841 var cat_atac_pierderi =reportInfo.attackingArmyLosses[7].count*8
842
843 }
844
845
846
847 var typeAttacker="?";
848 var nrTroupesAttacker=0;
849 var nrTroupesAttackerTotal=0;
850 var time_return=0;
851
852
853 if(axe_atac_total+light_atac_total+ram_atac_total >=2500 && axe_atac_total>=2500)
854 {
855 typeAttacker="off";
856 nrTroupesAttacker=(axe_atac_total-axe_atac_pierderi)+(light_atac_total-light_atac_pierderi) + (ram_atac_total-ram_atac_pierderi);
857 console.log("ianinte")
858 if(ram_atac_total>0 && noble==0 && axe_atac_total>=2000){
859 console.log("aici")
860 nrTroupesAttackerTotal=axe_atac_total+light_atac_total+ram_atac_total
861 let time_attack=ramSpeed*calcDistance(coordAttacker,coordDefender)
862 time_return=new Date(time_report).getTime()+time_attack;
863 time_return=new Date(time_return)
864 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
865 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
866
867 }else if(axe_atac_total>=2000 && noble==0 ){
868 nrTroupesAttackerTotal=axe_atac_total+light_atac_total
869 time_attack=axeSpeed*calcDistance(coordAttacker,coordDefender)
870 time_return=new Date(time_report).getTime()+time_attack;
871 time_return=new Date(time_return)
872 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
873 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
874
875 }else if(axe_atac_total>=2000 && noble>0){
876 nrTroupesAttackerTotal=axe_atac_total+light_atac_total+ram_atac_total
877 time_attack=axeSpeed*calcDistance(coordAttacker,coordDefender)
878 time_return=new Date(time_report).getTime()+time_attack;
879 time_return=new Date(time_return)
880 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
881 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
882 }
883 }
884 else if(spy_atac_total>10000){
885 typeAttacker="spy";
886 nrTroupesAttacker=spy_atac_total-spy_atac_pierderi;
887 }
888 else if(axe_atac_total+light_atac_total+ram_atac_total >20 && spear_atac_total+sword_atac_total+archer_atac_total+heavy_atac_total<15)
889 {
890 typeAttacker="new_off";
891 }
892 else if(axe_atac_total+light_atac_total+ram_atac_total <15 && spear_atac_total+sword_atac_total+archer_atac_total+heavy_atac_total>15){
893 typeAttacker="def";
894 }
895 else if(spy_atac_total>=800 && axe_atac_total+light_atac_total+ram_atac_total<500 && spear_atac_total+sword_atac_total+archer_atac_total+heavy_atac_total<40)
896 typeAttacker="def_spy";
897
898 if((cat_atac_total>=50*8 && typeAttacker=="def") || (cat_atac_total>=50*8 && axe_atac_total+light_atac_total+ram_atac_total<20)){
899 typeAttacker="def_cat";
900 nrTroupesAttacker=cat_atac_total-cat_atac_pierderi;
901 if(noble==0){
902 nrTroupesAttackerTotal=heavy_atac_total+cat_atac_total
903 time_attack=ramSpeed*calcDistance(coordAttacker,coordDefender)
904 time_return=new Date(time_report).getTime()+time_attack;
905 time_return=new Date(time_return)
906 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
907 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
908 }
909 }
910
911 reportInfo.time_return=time_return
912 reportInfo.nrTroupesAttackerTotal=nrTroupesAttackerTotal
913 reportInfo.typeAttacker=typeAttacker;
914 reportInfo.nrTroupesAttacker=nrTroupesAttacker;
915
916
917
918 /////////////////////////////////////////////////defender date/////////////////////
919 var nrTroupesDefender=0;
920 var typeDefender="?";
921 if(document.getElementsByClassName("unit-item unit-item-axe").length>2){
922
923 reportInfo.defendingArmy = defenseInfo.find('#attack_info_def_units tr:nth-of-type(2) .unit-item').get().map((el) => { return { type: $(el).prop('class').match(/unit-item-([\w\-]+)/)[1], count: parseInt($(el).text().trim()) } })
924 reportInfo.defendingArmyLosses = defenseInfo.find('#attack_info_def_units tr:nth-of-type(3) .unit-item').get().map((el) => { return { type: $(el).prop('class').match(/unit-item-([\w\-]+)/)[1], count: parseInt($(el).text().trim()) } })
925
926
927 if(reportInfo.defendingArmy[3].type=="archer"){
928 var spear_aparare_total =reportInfo.defendingArmy[0].count
929 var sword_aparare_total =reportInfo.defendingArmy[1].count
930 var axe_aparare_total =reportInfo.defendingArmy[2].count
931 var archer_aparare_total=reportInfo.defendingArmy[3].count
932 var spy_aparare_total =reportInfo.defendingArmy[4].count*2
933 var light_aparare_total =reportInfo.defendingArmy[5].count*4
934 var heavy_aparare_total =reportInfo.defendingArmy[7].count*6
935 var ram_aparare_total =reportInfo.defendingArmy[8].count*5
936 var cat_aparare_total =reportInfo.defendingArmy[9].count*8
937
938 var spear_aparare_pierderi =reportInfo.defendingArmyLosses[0].count
939 var sword_aparare_pierderi =reportInfo.defendingArmyLosses[1].count
940 var axe_aparare_pierderi =reportInfo.defendingArmyLosses[2].count
941 var archer_aparare_pierderi=reportInfo.defendingArmyLosses[3].count
942 var spy_aparare_pierderi =reportInfo.defendingArmyLosses[4].count*2
943 var light_aparare_pierderi =reportInfo.defendingArmyLosses[5].count*4
944 var heavy_aparare_pierderi =reportInfo.defendingArmyLosses[7].count*6
945 var ram_aparare_pierderi =reportInfo.defendingArmyLosses[8].count*5
946 var cat_aparare_pierderi =reportInfo.defendingArmyLosses[9].count*8
947
948 }
949 else{
950 var spear_aaparare_total=reportInfo.defendingArmy[0].count
951 var sword_aparare_total =reportInfo.defendingArmy[1].count
952 var axe_aparare_total =reportInfo.defendingArmy[2].count
953 var spy_aparare_total =reportInfo.defendingArmy[3].count*2
954 var light_aparare_total =reportInfo.defendingArmy[4].count*4
955 var heavy_aparare_total =reportInfo.defendingArmy[5].count*6
956 var ram_aparare_total =reportInfo.defendingArmy[6].count*5
957 var cat_aparare_total =reportInfo.defendingArmy[7].count*8
958 var archer_aparare_total=0;
959
960 var spear_aaparare_pierderi=reportInfo.defendingArmyLosses[0].count
961 var sword_aparare_pierderi =reportInfo.defendingArmyLosses[1].count
962 var axe_aparare_pierderi =reportInfo.defendingArmyLosses[2].count
963 var spy_aparare_pierderi =reportInfo.defendingArmyLosses[3].count*2
964 var light_aparare_pierderi =reportInfo.defendingArmyLosses[4].count*4
965 var heavy_aparare_pierderi =reportInfo.defendingArmyLosses[5].count*6
966 var ram_aparare_pierderi =reportInfo.defendingArmyLosses[6].count*5
967 var cat_aparare_pierderi =reportInfo.defendingArmyLosses[7].count*8
968 var archer_aparare_pierderi=0;
969
970 }
971
972
973
974 nrTroupesDefender=(axe_aparare_total-axe_aparare_pierderi)+(light_aparare_total-light_aparare_pierderi) + (ram_aparare_total-ram_aparare_pierderi);
975 if(axe_aparare_total+light_aparare_total+ram_aparare_total >=2500 && axe_aparare_total>=2500){
976 typeDefender="off";
977 }
978
979
980 }
981
982 if(document.getElementsByClassName("unit-item unit-item-axe").length>4){
983 let travelingTroopsContainer = $(document).find('#attack_spy_away');
984 if (travelingTroopsContainer.length)
985 {
986 reportInfo.travelingTroops = {};
987
988 travelingTroopsContainer.find('.unit-item').each((i, el) => {
989 let $el = $(el);
990 let cls = $el.prop('class');
991 let unitType = cls.match(/unit\-item\-(\w+)/)[1];
992 reportInfo.travelingTroops[unitType] = parseInt($el.text().trim());
993 });
994
995 var axe_aparare_spy=reportInfo.travelingTroops.axe
996 var light_aparare_spy=reportInfo.travelingTroops.light*4;
997 var ram_aparare_spy=reportInfo.travelingTroops.ram*5;
998 nrTroupesDefender+=axe_aparare_spy+(light_aparare_spy) + (ram_aparare_spy);
999
1000 if(axe_aparare_total+axe_aparare_spy>2500)
1001 typeDefender="off";
1002 else if(nrTroupesDefender>=2500 && axe_aparare_spy>=2500)
1003 typeDefender="off";
1004
1005
1006
1007 var spear_aparare_spy=reportInfo.travelingTroops.spear
1008 var sword_aparare_spy=reportInfo.travelingTroops.sword
1009 if(document.getElementsByClassName("unit-item unit-item-archer").length>0)
1010 var archer_aparare_spy=reportInfo.travelingTroops.archer
1011 else
1012 var archer_aparare_spy=0
1013
1014 var heavy_aparare_spy=reportInfo.travelingTroops.heavy*6;
1015 var trupe_aparare_total=spear_aparare_total+sword_aparare_total+archer_aparare_total+heavy_aparare_total;
1016 var total_aparare_spy=spear_aparare_spy+sword_aparare_spy+archer_aparare_spy+heavy_aparare_spy;
1017
1018 if(total_aparare_spy>1000){
1019 typeDefender="def";
1020 nrTroupesDefender=total_aparare_spy;
1021 }
1022 else if(axe_aparare_spy+light_aparare_spy <10 && axe_aparare_total+light_aparare_total<100 && trupe_aparare_total>5000 && total_aparare_spy<=1000){
1023 typeDefender="def??";
1024 }
1025 }
1026
1027 }
1028 reportInfo.typeDefender=typeDefender;
1029 reportInfo.nrTroupesDefender=nrTroupesDefender;
1030
1031
1032
1033 if(!tribemates.includes(nameAttacker)){//!reportInfo.typeAttacker.includes("?")
1034 // console.log("attacker")
1035 mapObject.coord=coordAttacker;
1036 mapObject.reportInfo=reportInfo;
1037 listObject.push(mapObject);
1038 mapObject={};
1039 }
1040 if(!tribemates.includes(nameDefender)){
1041 // console.log("defender")
1042 mapObject.coord=coordDefender;
1043 mapObject.reportInfo=reportInfo;
1044 listObject.push(mapObject);
1045 }
1046 }
1047 else if(document.getElementsByClassName("unit-item unit-item-axe").length==1)
1048 {
1049 var typeSupporter="?";
1050 var nrTroupesSupporter=0;
1051 let time_report=document.getElementsByClassName("vis")[3].firstElementChild.children[1].children[1].innerText;
1052 if(new Date()-new Date(time_report)>14*3600*1000)//report too old
1053 return listObject;
1054 var report=document.getElementsByClassName("vis")[3].innerHTML;
1055 // report=lzw_encode(report);
1056 reportInfo.time_report=time_report;
1057 // reportInfo.report=report;
1058
1059 var text=document.getElementsByClassName("vis")[3].innerText.split("\n");
1060 var nameSupporter=text[3].split(":")[1].trim();
1061 var coordSupporter=text[4].split(":")[1].trim().match(/[0-9]{3}\|[0-9]{3}/)[0];
1062 var supporterPlayerId=document.getElementsByClassName("vis")[3].getElementsByTagName("a")[1].href.split("id=")[1]
1063 // var supporterPlayerId=document.getElementsByClassName("village_anchor contexted")[0].getAttribute("data-player")
1064
1065 reportInfo.nameSupporter=nameSupporter;
1066 reportInfo.coordSupporter=coordSupporter;
1067 reportInfo.supporterPlayerId=supporterPlayerId;
1068
1069
1070 var axe_total=parseInt(document.getElementsByClassName("unit-item unit-item-axe")[0].innerText);
1071 var light_total=parseInt(document.getElementsByClassName("unit-item unit-item-light")[0].innerText)*4;
1072 var ram_total=parseInt(document.getElementsByClassName("unit-item unit-item-ram")[0].innerText)*5;
1073
1074 var spear_total=parseInt(document.getElementsByClassName("unit-item unit-item-spear")[0].innerText);
1075 var sword_total=parseInt(document.getElementsByClassName("unit-item unit-item-sword")[0].innerText);
1076 var archer_total=parseInt(document.getElementsByClassName("unit-item unit-item-archer")[0].innerText);
1077 var heavy_total=parseInt(document.getElementsByClassName("unit-item unit-item-heavy")[0].innerText)*6;
1078
1079 var total_atac=axe_total+light_total+ram_total;
1080 var total_aparare=spear_total+sword_total+archer_total+heavy_total;
1081
1082 if(total_atac>total_aparare && total_atac>=200){
1083 typeSupporter="off";
1084 nrTroupesSupporter=total_atac;
1085 }
1086 else if(total_aparare>total_atac && total_aparare>=200){
1087 typeSupporter="def";
1088 nrTroupesSupporter=total_aparare;
1089 }
1090 reportInfo.typeSupporter=typeSupporter;
1091 reportInfo.nrTroupesSupporter=nrTroupesSupporter;
1092
1093 if(!tribemates.includes(nameSupporter) && !reportInfo.typeSupporter.includes("?")){
1094 // console.log("supporter")
1095 mapObject.coord=coordSupporter;
1096 mapObject.reportInfo=reportInfo;
1097 listObject.push(mapObject);
1098 }
1099 }
1100 else if(document.getElementsByClassName("unit-item unit-item-axe").length==0 || document.getElementsByClassName("g-recaptcha").length>0
1101 ||document.getElementsByClassName("unit-item unit-item-axe")==undefined || checkContainsCaptcha(document)==true){//recaptcha
1102 console.log("recapthca")
1103 return null;
1104 }
1105
1106 return listObject;
1107 }
1108 catch(e){
1109 console.log("erorr in upload")
1110 return 0;
1111 }
1112
1113 }
1114
1115 function checkContainsCaptcha(docOrHtml) {
1116 var foundCaptcha = false;
1117 if (typeof docOrHtml == 'string') {
1118 foundCaptcha = !!docOrHtml.match(/data\-bot\-protect=/);
1119 } else {
1120 let $doc = $(docOrHtml);
1121 let $body = $doc.find('#ds_body');
1122 foundCaptcha = $body.length && !!$body.data('bot-protect')
1123 }
1124
1125 if (foundCaptcha) console.log('Found captcha!');
1126 return foundCaptcha;
1127 }
1128
1129 function calcDistance(coord1,coord2)
1130 {
1131 let x1=parseInt(coord1.split("|")[0])
1132 let y1=parseInt(coord1.split("|")[1])
1133 let x2=parseInt(coord2.split("|")[0])
1134 let y2=parseInt(coord2.split("|")[1])
1135
1136 return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
1137 }
1138
1139 ////////////////////////////////////////////////data compression////////////////////////////////////////////////////////////////////////////
1140 function lzw_encode (s) {
1141 if (!s) return s;
1142 var dict = new Map(); // Use a Map!
1143 var data = (s + "").split("");
1144 var out = [];
1145 var currChar;
1146 var phrase = data[0];
1147 var code = 256;
1148 for (var i = 1; i < data.length; i++) {
1149 currChar = data[i];
1150 if (dict.has(phrase + currChar)) {
1151 phrase += currChar;
1152 } else {
1153 out.push (phrase.length > 1 ? dict.get(phrase) : phrase.codePointAt(0));
1154 dict.set(phrase + currChar, code);
1155 code++;
1156 if (code === 0xd800) { code = 0xe000; }
1157 phrase = currChar;
1158 }
1159 }
1160 out.push (phrase.length > 1 ? dict.get(phrase) : phrase.codePointAt(0));
1161 for (var i = 0; i < out.length; i++) {
1162 out[i] = String.fromCodePoint(out[i]);
1163 }
1164 //console.log ("LZW MAP SIZE", dict.size, out.slice (-50), out.length, out.join("").length);
1165 return out.join("");
1166 }
1167 ////////////////////////////////////////////////data decompression////////////////////////////////////////////////////////////////////////////
1168 function lzw_decode (s) {
1169 var dict = new Map(); // Use a Map!
1170 var data = Array.from(s + "");
1171 //var data = (s + "").split("");
1172 var currChar = data[0];
1173 var oldPhrase = currChar;
1174 var out = [currChar];
1175 var code = 256;
1176 var phrase;
1177 for (var i = 1; i < data.length; i++) {
1178 var currCode = data[i].codePointAt(0);
1179 if (currCode < 256) {
1180 phrase = data[i];
1181 } else {
1182 phrase = dict.has(currCode) ? dict.get(currCode) : (oldPhrase + currChar);
1183 }
1184 out.push(phrase);
1185 var cp = phrase.codePointAt(0);
1186 currChar = String.fromCodePoint(cp); //phrase.charAt(0);
1187 dict.set(code, oldPhrase + currChar);
1188 code++;
1189 if (code === 0xd800) { code = 0xe000; }
1190 oldPhrase = phrase;
1191 }
1192 return out.join("");
1193 }
1194 ///////////////////////////////////////////////////////get request//////////////////////////////////////////////////////////////////////////
1195 function httpGet(theUrl)
1196 {
1197 var xmlHttp = new XMLHttpRequest();
1198 xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
1199 xmlHttp.send( null );
1200 return xmlHttp.responseText;
1201 }
1202
1203 ///////////////////////////////////////////////////////get speed//////////////////////////////////////////////////////////////////////////
1204
1205
1206
1207
1208 ///////////////////////////////////////////////////////get all incomings//////////////////////////////////////////////////////////////////////////
1209
1210 function getIncomings(){
1211 return new Promise( (resolve,reject)=>{
1212
1213 if(document.getElementsByClassName("info").length>0)
1214 $(".info").remove()
1215 var current_href_incomings=window.location.href;
1216 let index=window.location.href.lastIndexOf("game.php")
1217 let incomings_href= window.location.href.substr(0,index)+"game.php?"+"screen=overview_villages&mode=incomings&type=all&subtype=attacks&group=0&page=-1";
1218 if(current_href_incomings.includes("t="))
1219 {
1220 incomings_href+="&t="+current_href_incomings.split("t=")[1].split("&")[0];
1221 }
1222 console.log("currentLink")
1223 console.log(incomings_href)
1224 document.body.innerHTML=httpGet(incomings_href);
1225 let list_href=[];
1226 if(document.getElementsByClassName("vis")[1].getElementsByTagName("select").length>0){
1227 Array.from(document.getElementsByClassName("vis")[1].getElementsByTagName("select")[0].options).forEach(el=>{
1228 list_href.push(el.value);
1229 })
1230 list_href.pop();
1231 }
1232 else if(document.getElementsByClassName("paged-nav-item").length>0){
1233 let arr=Array.from(document.getElementsByClassName("paged-nav-item"));
1234 for(let i=0;i<arr.length;i++)
1235 list_href.push(arr[i].getAttribute("href"))
1236 }
1237 else{
1238 list_href.push(incomings_href)
1239
1240 }
1241 if(document.getElementById("incomings_table")==null)
1242 throw new Error("you don't have any incomings");
1243
1244 console.log(list_href)
1245 let incomings_data=new Map();
1246
1247
1248 var indexIncoming=1;
1249 var url_length=list_href.length
1250 var start_ajax=new Date();
1251 function ajaxRequest (urls) {
1252 let current_url
1253 var time=0
1254 if(urls.length>0){
1255 current_url=urls.pop()
1256 }
1257 else{
1258 current_url="stop"
1259 }
1260 console.log("in functie in plm "+urls.length)
1261 // console.log(current_url)
1262
1263 if (urls.length >= 0 && current_url!="stop") {
1264 $.ajax({
1265 url: current_url,
1266 method: 'get',
1267 success: (data) => {
1268 document.body.innerHTML=data
1269 if(document.getElementById("incomings_table")==null)
1270 alert("turn off the filters");
1271 let table_incomings=document.getElementById("incomings_table").getElementsByTagName("tbody")[0].children
1272 for(let i=1;i<table_incomings.length-1;i++){
1273 if(table_incomings[i].children[0].innerText!="--"){
1274 let coord_dest=table_incomings[i].children[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
1275 let coord_origin=table_incomings[i].children[2].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
1276 let length_tr=table_incomings[i].children.length
1277 let time_land=table_incomings[i].children[length_tr-2].innerText
1278 let server_date=document.getElementById("serverDate").innerText.split("/")
1279 let date_land="";
1280 if(time_land.includes(wordsTranslate[1])){//wordsTranslate[1]==today
1281 date_land=server_date[1]+"/"+server_date[0]+"/"+server_date[2]+" "+time_land.split(" ")[2];
1282 }
1283 else if(time_land.includes(wordsTranslate[2])){//wordsTranslate[2]== tomorrow
1284 var tomorrow_date=new Date(server_date[1]+"/"+server_date[0]+"/"+server_date[2]);
1285 tomorrow_date.setDate(tomorrow_date.getDate()+1);
1286 date_land= ("0"+(tomorrow_date.getMonth()+1)).slice(-2)+"/"+("0"+tomorrow_date.getDate()).slice(-2)+"/"+tomorrow_date.getFullYear()+" "+time_land.split(" ")[2];
1287 }else if(time_land.includes(wordsTranslate[3])){//wordsTranslate[3]==on
1288 var on=time_land.split(" ")
1289 date_land=on[1].split(".")[1]+"/"+on[1].split(".")[0]+"/"+server_date[2]+" "+on[3];
1290 }
1291 // console.log(date_land)
1292 if(!incomings_data.has(coord_origin)){
1293 let list=[date_land]
1294 incomings_data.set(coord_origin,list)
1295
1296 }else{
1297 let list=incomings_data.get(coord_origin)
1298 list.push(date_land)
1299 incomings_data.set(coord_origin,list)
1300 }
1301 }
1302 }
1303
1304 UI.InfoMessage(indexIncoming+"/"+url_length)
1305 indexIncoming++;
1306 var stop_ajax=new Date();
1307 var dif_time=stop_ajax.getTime()-start_ajax.getTime()
1308 window.setTimeout(function(){
1309 ajaxRequest (list_href)
1310 },200)
1311 }
1312 })
1313
1314 }
1315 else
1316 {
1317 UI.SuccessMessage("done",2000)
1318 if(document.getElementById("incomings_table")!=null){
1319 // showButtons();
1320 }
1321
1322 if( document.getElementsByClassName("g-recaptcha").length>0){//recaptcha
1323 console.log("recapthca")
1324 UI.ErrorMessage("recapthca, upload again")
1325 resolve(null);
1326 }
1327
1328 window.setTimeout(function(){
1329 document.body.innerHTML=httpGet(current_href_incomings);
1330 console.log(incomings_data)
1331 resolve(incomings_data)
1332 },1000+Math.random()*500)
1333
1334
1335
1336 }
1337 }
1338 if(list_href.length>0)
1339 ajaxRequest(list_href);
1340 else
1341 reject("error on incomings")
1342 })
1343 }
1344 ///////////////////////////////////////////////////////upload all incomings//////////////////////////////////////////////////////////////////////////
1345
1346 function uploadIncomings(){
1347
1348 $.ajax({
1349 url: "https://content.dropboxapi.com/2/files/download",
1350 method: 'POST',
1351 dataType: "text",
1352 headers: { 'Authorization': 'Bearer ' + dropboxToken,
1353 'Dropbox-API-Arg': JSON.stringify({path: "/"+filename_incomings})},
1354
1355 success: (data) => {
1356 let map_incomings_dropbox=new Map(JSON.parse(lzw_decode(data)))
1357 let keys_dropbox=Array.from(map_incomings_dropbox.keys());
1358
1359 let server_date=document.getElementById("serverDate").innerText.split("/")
1360 let server_time=document.getElementById("serverTime").innerText
1361 let current_date=new Date(server_date[1]+"/"+server_date[0]+"/"+server_date[2]+" "+server_time);
1362 /////////////////////////////////eliminate old incomings from dropbox////////////////////////////////////
1363 let start=new Date();
1364 keys_dropbox.forEach(el=>{
1365 let list=map_incomings_dropbox.get(el);
1366 let update=false;
1367 for(let i=0;i<list.length;i++){
1368 let date_incomings=new Date(list[i])
1369 // console.log(date_incomings<current_date)
1370 if(date_incomings<current_date){
1371 list.splice(i,1);
1372 i--;
1373 update=true;
1374 }
1375 if(list[i]==""){
1376 list.splice(i,1);
1377 update=true;
1378 }
1379
1380 }
1381 if(update==true || list.length==0){
1382 if(list.length==0)
1383 map_incomings_dropbox.delete(el);
1384 else{
1385 map_incomings_dropbox.set(el,list);
1386 }
1387 }
1388 })
1389 let stop=new Date();
1390 console.log(stop-start)
1391 var incomings_data
1392 var getPromiseIncoming=getIncomings();
1393 getPromiseIncoming.then( result=>{
1394 incomings_data=result
1395 let keys_incomings=Array.from(incomings_data.keys());
1396 keys_incomings.forEach(el=>{
1397 let list=incomings_data.get(el)
1398 if(map_incomings_dropbox.has(el)){//update
1399 let list_dropbox=map_incomings_dropbox.get(el)
1400 list_dropbox=list_dropbox.concat(list);
1401 var list_concat =[...new Set([...list ,...list_dropbox])];
1402 map_incomings_dropbox.set(el,list_concat);
1403 }
1404 else{//add
1405 map_incomings_dropbox.set(el,list);
1406 }
1407 })
1408 console.log(map_incomings_dropbox)
1409 UI.SuccessMessage("compressing database, wait few seconds",2000)
1410 window.setTimeout(function(){
1411 var data=lzw_encode(JSON.stringify(Array.from(map_incomings_dropbox.entries())))
1412 console.log("scris in test2")
1413 // document.body.innerHTML=httpGet(current_href_incomings);
1414 addWindow();
1415 showButtons();
1416 document.getElementById("progress_incomings").innerText=incomings_data.size+" villages";
1417 document.getElementById("progress_all").innerText="done";
1418 UI.SuccessMessage("upload incomings done","slow")
1419 uploadFile(data,filename_incomings,dropboxToken)
1420 },400)
1421 }).catch(message=>alert(message))
1422
1423
1424 }
1425 }).fail(function(){
1426 // alert("error upload")
1427 UI.ErrorMessage("error upload incomings")
1428 })
1429 }
1430
1431 //////////////////////////////////////////////////////upload all data to dropbox/////////////////////////////////////////////////////////////////
1432
1433 function uploadFile(data,filename,dropboxToken)
1434 {
1435 var file = new Blob([data], {type: "plain/text"});
1436 var nr_start1=new Date().getTime();
1437 file.name=filename;
1438
1439 //stop refreshing the page
1440 $(document).bind("keydown", disableF5);
1441 window.onbeforeunload = function (e) {
1442 console.log("is uploading");
1443 return "are you sure?";
1444 };
1445
1446 var xhr = new XMLHttpRequest();
1447 xhr.upload.onprogress = function(evt) {
1448 console.log(evt)
1449 var percentComplete = parseInt(100.0 * evt.loaded / evt.total);
1450 console.log(percentComplete)
1451 UI.SuccessMessage("progress upload: "+percentComplete+"%")
1452 };
1453
1454 xhr.onload = function() {
1455 if (xhr.status === 200) {
1456 var fileInfo = JSON.parse(xhr.response);
1457 // Upload succeeded. Do something here with the file info.
1458 UI.SuccessMessage("upload succes")
1459 var nr_stop1=new Date().getTime();
1460 console.log("time upload: "+(nr_stop1-nr_start1))
1461
1462 //enable refresh page
1463 window.onbeforeunload = function (e) {
1464 console.log("done");
1465 };
1466 $(document).unbind("keydown", disableF5);
1467
1468 }
1469 else {
1470 var errorMessage = xhr.response || 'Unable to upload file';
1471 // Upload failed. Do something here with the error.
1472 UI.SuccessMessage("upload failed")
1473 }
1474 };
1475
1476 xhr.open('POST', 'https://content.dropboxapi.com/2/files/upload');
1477 xhr.setRequestHeader('Authorization', 'Bearer ' + dropboxToken);
1478 xhr.setRequestHeader('Content-Type', 'application/octet-stream');
1479 xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
1480 path: '/' + file.name,
1481 mode: 'add',
1482 autorename: true,
1483 mode:'overwrite',
1484 mute: false
1485 }));
1486
1487 xhr.send(file)
1488 }
1489
1490 function disableF5(e) { if ((e.which || e.keyCode) == 116 || (e.which || e.keyCode) == 82) e.preventDefault(); };
1491
1492
1493 //////////////////////////////////////////////////////buttons in incomings page/////////////////////////////////////////////////////////////////
1494
1495
1496 function showButtons(){
1497 if(document.getElementById("incomings_table")!=null){
1498 $("#table_incomings").remove();
1499 var incomingshtml=`
1500
1501 <table id="table_incomings" class="" border="1" style="width: 50%;">
1502 <tbody>
1503 <tr>
1504 <td style="text-align:center; width:auto;">
1505 <center style="margin:10px"><u><input class="btn" type="button" onclick="addWindow()"value="open upload"></center>
1506 </td>
1507
1508 <td style="text-align:center; width:auto;">
1509 <center style="margin:10px"><u><input class="btn" type="button" onclick="moreInfo()" value="more info"></center>
1510 </td>
1511 <td style="text-align:center; width:auto;">
1512 <center style="margin:10px"><u><input class="btn" id="btn_tag" type="button" onclick="tagIncomings()" value="tag"></center>
1513 </td>
1514 <td style="text-align:center; width:auto;">
1515 <center style="margin:10px"><u><input class="btn" type="button" onclick="setIntervalIncomings()" value="get incomings"></center>
1516 </td>
1517 <td style="text-align:center; width:auto;">
1518 <center style="margin:10px"><u><input id="btn_highlight" class="btn" type="button" onclick="toggleHighLight()" value="highlight"></center>
1519 </td>
1520 </tr>
1521 </tbody>
1522 </table>
1523 </div>`
1524 // $(".vis").eq(3).append(incomingshtml)
1525 $(".overview_filters").before(incomingshtml)
1526
1527 var link = document.createElement('link');
1528 link.id = "style_popup";
1529 link.rel = 'stylesheet';
1530 link.type = 'text/css';
1531 link.href = 'https://dl.dropboxusercontent.com/s/ki0zhogjf0705c3/style_popup.css';
1532 link.media = 'all';
1533 document.getElementsByTagName('head')[0].appendChild(link);
1534 }
1535
1536
1537
1538
1539 }
1540 showButtons();
1541
1542 //////////////////////////////////////////////////////show info in incomings page/////////////////////////////////////////////////////////////////
1543
1544
1545
1546 function moreInfo(){
1547 let map_reports_dropbox
1548 let map_incomings_dropbox
1549 $("#div_container").remove();
1550 $(".deleteTh").remove();
1551
1552 console.log("inainte")
1553
1554 $.ajax({
1555 url: "https://content.dropboxapi.com/2/files/download",
1556 method: 'POST',
1557 dataType: "text",
1558 headers: { 'Authorization': 'Bearer ' + dropboxToken,
1559 'Dropbox-API-Arg': JSON.stringify({path: "/"+filename_reports})},
1560 before:function(){
1561 UI.InfoMessage("load reports..","fast")
1562 },
1563 complete:function(){
1564 UI.SuccessMessage("done reports","fast")
1565 },
1566 success: (data_reports) => {
1567 map_reports_dropbox=new Map( JSON.parse( lzw_decode(data_reports)));
1568
1569 console.log(map_reports_dropbox)
1570 console.log("get reports")
1571
1572
1573 $.ajax({
1574 url: "https://content.dropboxapi.com/2/files/download",
1575 method: 'POST',
1576 dataType: "text",
1577 headers: { 'Authorization': 'Bearer ' + dropboxToken,
1578 'Dropbox-API-Arg': JSON.stringify({path: "/"+filename_incomings})},
1579 before:function(){
1580 UI.InfoMessage("load incomings..","fast")
1581 },
1582 complete:function(){
1583 UI.SuccessMessage("done incomings","fast")
1584 },
1585 success: (data_incomings) => {
1586 console.log("get incomings")
1587 $(".tr_delimitator").remove();
1588 map_incomings_dropbox=new Map(JSON.parse(lzw_decode(data_incomings)))
1589 console.log(map_incomings_dropbox)
1590 if(document.getElementsByClassName("info").length>0)
1591 $(".info").remove()
1592 else{
1593 let start=new Date();
1594
1595 let table=document.getElementById("incomings_table").lastElementChild.children;
1596 let list=[];
1597 let map_nr_atacuri=new Map();
1598 let map_nr_destination=new Map();
1599
1600 //adaugare o noua coloana
1601 let coloana_nr=table[0].insertCell(3);
1602 coloana_nr.outerHTML="<th class='deleteTh'><a href=# id='id_nr'> nr</a></th>";
1603 coloana_nr.className="info"
1604
1605 let coloana_tribe=table[0].insertCell(4);
1606 coloana_tribe.outerHTML="<th class='deleteTh'><a href=# id='id_nr_tr'> nr_tribe</a></th>";
1607 coloana_tribe.className="info"
1608
1609 let coloana_type=table[0].insertCell(5);
1610 coloana_type.outerHTML="<th class='deleteTh'><a href=# id='id_type'> type</a></th>";
1611 coloana_type.className="info"
1612
1613 let coloana_pop=table[0].insertCell(6);
1614 coloana_pop.outerHTML="<th class='deleteTh'><a href=# id='id_pop'>pop</a></th>";
1615 coloana_pop.className="info"
1616
1617 let coloana_time=table[0].insertCell(7);
1618 coloana_time.outerHTML="<th class='deleteTh'><a href=# id='id_time'>time</a></th>";
1619 coloana_time.className="info"
1620
1621 let coloana_report=table[0].insertCell(8);
1622 coloana_report.outerHTML="<th class='deleteTh'><a href=# id='id_report'>report</a></th>";
1623 coloana_report.className="info"
1624
1625 var list_coord_player=[]
1626 for(let i=1;i<table.length-1;i++){
1627 let coord=table[i].children[2].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
1628 let coord_destination=table[i].children[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
1629 let player_id=table[i].children[table[i].children.length-4].children[0].href.split("player&id=")[1]
1630 list_coord_player.push({
1631 coord:coord,
1632 player_id:player_id
1633 })
1634 //origin coord
1635 if(map_nr_atacuri.has(coord))
1636 map_nr_atacuri.set(coord,parseInt(map_nr_atacuri.get(coord)) +1);
1637 else
1638 map_nr_atacuri.set(coord,1);
1639 //destination coord
1640 if(map_nr_destination.has(coord_destination))
1641 map_nr_destination.set(coord_destination,parseInt(map_nr_destination.get(coord_destination)) +1);
1642 else
1643 map_nr_destination.set(coord_destination,1);
1644 }
1645 for(let i=1;i<table.length-1;i++){
1646 var html_nr="?"
1647 var html_nr_tribe="<center>0</center>"
1648 var html_type="?"
1649 var html_pop="?"
1650 var html_time="?"
1651 var html_report="?"
1652
1653 var length_tr=table[i].children.length
1654 let coord=list_coord_player[i-1].coord
1655 let player_id=list_coord_player[i-1].player_id
1656 let coord_destination=table[i].children[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
1657 let duplicate_destination=map_nr_destination.get(coord_destination)
1658 table[i].children[1].setAttribute("data-nr",duplicate_destination)
1659
1660
1661 html_nr="<h4>"+map_nr_atacuri.get(coord)+"</h4>";
1662
1663
1664 if(map_incomings_dropbox.has(coord)){
1665 let list_incomings=map_incomings_dropbox.get(coord)
1666 html_nr_tribe=" <center><h4 style='color:black'>"+list_incomings.length+"</h4></center>";
1667 }
1668 if(map_reports_dropbox.has(coord) )
1669 {
1670 let idPlayer_dropbox
1671 let type_dropbox
1672 let nr_troupes_dropbox
1673
1674 var obj=map_reports_dropbox.get(coord);
1675 var traveling=false
1676 if(coord == obj.coordAttacker){
1677 idPlayer_dropbox=obj.attackingPlayerId;
1678 type_dropbox=obj.typeAttacker;
1679 nr_troupes_dropbox=obj.nrTroupesAttacker
1680 traveling=true;
1681 }
1682 else if(coord == obj.coordDefender){
1683 idPlayer_dropbox=obj.defendingPlayerId;
1684 type_dropbox=obj.typeDefender;
1685 nr_troupes_dropbox=obj.nrTroupesDefender
1686 traveling=false;
1687 }
1688 else{
1689 idPlayer_dropbox=obj.supporterPlayerId
1690 type_dropbox=obj.typeSupporter;
1691 nr_troupes_dropbox=obj.nrTroupesSupporter
1692 }
1693
1694 if(idPlayer_dropbox == player_id)
1695 {
1696 let date_start=new Date(obj.time_report);
1697 let date_stop=new Date();
1698 let days=("00"+parseInt((date_stop-date_start)/(24*3600*1000))).slice(-3);
1699 let hours=("0"+parseInt((date_stop-date_start)/(3600*1000)%24)).slice(-2);
1700 let minutes=("0"+parseInt(((date_stop-date_start)/(60*1000)%60))).slice(-2);
1701 let seconds=( "0"+parseInt((((date_stop-date_start)/1000)%60))).slice(-2);
1702
1703 //calculate population
1704 let date_landing_report=new Date(obj.time_report)
1705 let distance=parseFloat(table[i].children[length_tr-3].innerText);
1706 let time_attack=0;
1707 let time_land=table[i].children[length_tr-2].innerText
1708 let date_land=new Date(getLandTime(time_land))
1709 let labelName=""
1710 if(table[i].children[0].getElementsByTagName("img")[1]==undefined || table[i].children[0].getElementsByTagName("img")[1]==null )
1711 labelName="ram.png"
1712 else
1713 labelName=table[i].children[0].getElementsByTagName("img")[1].src
1714
1715 if(labelName.includes("snob.png")){
1716 time_attack=nobleSpeed*distance
1717 }else if(labelName.includes("ram.png")){
1718 time_attack=ramSpeed*distance
1719 }else if(labelName.includes("sword.png")){
1720 time_attack=swordSpeed*distance
1721 }else if(labelName.includes("axe.png")){
1722 time_attack=axeSpeed *distance
1723 }
1724 if(traveling==false)
1725 time_attack=0;
1726
1727 if(type_dropbox=="off"){
1728 console.log(date_land.getTime())
1729 console.log(time_attack)
1730 console.log(date_landing_report.getTime())
1731 let timeForRecruiting = (date_land.getTime()-time_attack)-date_landing_report.getTime()
1732 console.log(timeForRecruiting)
1733 nr_troupes_dropbox=calcProductionTroupes(timeForRecruiting,nr_troupes_dropbox)
1734 nr_troupes_dropbox=Math.round(nr_troupes_dropbox*10)/10+"%"
1735 console.log("final "+nr_troupes_dropbox)
1736 }
1737 else{
1738 nr_troupes_dropbox="?"
1739 }
1740
1741
1742 html_type=" <h4 class='cls_type'>"+type_dropbox+"</h4>"
1743 html_pop=" <h4 class='cls_pop'>"+nr_troupes_dropbox+"</h4>"
1744 if(obj.time_return==0 || obj.time_return==undefined){
1745 html_time=" <h4>"+days+":"+hours+":"+minutes+":"+seconds+"</h4>";
1746 }
1747 else{
1748 html_time=" <h4 class='possible_fake' date-fake='"+obj.time_return+"'>"+days+":"+hours+":"+minutes+":"+seconds+"</h4>";
1749 }
1750
1751
1752 console.log(obj)
1753 html_report=`
1754 <div class="popup" onclick='var popup = document.getElementById("table`+i+`");popup.classList.toggle("show")'><h4>show</h4>
1755 <table class="popuptext" id="table`+i+'"'+
1756 createReport(obj)+
1757 '</table></div>';
1758 }
1759 }
1760 coloana_nr=table[i].insertCell(3);
1761 coloana_nr.innerHTML=html_nr
1762 coloana_nr.className="info test"
1763
1764 coloana_tribe=table[i].insertCell(4);
1765 coloana_tribe.innerHTML=html_nr_tribe
1766 coloana_tribe.className="info"
1767
1768 coloana_type=table[i].insertCell(5);
1769 coloana_type.innerHTML=html_type
1770 coloana_type.className="info"
1771
1772 coloana_pop=table[i].insertCell(6);
1773 coloana_pop.innerHTML=html_pop
1774 coloana_pop.className="info"
1775
1776 coloana_time=table[i].insertCell(7);
1777 coloana_time.innerHTML=html_time
1778 coloana_time.className="info"
1779
1780 coloana_report=table[i].insertCell(8);
1781 coloana_report.innerHTML=html_report
1782 coloana_report.className="info"
1783 }
1784
1785 var stop=new Date();
1786 console.log("add info: "+(stop-start))
1787 sortIncomings();
1788 highLightIncomings();
1789 }
1790 }
1791 })
1792
1793
1794
1795
1796 }
1797 })
1798
1799
1800
1801
1802 }
1803
1804 //////////////////////////////////////////////////////sort incomings by.. /////////////////////////////////////////////////////////////////
1805
1806 function sortIncomings()
1807 {
1808 var table=document.getElementById("incomings_table").lastElementChild.children;
1809 var new_table=document.getElementById("incomings_table").lastElementChild;
1810 var last_row=table[table.length-1];
1811 var list=[];
1812 var list_info=[]
1813 for(let i=1;i<table.length-1;i++){
1814 if(table[i].classList.contains("row_a")){
1815 table[i].classList.remove("row_a")
1816 table[i].classList.add("row_b")
1817 }
1818 if(table[i].classList.contains("selected")){
1819 table[i].classList.remove("selected")
1820 }
1821
1822 list.push(table[i]);
1823 }
1824 var length_table=1
1825 if(table.length>2){
1826 length_table=table[1].children.length
1827 }
1828
1829
1830 //sort by nr
1831 document.getElementById("id_nr").addEventListener("click",function()
1832 {
1833 var start=new Date();
1834 $(".tr_delimitator").remove();
1835 list.sort( (a,b)=>{
1836 return (parseInt(a.children[3].innerText)<parseInt(b.children[3].innerText))?1:(parseInt(a.children[3].innerText)>parseInt(b.children[3].innerText))?-1:
1837 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
1838 });
1839
1840
1841 //add new table in page
1842 for(let i=0;i<list.length;i++)
1843 {
1844 new_table.appendChild(list[i]);
1845 }
1846 new_table.appendChild(last_row);
1847
1848 for(let i=0;i<list.length;i++)
1849 {
1850 list_info.push({
1851 coord_attacker:list[i].children[2].innerText,
1852 nr:parseInt(list[i].children[3].innerText),
1853 })
1854 }
1855 var pozitie=2;
1856 for(let i=0;i<list.length-1;i++)
1857 {
1858 let nr_atacuri=list_info[i].nr
1859 if(nr_atacuri>1 && list_info[i].coord_attacker !=list_info[i+1].coord_attacker)
1860 {
1861 var tableRef = document.getElementById("incomings_table").lastElementChild;
1862 var newRow = tableRef.insertRow(pozitie);
1863 newRow.className="tr_delimitator"
1864 for(let i=0; i<1;i++){
1865 let cell = newRow.insertCell();
1866 cell.setAttribute("colspan",length_table)
1867 cell.classList.add("selected")
1868 var delimitator = document.createTextNode('--');
1869 cell.appendChild(delimitator);
1870
1871 }
1872 pozitie++;
1873 }
1874 else if(nr_atacuri==1){
1875 break;
1876 }
1877 pozitie++;
1878 }
1879 list_info=[]
1880 var stop=new Date();
1881 console.log(stop-start)
1882 })
1883
1884 //sort by nr tribe
1885 document.getElementById("id_nr_tr").addEventListener("click",function()
1886 {
1887 var start=new Date();
1888
1889 $(".tr_delimitator").remove();
1890 list.sort( (a,b)=>{
1891 return (parseInt(a.children[4].innerText)<parseInt(b.children[4].innerText))?1:(parseInt(a.children[4].innerText)>parseInt(b.children[4].innerText))?-1:
1892 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
1893 });
1894
1895
1896 //add new table in page
1897 for(let i=0;i<list.length;i++)
1898 {
1899 new_table.appendChild(list[i]);
1900 }
1901 new_table.appendChild(last_row);
1902
1903 for(let i=0;i<list.length;i++)
1904 {
1905 list_info.push({
1906 coord_attacker:list[i].children[2].innerText,
1907 nr:parseInt(list[i].children[4].innerText),
1908 })
1909 }
1910 var pozitie=2;
1911 for(let i=0;i<list.length-1;i++)
1912 {
1913 let nr_atacuri=list_info[i].nr
1914 if(nr_atacuri>1 && list_info[i].coord_attacker !=list_info[i+1].coord_attacker)
1915 {
1916 var tableRef = document.getElementById("incomings_table").lastElementChild;
1917 var newRow = tableRef.insertRow(pozitie);
1918 newRow.className="tr_delimitator"
1919 for(let i=0; i<1;i++){
1920 let cell = newRow.insertCell();
1921 cell.setAttribute("colspan",length_table)
1922 cell.classList.add("selected")
1923 var delimitator = document.createTextNode('--');
1924 cell.appendChild(delimitator);
1925
1926 }
1927 pozitie++;
1928 }
1929 else if(nr_atacuri==1){
1930 break;
1931 }
1932 pozitie++;
1933 }
1934 list_info=[]
1935 var stop=new Date();
1936 console.log(stop-start)
1937 })
1938
1939
1940 //sort by type
1941 document.getElementById("id_type").addEventListener("click",function()
1942 {
1943 var start=new Date();
1944 $(".tr_delimitator").remove();
1945 list.sort( (a,b)=>{
1946 return (a.children[5].innerText<b.children[5].innerText)?1:(a.children[5].innerText>b.children[5].innerText)?-1:
1947 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
1948 });
1949
1950 //add new table in page
1951 for(let i=0;i<list.length;i++)
1952 {
1953 new_table.appendChild(list[i]);
1954 }
1955 new_table.appendChild(last_row);
1956
1957 var pozitie=2;
1958 for(let i=0;i<list.length-1;i++)
1959 {
1960 let type=list[i].children[5].innerText;
1961 if(type!="?" && list[i].children[5].innerText !=list[i+1].children[5].innerText)
1962 {
1963 var tableRef = document.getElementById("incomings_table").lastElementChild;
1964 var newRow = tableRef.insertRow(pozitie);
1965 newRow.className="tr_delimitator"
1966 for(let i=0; i<1;i++){
1967 let cell = newRow.insertCell();
1968 cell.setAttribute("colspan",length_table)
1969 cell.classList.add("selected")
1970 var delimitator = document.createTextNode('--');
1971 cell.appendChild(delimitator);
1972 }
1973 pozitie++;
1974 }
1975 pozitie++;
1976 }
1977 list_info=[]
1978 var stop=new Date();
1979 console.log(stop-start)
1980 })
1981
1982 //sort by nr pop
1983 document.getElementById("id_pop").addEventListener("click",function()
1984 {
1985 var start=new Date();
1986 console.log("aici baaaa")
1987 console.log($(".tr_delimitator"))
1988 $(".tr_delimitator").remove();
1989 list.sort( (a,b)=>{
1990 if(a.children[6].innerText=="?")
1991 var a_comp=2000000;
1992 else
1993 var a_comp=parseFloat(a.children[6].innerText);
1994
1995 if(b.children[6].innerText=="?")
1996 var b_comp=2000000;
1997 else
1998 var b_comp=parseFloat(b.children[6].innerText);
1999
2000 return (a_comp>b_comp)?1:(a_comp<b_comp)?-1:
2001 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
2002 });
2003
2004 //add new table in page
2005 for(let i=0;i<list.length;i++)
2006 {
2007 new_table.appendChild(list[i]);
2008 }
2009 list_info=[]
2010 new_table.appendChild(last_row);
2011
2012 let pozitie=1
2013 for(let i=0;i<list.length;i++)
2014 {
2015 console.log(i)
2016 if(i%4==0 && i>0){
2017 console.log("inside "+i)
2018 var tableRef = document.getElementById("incomings_table").lastElementChild;
2019 var newRow = tableRef.insertRow(pozitie);
2020 newRow.className="tr_delimitator"
2021 for(let i=0; i<1;i++){
2022 let cell = newRow.insertCell();
2023 cell.setAttribute("colspan",length_table)
2024 cell.classList.add("selected")
2025 var delimitator = document.createTextNode('--');
2026 cell.appendChild(delimitator);
2027 }
2028 pozitie++;
2029
2030 }
2031 pozitie++;
2032 }
2033
2034
2035
2036
2037 var stop=new Date();
2038 console.log(stop-start)
2039 })
2040
2041 //sort by time
2042 document.getElementById("id_time").addEventListener("click",function()
2043 {
2044 var start=new Date();
2045
2046 $(".tr_delimitator").remove();
2047
2048 list.sort( (a,b)=>{
2049 if(a.children[7].innerText=="?")
2050 var a_comp=10000000000;
2051 else{
2052 var v=a.children[7].innerText.split(":");
2053 var a_comp=parseInt(v[0])*24*3600+parseInt(v[1])*3600 +parseInt(v[2])*60 +parseInt(v[3]);
2054 }
2055
2056 if(b.children[7].innerText=="?")
2057 var b_comp=10000000000;
2058 else{
2059 var v=b.children[7].innerText.split(":");
2060 var b_comp=parseInt(v[0])*24*3600+parseInt(v[1])*3600 +parseInt(v[2])*60 +parseInt(v[3]);
2061 }
2062
2063 return (a_comp>b_comp)?1:(a_comp<b_comp)?-1:
2064 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
2065 });
2066
2067 //add new table in page
2068 for(let i=0;i<list.length;i++)
2069 {
2070 new_table.appendChild(list[i]);
2071 }
2072 list_info=[]
2073 new_table.appendChild(last_row);
2074
2075 let pozitie=1
2076 for(let i=0;i<list.length;i++)
2077 {
2078 console.log(i)
2079 if(i%4==0 && i>0){
2080 console.log("inside "+i)
2081 var tableRef = document.getElementById("incomings_table").lastElementChild;
2082 var newRow = tableRef.insertRow(pozitie);
2083 newRow.className="tr_delimitator"
2084 for(let i=0; i<1;i++){
2085 let cell = newRow.insertCell();
2086 cell.setAttribute("colspan",length_table)
2087 cell.classList.add("selected")
2088 var delimitator = document.createTextNode('--');
2089 cell.appendChild(delimitator);
2090 }
2091 pozitie++;
2092
2093 }
2094 pozitie++;
2095 }
2096
2097
2098 var stop=new Date();
2099 console.log(stop-start)
2100 })
2101
2102 //sort by coord destination
2103 var destination_th=document.getElementById("incomings_table").lastElementChild.children[0].children[1]
2104 destination_th=destination_th.getElementsByTagName("a")[0]
2105 destination_th.outerHTML="<a href='#' id='nr_dest'>"+destination_th.innerHTML+"</a>"
2106
2107 document.getElementById("nr_dest").addEventListener("click",function()
2108 {
2109 console.log("aici")
2110 var start=new Date();
2111
2112 $(".tr_delimitator").remove();
2113 list.sort( (a,b)=>{
2114 return (parseInt(a.children[1].getAttribute("data-nr"))<parseInt(b.children[1].getAttribute("data-nr")))?1:
2115 (parseInt(a.children[1].getAttribute("data-nr"))>parseInt(b.children[1].getAttribute("data-nr")))?-1:
2116 (a.children[1].innerText<b.children[1].innerText) ? 1: (a.children[1].innerText>b.children[1].innerText)?-1:0;
2117 });
2118
2119
2120 //add new table in page
2121 for(let i=0;i<list.length;i++)
2122 {
2123 new_table.appendChild(list[i]);
2124 }
2125 new_table.appendChild(last_row);
2126
2127 for(let i=0;i<list.length;i++)
2128 {
2129 list_info.push({
2130 coord_deff:list[i].children[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0],
2131 nr:parseInt(list[i].children[1].getAttribute("data-nr")),
2132 id_coord:list[i].children[1].children[0].href.split("village=")[1].split("&")[0]
2133 })
2134 }
2135 console.log(list_info)
2136
2137 //add delimiter on the first row
2138 var tableRef = document.getElementById("incomings_table").lastElementChild;
2139 var newRow = tableRef.insertRow(1);
2140 newRow.className="tr_delimitator"
2141 let cell = newRow.insertCell();
2142
2143 cell.setAttribute("colspan",length_table)
2144 cell.classList.add("selected")
2145 var delimitator = document.createElement("button")
2146 delimitator.innerText="load: ("+list_info[0].coord_deff+")"
2147 delimitator.setAttribute("data-id",list_info[0].id_coord)
2148 delimitator.setAttribute("data-nr",list_info[0].nr)
2149 delimitator.style.margin="10px"
2150 delimitator.classList.add("btn","load_troops")
2151 cell.appendChild(delimitator);
2152
2153 //add delimiter after each village destination
2154 var pozitie=3;
2155 for(let i=0;i<list.length-1;i++)
2156 {
2157 if(list_info[i].coord_deff !=list_info[i+1].coord_deff)
2158 {
2159 var tableRef = document.getElementById("incomings_table").lastElementChild;
2160 var newRow = tableRef.insertRow(pozitie);
2161 newRow.className="tr_delimitator"
2162 let cell = newRow.insertCell();
2163
2164 cell.setAttribute("colspan",length_table)
2165 cell.classList.add("selected")
2166 var delimitator = document.createElement("button")
2167 delimitator.innerText="load: ("+list_info[i+1].coord_deff+")"
2168 delimitator.setAttribute("data-id",list_info[i+1].id_coord)
2169 delimitator.setAttribute("data-nr",list_info[i+1].nr)
2170 delimitator.style.margin="10px"
2171 delimitator.classList.add("btn","load_troops")
2172 cell.appendChild(delimitator);
2173
2174
2175 pozitie++;
2176 }
2177 pozitie++;
2178 }
2179 list_info=[]
2180 var stop=new Date();
2181 console.log(stop-start)
2182 eventGetTroops();
2183 })
2184
2185
2186 }
2187
2188 //////////////////////////////////////////////////////tag incomings /////////////////////////////////////////////////////////////////
2189 function tagIncomings(){
2190
2191 if(document.getElementsByClassName("info").length==0){
2192 UI.ErrorMessage("press first the button 'more info'!")
2193 }
2194 else{
2195 $("#btn_tag").attr('disabled', true);
2196 $(".tr_delimitator").remove();
2197 let csrf = window.csrf_token;
2198 var list_incomings_href=[]
2199 var indexIncoming=1;
2200 var table_incomings=document.getElementById("incomings_table").children[1].children
2201
2202 var nobleSpeed=2100*1000/(speedWorld*speedTroupes)//ms
2203 var ramSpeed=1800*1000/(speedWorld*speedTroupes)//ms
2204 var swordSpeed=1260*1000/(speedWorld*speedTroupes)//ms
2205 var axeSpeed=1080*1000/(speedWorld*speedTroupes)//ms
2206
2207 for(let i=1;i<table_incomings.length-1;i++){
2208 let incomingId=table_incomings[i].children[0].children[2].getAttribute("data-id");
2209 let coordOrigin=table_incomings[i].children[2].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
2210 let href=window.location.href.split("&")[0]+`&screen=info_command&ajaxaction=edit_other_comment&id=${incomingId}&h=${csrf}`
2211 var nameTroupe=table_incomings[i].children[0].innerText.trim().split(/\s+/)[0];
2212 let nr=parseInt(table_incomings[i].children[3].innerText);
2213 let nr_tribe=table_incomings[i].children[4].innerText;
2214 let type=table_incomings[i].children[5].innerText;
2215 let pop= (table_incomings[i].children[6].innerText !="?")?parseInt(table_incomings[i].children[6].innerText):"?"
2216 let time=table_incomings[i].children[7].innerText;
2217 let length_tr=table_incomings[i].children.length
2218 let nameAttacker=table_incomings[i].children[length_tr-4].innerText
2219 ////////////////////////////////get land time///////////////////////////////
2220 let time_land=table_incomings[i].children[length_tr-2].innerText
2221 let date_land=getLandTime(time_land)
2222
2223 let fake=false;
2224
2225
2226 if(table_incomings[i].getElementsByClassName("possible_fake").length>0 && table_incomings[i].children[0].getElementsByTagName("img").length==2){
2227 let date_home=new Date(table_incomings[i].getElementsByClassName("possible_fake")[0].getAttribute("date-fake"))
2228 let distance=parseFloat(table_incomings[i].children[length_tr-3].innerText);
2229 let labelName=table_incomings[i].children[0].getElementsByTagName("img")[1].src
2230 let time_attack=0;
2231 if(labelName.includes("snob.png")){
2232 time_attack=nobleSpeed*distance
2233 }else if(labelName.includes("ram.png")){
2234 time_attack=ramSpeed*distance
2235 }else if(labelName.includes("sword.png")){
2236 time_attack=swordSpeed*distance
2237 }else if(labelName.includes("axe.png")){
2238 time_attack=axeSpeed *distance
2239 }
2240
2241 let dateLand=new Date(date_land)
2242 console.log(time_attack)
2243 if(time_attack+date_home.getTime()>dateLand.getTime() ){
2244 fake=true;
2245 console.log("fake from "+coordOrigin)
2246 }
2247 var days=parseInt(time.split(":")[0])*24*3600*1000
2248 var hours=parseInt(time.split(":")[1])*3600*1000
2249 var min=parseInt(time.split(":")[2])*60*1000
2250 var sec=parseInt(time.split(":")[3])*1000
2251 var total_time=days+hours+min+sec-time_attack
2252 time=total_time/(24*3600*1000)
2253 time+=":00:00:00"
2254 }
2255
2256 let obj={
2257 incomingId:incomingId,
2258 coordOrigin:coordOrigin,
2259 href:href,
2260 nameTroupe:nameTroupe,
2261 nr:nr,
2262 nr_tribe:nr_tribe,
2263 type:type,
2264 pop:pop,
2265 time:time,
2266 nameAttacker:nameAttacker,
2267 fake:fake,
2268 }
2269 if(!table_incomings[i].children[0].innerText.toLowerCase().includes("attack") && !table_incomings[i].children[0].innerText.toLowerCase().includes('"'))
2270 list_incomings_href.push(obj)
2271 }
2272 list_incomings_href=list_incomings_href.reverse();
2273
2274 var url_length=list_incomings_href.length
2275 var start_tagging=new Date()
2276 function ajaxRequest (urls) {
2277 let current_url
2278 let labelInfo=""
2279 let obj=null
2280 if(urls.length>0){
2281 obj=urls.pop()
2282 let clientTime = Math.round(new Date().valueOf() / 1000);
2283 current_url+="&"+clientTime
2284 current_url=obj.href;
2285 labelInfo=obj.nameTroupe;
2286 let nr
2287 if(obj.nr_tribe=="?")
2288 nr=parseInt(obj.nr)
2289 else{
2290 nr=Math.max(parseInt(obj.nr), parseInt(obj.nr_tribe) )
2291 }
2292
2293 if(obj.type!="?"){
2294 obj.time=parseInt(obj.time.split(":")[0]);
2295
2296 if(obj.nr==20000)
2297 labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" "+obj.type;
2298 else if(obj.type=="new_off")
2299 labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" off";
2300 else if(obj.type.includes("def"))
2301 labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" "+obj.type+" "+obj.time+"d";
2302 else
2303 labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" "+obj.type+" "+obj.pop+"% "+obj.time+"d"
2304 // if(obj.nr==20000)
2305 // labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" "+obj.type;
2306 // else if(obj.type=="new_off")
2307 // labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" off";
2308 // else if(obj.type.includes("def"))
2309 // labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" "+obj.type
2310 // else
2311 // labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" "+obj.type
2312
2313
2314
2315
2316 }
2317 else{
2318 labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr
2319 }
2320 if(obj.fake==true){
2321 labelInfo+=' ("fake")';
2322 }
2323 // console.log(labelInfo)
2324 }
2325 else{
2326 current_url="stop"
2327 }
2328 console.log("in functie in plm "+urls.length)
2329 // console.log(current_url)
2330 var start_ajax=new Date();
2331 if (urls.length >= 0 && current_url!="stop") {
2332 // console.log("rename "+labelInfo)
2333 $.ajax({
2334 url: current_url,
2335 method: 'POST',
2336 dataType: "json",
2337 data: { text: labelInfo },
2338 headers: { 'TribalWars-Ajax': 1 },
2339 success: (data) => {
2340 $("span[data-id="+obj.incomingId+"]").find(".quickedit-label").text(labelInfo)
2341 UI.InfoMessage(indexIncoming+"/"+url_length)
2342 indexIncoming++;
2343 var stop_ajax=new Date();
2344 var dif_time=stop_ajax.getTime()-start_ajax.getTime();
2345 console.log("dif_time "+dif_time+" wait "+(200-dif_time))
2346 window.setTimeout(function(){
2347 ajaxRequest (list_incomings_href)
2348
2349 },200-dif_time)
2350 }
2351 })
2352
2353 }
2354 else
2355 {
2356 UI.SuccessMessage("done",2000)
2357 var stop_tagging=new Date();
2358 console.log("total time "+stop_tagging.getTime()-start_tagging.getTime())
2359
2360 }
2361 }
2362 ajaxRequest(list_incomings_href);
2363
2364 }
2365
2366
2367 }
2368
2369function getLandTime(time_land){
2370 var date_land=""
2371 let server_date=document.getElementById("serverDate").innerText.split("/")
2372 if(time_land.includes(wordsTranslate[1])){ //today
2373 date_land=server_date[1]+"/"+server_date[0]+"/"+server_date[2]+" "+time_land.split(" ")[2];
2374 }
2375 else if(time_land.includes(wordsTranslate[2])){ //tomorrow
2376 var tomorrow_date=new Date(server_date[1]+"/"+server_date[0]+"/"+server_date[2]);
2377 tomorrow_date.setDate(tomorrow_date.getDate()+1);
2378 date_land= ("0"+(tomorrow_date.getMonth()+1)).slice(-2)+"/"+("0"+tomorrow_date.getDate()).slice(-2)+"/"+tomorrow_date.getFullYear()+" "+time_land.split(" ")[2];
2379 }else if(time_land.includes(wordsTranslate[3])){ //on
2380 var on=time_land.split(" ")
2381 date_land=on[1].split(".")[1]+"/"+on[1].split(".")[0]+"/"+server_date[2]+" "+on[3];
2382 }
2383 return date_land;
2384}
2385
2386function calcProductionTroupes(time,popReport){
2387 var maxPop=popReport;
2388 let nrAxemax=6000,nrLcMax=3000,nrRamMax=400;
2389 let countAxe=0,countLc=0,countRam=0;
2390 let time_temp=time
2391 while(maxPop<20000 && time_temp>0){
2392 if(countAxe<nrAxemax){
2393 countAxe++;
2394 time_temp-=axeTime;
2395 maxPop+=1
2396 }
2397 else break;
2398 }
2399 time_temp=time
2400 while(maxPop<20000 && time_temp>0){
2401 if(countLc<nrLcMax){
2402 countLc++;
2403 time_temp-=lhTime;
2404 maxPop+=4
2405 }
2406 else break;
2407 }
2408 time_temp=time
2409 while(maxPop<20000 && time_temp>0){
2410 if(countRam<nrRamMax){
2411 countRam++;
2412 time_temp-=ramTime;
2413 maxPop+=5
2414 }
2415 else break;
2416 }
2417
2418 console.log("axe "+countAxe+" lc "+countLc+" ram "+countRam)
2419 console.log(maxPop)
2420 maxPop=(maxPop/20000)*100
2421 return maxPop
2422}
2423 //////////////////////////////////////////////////////search reports /////////////////////////////////////////////////////////////////
2424
2425 var map_search
2426 function loadReports(){
2427 $.ajax({
2428 url: "https://content.dropboxapi.com/2/files/download",
2429 method: 'POST',
2430 dataType: "text",
2431 headers: { 'Authorization': 'Bearer ' + dropboxToken,
2432 'Dropbox-API-Arg': JSON.stringify({path: "/"+filename_reports})},
2433
2434 success: (data) => {
2435 map_search=new Map( JSON.parse( lzw_decode(data) ));
2436
2437 console.log(map_search)
2438 loadReportsOk=true;
2439 $("#input_search").on("input",function(){
2440 let current_value=$("#input_search").val()
2441 if(current_value.match(/[0-9]{3}\|[0-9]{3}/)!=null){
2442 coords=current_value.match(/[0-9]{3}\|[0-9]{3}/g)
2443 console.log(coords)
2444 $("#report_view").empty()
2445 let contentHtml=""
2446 let nr_found=0;
2447 for(let i=0;i<coords.length;i++){
2448 if(map_search.has(coords[i])){
2449 let obj=map_search.get(coords[i]);
2450 console.log(coords[i])
2451 contentHtml+= `<div>
2452 <center style="margin:10px"><input class="btn evt-confirm-btn btn-confirm-yes" type="button"onclick="$('#table`+i+`').toggle('slow')" value="`+coords[i]+`"></center>
2453
2454 <table class="table_hide" id="table`+i+'"'+
2455 createReport(obj)+
2456 `</table></div>`;
2457 nr_found++;
2458 }
2459 }
2460 $("#report_view").append(contentHtml)
2461 $(".table_hide").hide();
2462 $("#progress_search").text("found: "+nr_found)
2463 }else{
2464 $("#report_view").empty()
2465 }
2466
2467 })
2468 $("#input_search").mouseout(function(){
2469 let current_value=$("#input_search").val()
2470 if(current_value.match(/[0-9]{3}\|[0-9]{3}/)!=null){
2471 let coords=current_value.match(/[0-9]{3}\|[0-9]{3}/g)
2472 $("#input_search").val(Array.from(coords).join(","))
2473 }
2474 }) }
2475 }).done(function(){
2476 UI.SuccessMessage("load reports","fast")
2477 })
2478 }
2479
2480///////////////////////////////////////////////////////create table for view report//////////////////////////////////////////////////////
2481function createReport(obj){
2482 var tableHTML=``;
2483 if(obj.attackingArmy!=undefined){
2484 tableHTML=`
2485 <tbody>
2486 <tr>
2487 <td>Battle time </td>
2488 <td>`+ obj.time_report +`</td>
2489 </tr>
2490 <tr>
2491 <td colspan="2" valign="top" height="160" style="border: solid 1px ; padding 4px;" class="report_ReportAttack">
2492 <table id="attack_info_att" width=100% style="border: 1px solid #DED3B9">
2493 <tbody>
2494 <tr>
2495 <th style="width:20%">Attacker:</th>
2496 <th >`+obj.nameAttacker+`</th>
2497 </tr>
2498 <tr>
2499 <td >Origin:</td>
2500 <td >`+obj.coordAttacker+`</td>
2501 </tr>
2502 <tr>
2503 <td colspan="2" style="padding:0px">`+
2504 createTableTroupes(obj.attackingArmy,obj.attackingArmyLosses)+
2505 `</td>
2506 </tr>
2507 </tbody>
2508 </table>
2509 </td>
2510 </tr>`
2511 }
2512 if(obj.defendingArmy!=undefined){
2513 tableHTML+= `
2514 <tr>
2515 <td colspan="2" valign="top" height="160" style="border: solid 1px ; padding 4px;" >
2516 <table id="attack_info_def" width=100% style="border: 1px solid #DED3B9">
2517 <tbody>
2518 <tr>
2519 <th style="width:20%">Defender:</th>
2520 <th >`+obj.nameDefender+`</th>
2521 </tr>
2522 <tr>
2523 <td >Origin:</td>
2524 <td >`+obj.coordDefender+`</td>
2525 </tr>
2526 <tr>
2527 <td colspan="2" style="padding:0px">`+
2528 createTableTroupes(obj.defendingArmy,obj.defendingArmyLosses)+
2529 `</td>
2530 </tr>
2531 </tbody>
2532 </table>
2533 </td>
2534 </tr>
2535 `
2536 }
2537
2538 if(obj.travelingTroops!=undefined){
2539 tableHTML+= `
2540 <tr>
2541 <td colspan="2" valign="top" height="160" style="border: solid 1px ; padding 4px;">
2542 <table id="attack_spy_away" width=100% style="border: 1px solid #DED3B9; width:100%; margin-top:5px;">
2543 <tbody>
2544 <tr>
2545 <th colspan="2">Units outside of village:</th>
2546 </tr>
2547
2548 <tr>
2549 <td colspan="2" >`+
2550 createTableTroupesAway(obj.travelingTroops)+
2551 `</td>
2552 </tr>
2553 </tbody>
2554 </table>
2555 </td>
2556 </tr>
2557 `
2558 }
2559 if(obj.attackingArmy!=undefined){
2560 tableHTML+="</tbody>"
2561 }
2562
2563 return tableHTML
2564}
2565
2566function createTableTroupes(totalArmy,lostArmy){
2567 let tableHTML=`
2568<table class="vis" >
2569 <tbody>
2570 <tr class="center">
2571 <td width="20"></td>`
2572
2573 let units=game_data.units
2574 for(let i=0;i<totalArmy.length;i++){
2575 if(units[i]!="militia"){
2576 if(totalArmy[i].count==0 )
2577 tableHTML+=`<td width="35"><img src="https://dsen.innogamescdn.com/asset/3ec301e5/graphic/unit/unit_`+units[i]+`.png" alt class="faded"</td>`
2578 else
2579 tableHTML+=`<td width="35"><img src="https://dsen.innogamescdn.com/asset/3ec301e5/graphic/unit/unit_`+units[i]+`.png"</td>`
2580 }
2581 }
2582 tableHTML+="</tr>"
2583 tableHTML+=`
2584 <tr>
2585 <td width="20">Quantity:</td>`
2586 for(let i=0;i<totalArmy.length;i++){
2587 if(units[i]!="militia"){
2588 if(totalArmy[i].count==0)
2589 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+units[i]+` hidden">`+totalArmy[i].count+"</td>"
2590 else
2591 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+units[i]+`">`+totalArmy[i].count+"</td>"
2592 }
2593 }
2594 tableHTML+="</tr>"
2595 tableHTML+=`
2596 <tr>
2597 <td width="20">Losses:</td>`
2598 for(let i=0;i<lostArmy.length;i++){
2599 if(units[i]!="militia"){
2600 if(lostArmy[i].count==0)
2601 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+units[i]+` hidden">`+lostArmy[i].count+"</td>"
2602 else
2603 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+units[i]+`">`+lostArmy[i].count+"</td>"
2604 }
2605 }
2606 tableHTML+="</tr>"
2607
2608
2609
2610
2611 tableHTML+="</tr></tbody></table>"
2612 return tableHTML
2613}
2614
2615
2616function createTableTroupesAway(totalArmy){
2617 let tableHTML=`
2618<table class="vis">
2619 <tbody>
2620 <tr class="center">`
2621
2622 let units=game_data.units
2623 Object.keys(totalArmy).forEach(key=>{
2624 if(totalArmy[key]==0)
2625 tableHTML+=`<th width="35"><img src="https://dsen.innogamescdn.com/asset/3ec301e5/graphic/unit/unit_`+key+`.png" alt class="faded"</th>`
2626 else
2627 tableHTML+=`<th width="35"><img src="https://dsen.innogamescdn.com/asset/3ec301e5/graphic/unit/unit_`+key+`.png"</th>`
2628
2629 })
2630
2631
2632 tableHTML+="</tr>"
2633 tableHTML+=`<tr>`
2634 Object.keys(totalArmy).forEach(key=>{
2635 if(totalArmy[key]==0)
2636 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+key+` hidden">`+totalArmy[key]+"</td>"
2637 else
2638 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+key+`">`+totalArmy[key]+"</td>"
2639
2640 })
2641 tableHTML+="</tr>"
2642
2643 tableHTML+="</tr></tbody></table>"
2644 return tableHTML
2645}
2646
2647
2648
2649////////////////////////////////////////////////////////get speed world///////////////////////////////////////////////////
2650
2651
2652function getSpeedConstant() { //Get speed constant (world speed * unit speed) for world
2653 if (localStorage.getItem(game_data.world+"speedWorld") !== null) {
2654 let obj=JSON.parse(localStorage.getItem(game_data.world+"speedWorld"))
2655 console.log("speed world already exist")
2656 return obj
2657 }
2658 else { //Get data from xml and save it in localStorage to avoid excessive XML requests to server
2659 let currentHtml=document.body.innerHTML
2660 document.body.innerHTML = httpGet("/interface.php?func=get_config") //Load world data
2661 let obj={}
2662 let worldSpeed = Number(document.getElementsByTagName("speed")[0].innerHTML)
2663 let unitSpeed = Number(document.getElementsByTagName("unit_speed")[0].innerHTML);
2664 obj.unitSpeed=unitSpeed
2665 obj.worldSpeed=worldSpeed
2666 document.body.innerHTML=currentHtml
2667 localStorage.setItem(game_data.world+"speedWorld",JSON.stringify(obj));
2668 console.log("save speed world")
2669 return obj
2670 }
2671}
2672
2673
2674
2675
2676
2677/////////////////////////////////////////////////////// interface for get all tr from incomings page/////////////////////////////////////////
2678function setIntervalIncomings(){
2679 htmlInc = `
2680 <div id="div_container" class="ui-widget-content" style="width:600px;background-color:${backgroundColor};cursor:move;z-index:50;">
2681 <div class="close-btn" id="btn_close" onclick="closeWindow()" style="position:absolute;top:10px;right: 10px;"><b><a href=#><font color="${titleColor}">X</font></b></a></div>
2682 <h2><center style="margin:10px"><u><font color="${titleColor}">get all incomings</font></u></center></h2>
2683 <table id="table_upload" class="" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor}">
2684 <tr>
2685 <td style="text-align:center; width:auto; background-color:${headerColor}">
2686 <p><center style="margin:10px"><font color="${titleColor}">between hours </font></center></p>
2687 </td>
2688 <td style="text-align:center; width:auto; background-color:${headerColor}">
2689 <p><center style=""><input type="number" id="id_start" size="5" style="text-align:center" class=" input-nicer show" value="0"><br><br></center></p>
2690 </td>
2691 <td style="text-align:center; width:auto; background-color:${headerColor}">
2692 <p><center style=""><input type="number" id="id_stop" size="5" style="text-align:center" class=" input-nicer show" value="100"><br><br></center></p>
2693 </td>
2694
2695 </tr>
2696 </table>
2697 <center style="margin:10px"><u><input class="btn" type="button" id="btn_village" onclick="getTrIncomings()" value="Start"></center>
2698
2699
2700
2701 </div>
2702 `;
2703 ////////////////////////////////////////add and remove window from page/////////////////////////////////////////////////////////////////
2704 $("#div_container").remove()
2705 $("#contentContainer").eq(0).prepend(htmlInc);
2706 $("#mobileContent").eq(0).prepend(htmlInc);
2707
2708 if(game_data.device=="desktop"){
2709 $("#div_container").css("position","fixed");
2710 $("#div_container").draggable();
2711 }
2712 $('#id_start').on('input',function(e){
2713 let value=this.value;
2714 localStorage.setItem(game_data.world+"startInc",value)
2715 });
2716 $('#id_stop').on('input',function(e){
2717 let value=this.value;
2718 localStorage.setItem(game_data.world+"stopInc",value)
2719 });
2720 if(localStorage.getItem(game_data.world+"startInc")!=null)
2721 $('#id_start').val(localStorage.getItem(game_data.world+"startInc"))
2722 if(localStorage.getItem(game_data.world+"stopInc")!=null)
2723 $('#id_stop').val(localStorage.getItem(game_data.world+"stopInc"))
2724
2725
2726}
2727
2728//////////////////////////////////////////////get a list with all tr ///////////////////////////////////////////////////////////////////
2729function getTrIncomings(){
2730
2731 //get pages for all incoming
2732 let list_pages=[]
2733 let start=parseInt(document.getElementById("id_start").value)
2734 let stop=parseInt(document.getElementById("id_stop").value)
2735
2736 if(document.getElementsByClassName("vis")[1].getElementsByTagName("select").length>0){
2737 Array.from(document.getElementsByClassName("vis")[1].getElementsByTagName("select")[0]).forEach(function(item){
2738 list_pages.push(item.value)
2739 })
2740 list_pages.pop();
2741 }
2742 else if(document.getElementsByClassName("paged-nav-item").length>0){//all pages from the current folder
2743 let nr=0;
2744 Array.from(document.getElementsByClassName("paged-nav-item")).forEach(function(item){
2745 let current=item.href;
2746 current=current.split("page=")[0]+"page="+nr
2747 nr++;
2748 list_pages.push(current);
2749 })
2750 }
2751 else{
2752 let current_link=window.location.href;
2753 list_pages.push(current_link);
2754 }
2755 list_pages=list_pages.reverse();
2756
2757
2758 // go to every page and get incoming
2759 var rows=[]
2760 function ajaxRequest (urls) {
2761 let current_url
2762 var startAjax=new Date().getTime();
2763 if(urls.length>0){
2764 current_url=urls.pop()
2765 }
2766 else{
2767 current_url="stop"
2768 }
2769 console.log(current_url)
2770 if (urls.length >= 0 && current_url!="stop") {
2771 $.ajax({
2772 url: current_url,
2773 method: 'get',
2774 success: (data) => {
2775 document.body.innerHTML=data
2776 var table_incomings=document.getElementById("incomings_table").children[1].children
2777 for(let i=1;i<table_incomings.length-1;i++){
2778 rows.push(table_incomings[i])
2779 }
2780 var stopAjax=new Date().getTime();
2781 var diff=stopAjax-startAjax
2782 console.log("wait inc: "+(200-diff))
2783 window.setTimeout(function(){
2784 ajaxRequest (list_pages)
2785 },200-diff)
2786 }
2787 })
2788
2789 }
2790 else
2791 {
2792 $(".row_a").remove();
2793 $(".row_b").remove();
2794 var table_incomings=document.getElementById("incomings_table")
2795 var lastRow=table_incomings.children[1].children[1];
2796 table_incomings.children[1].children[1].remove();
2797 var nr_row=0;
2798 for(let i=0;i<rows.length;i++){
2799 var hours=rows[i].children[ rows[i].children.length-1 ].innerText.split(":")[0]
2800 if(hours>=start && hours< stop){
2801 $(table_incomings).append(rows[i])
2802 nr_row++;
2803 }
2804 }
2805 table_incomings.children[1].children[0].children[0].innerText="Command ("+nr_row+")"
2806 $(table_incomings).append(lastRow)
2807 UI.SuccessMessage("done")
2808 console.log(rows)
2809 showButtons();
2810
2811 }
2812 }
2813 ajaxRequest(list_pages);
2814
2815}
2816
2817/////////////////////////////////////////////highlight trains->yellow, nobles->red, nukes-> green////////////////////////////////////////
2818function highLightIncomings(){
2819 let table=document.querySelectorAll(".row_a,.row_b")
2820 if(localStorage.getItem(game_data.world+"highlight")=="true"){
2821 let colors = {
2822 yellow: '#ffff66',
2823 red: '#ff8080',
2824 green: '#4dff4d'
2825 };
2826 document.getElementById("btn_highlight").classList.remove("btn-confirm-no")
2827 document.getElementById("btn_highlight").classList.add("btn-confirm-yes")
2828 for(let i=0;i<table.length;i++){
2829 let length_tr=table[i].children.length
2830 table[i].classList.remove("selected")
2831 //highlight nukes if has more than 70% pop
2832 if(document.getElementById("id_type")!=null){
2833 let watchTower=table[i].children[0].getElementsByTagName("img")[0].src.includes("attack_large.png")
2834 let hasNuke=false
2835 if(table[i].getElementsByClassName("cls_type").length>0){
2836 let type=table[i].getElementsByClassName("cls_type")[0].innerText
2837 let pop=parseFloat(table[i].getElementsByClassName("cls_pop")[0].innerText)
2838 if((type=="off" && pop>70)|| watchTower==true){
2839 hasNuke=true;
2840 }
2841 }
2842 if(hasNuke==true || watchTower==true){
2843 $(table[i]).find('td').each(function(){
2844 $(this).css('background-color', colors.green);
2845 });
2846 }
2847 }
2848
2849 //highlight all possible trains
2850 for(let j=i+1;j<table.length;j++){
2851 let tr1=table[i].children[length_tr-2].innerText.match(/[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{3}/)[0]
2852 let tr2=table[j].children[length_tr-2].innerText.match(/[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{3}/)[0]
2853 let time1=parseInt(tr1.split(":")[0])*3600*1000+parseInt(tr1.split(":")[1])*60*1000+parseInt(tr1.split(":")[2])*1000+parseInt(tr1.split(":")[3])
2854 let time2=parseInt(tr2.split(":")[0])*3600*1000+parseInt(tr2.split(":")[1])*60*1000+parseInt(tr2.split(":")[2])*1000+parseInt(tr2.split(":")[3])
2855
2856 if(table[i].children[2].innerHTML==table[j].children[2].innerHTML){//if origin coord is the same
2857 if(Math.abs(time1-time2)==50 || Math.abs(time1-time2)==100 || Math.abs(time1-time2)==150){
2858 // console.log(tr1+" === "+tr2)
2859 // console.log(time1+" === "+time2)
2860 // console.log("diference tr: "+(time2-time1))
2861
2862 $(table[i]).find('td').each(function(){
2863 $(this).css('background-color', colors.yellow);
2864 });
2865 $(table[j]).find('td').each(function(){
2866 $(this).css('background-color', colors.yellow);
2867 });
2868 break;
2869 }
2870 }
2871 if(Math.abs(time1-time2)>200)
2872 break;
2873 }
2874 // highlist if it is tagged as noble
2875 if(table[i].children[0].getElementsByTagName("img").length==2){
2876 let hasNoble=table[i].children[0].getElementsByTagName("img")[1].src.includes("snob.png")
2877 if(hasNoble==true){
2878 $(table[i]).find('td').each(function(){
2879 $(this).css('background-color', colors.red);
2880 });
2881 }
2882 }
2883
2884 }
2885 }
2886 else{
2887 for(let i=0;i<table.length;i++){
2888 $(table[i]).find('td').each(function(){
2889 $(this).css('background-color', "");
2890 });
2891 }
2892 document.getElementById("btn_highlight").classList.remove("btn-confirm-yes")
2893 document.getElementById("btn_highlight").classList.add("btn-confirm-no")
2894 }
2895
2896
2897
2898}
2899if(window.location.href.includes("mode=incomings"))
2900 highLightIncomings();
2901
2902function toggleHighLight(){
2903
2904 if(localStorage.getItem(game_data.world+"highlight")!=null){
2905 let isHighLight=localStorage.getItem(game_data.world+"highlight")
2906 if(isHighLight=="true"){
2907 localStorage.setItem(game_data.world+"highlight","false")
2908 // UI.ErrorMessage("highlight off",500)
2909 highLightIncomings();
2910 }
2911 else{
2912 localStorage.setItem(game_data.world+"highlight","true")
2913 // UI.SuccessMessage("highlit on",500)
2914 highLightIncomings();
2915 }
2916
2917 }
2918 else{
2919 localStorage.setItem(game_data.world+"highlight","true")
2920 highLightIncomings();
2921 }
2922}
2923
2924
2925
2926
2927function eventGetTroops(){
2928 var units=game_data.units
2929
2930
2931 $(".load_troops").on("click",function(event){
2932 event.preventDefault()
2933 $(".load_troops").attr("disabled", true)
2934 let villageId=this.getAttribute("data-id")
2935 let nr_attacks=this.getAttribute("data-nr")
2936 let link_home_troops=game_data.link_base_pure + `map&ajax=map_info&source=${villageId}&target=${villageId}&`
2937 let link_coming_troops=window.location.href.split("village=")[0]+`village=${villageId}&screen=place&mode=call&target=${villageId}`
2938 let coord=this.innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
2939 let button=this
2940 console.log(link_home_troops)
2941 this.parentElement.classList.remove("selected")
2942
2943
2944
2945 let time_start=new Date().getTime();
2946 $.get(link_home_troops,function(response){
2947 console.log(response)
2948 let obj_troops={}
2949 for(let i=0;i<units.length-1;i++){
2950 obj_troops[units[i]]=parseInt(response.units[units[i]].count.home)+parseInt(response.units[units[i]].count.foreign)
2951 }
2952 let wallLevel,farmLevel,flagName,LoyaltyLevel
2953 wallLevel=response.buildings.wall
2954 farmLevel=response.buildings.farm
2955 LoyaltyLevel=response.mood
2956 console.log(response.flag)
2957 if(response.flag!=undefined)
2958 flagName =response.flag.short_desc
2959 else
2960 flagName="none"
2961 console.log(obj_troops)
2962 console.log("wallLevel: "+wallLevel)
2963 console.log("farmLevel: "+farmLevel)
2964 console.log("flagName: "+flagName)
2965 console.log("LoyaltyLevel: "+LoyaltyLevel)
2966
2967
2968
2969 let htmlDiv=`<div id="div_coming_troops" hidden></div>`
2970 $("#contentContainer").eq(0).prepend(htmlDiv)
2971 console.log(link_coming_troops)
2972
2973 $.get(link_coming_troops,function(data){
2974 document.getElementById("div_coming_troops").innerHTML=data
2975
2976 let obj_troops_coming={snob:0}
2977 let troops_coming=document.getElementById("div_coming_troops").querySelectorAll("#support_sum td")
2978 console.log(troops_coming)
2979 for(let i=0;i<troops_coming.length-1;i++){
2980 let name=troops_coming[i].getAttribute("data-unit")
2981 let value=parseInt(troops_coming[i].innerText)
2982 obj_troops_coming[name]=value
2983 }
2984 document.getElementById("div_coming_troops").remove()
2985
2986
2987
2988
2989 let html=`
2990 <div style="width:600px;background-color:${backgroundColor};cursor:move;width:50%;margin:10px auto">
2991
2992 <table class="" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor}">
2993 <tr>
2994 <td style="text-align:center; width:auto; background-color:${headerColor}">
2995 <p><center style="margin:10px"><font color="${titleColor}">coord </font></center></p>
2996 </td>
2997 <td style="text-align:center; width:auto; background-color:${headerColor}">
2998 <p><center style="margin:10px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/4ba99e83/graphic/unit/att.png"> </font></center></p>
2999 </td>
3000 <td style="text-align:center; width:auto; background-color:${headerColor}">
3001 <p><center style="margin:10px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/4ba99e83/graphic/flags/small/3.png"> </font></center></p>
3002 </td>
3003 <td style="text-align:center; width:auto; background-color:${headerColor}">
3004 <p><center style="margin:10px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/1d2499b/graphic/buildings/snob.png"> </font></center></p>
3005 </td>
3006 <td style="text-align:center; width:auto; background-color:${headerColor}">
3007 <p><center style="margin:10px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/1d2499b/graphic/buildings/wall.png"> </font></center></p>
3008 </td>
3009 <td style="text-align:center; width:auto; background-color:${headerColor}">
3010 <p><center style="margin:10px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/1d2499b/graphic/buildings/farm.png"> </font></center></p>
3011 </td>
3012 <td style="text-align:center; width:auto; background-color:${headerColor}">
3013 <p><center style="margin:10px"><font color="${titleColor}">troops </font></center></p>
3014 </td>
3015
3016 `;
3017 for(let i=0;i<units.length-1;i++){
3018 html+=`<td class="fm_unit" style="width:30px;text-align:center;width:auto; background-color:${headerColor}"><img src="https://dsen.innogamescdn.com/asset/1d2499b/graphic/unit/unit_${units[i]}.png"></td>`
3019 }
3020 html+=`
3021 <td style="text-align:center; width:auto; background-color:${headerColor}">
3022 <p><center style="margin:10px"><font color="${titleColor}">pop</font></center></p>
3023 </td>`
3024 html+=`</tr>
3025 <tr>`
3026
3027 html+=`
3028 <td rowspan="3" class="" style="width:30px;height:30px;text-align:center; background-color:${headerColor};color:white">${coord}</td>
3029 <td rowspan="3" class="" style="width:70px;height:30px;text-align:center; background-color:${headerColor};color:white">${nr_attacks}</td>
3030 <td rowspan="3" class="" style="width:70px;height:30px;text-align:center; background-color:${headerColor};color:white">${flagName}</td>
3031 <td rowspan="3" class="" style="width:30px;height:30px;text-align:center; background-color:${headerColor};color:white">${LoyaltyLevel}</td>
3032 <td rowspan="3" class="" style="width:30px;height:30px;text-align:center; background-color:${headerColor};color:white">${wallLevel}</td>
3033 <td rowspan="3" class="" style="width:30px;height:30px;text-align:center; background-color:${headerColor};color:white">${farmLevel}</td>
3034 <td style="text-align:center; width:auto; background-color:${headerColor}">
3035 <p><center style="margin:10px"><font color="${titleColor}">home</font></center></p>
3036 </td>
3037 `
3038 //home troops
3039 let total_pop=0;
3040 for(let i=0;i<units.length-1;i++){
3041 let value_troop=obj_troops[units[i]]
3042 let name_troop=units[i]
3043 if(name_troop!="spy" && name_troop!="light" && name_troop!="marcher" && name_troop!="ram"&& name_troop!="catapult" && name_troop!="axe"){
3044 total_pop+=value_troop*troopsPop[name_troop]
3045 }
3046 html+=`<td style="width:30px;height:30px;text-align:center; background-color:${headerColor};color:white">`+value_troop+"</td>"
3047 }
3048 html+=`<td style="width:60px;height:30px;text-align:center; background-color:${headerColor};color:white">`+total_pop+"</td>"
3049 html+=`</tr>
3050 <tr>
3051 <td style="text-align:center; width:auto; background-color:${headerColor}">
3052 <p><center style="margin:10px"><font color="${titleColor}">coming</font></center></p>
3053 </td>`
3054 //coming troops
3055 total_pop=0;
3056 for(let i=0;i<units.length-1;i++){
3057 let value_troop_coming=obj_troops_coming[units[i]]
3058 let name_troop=units[i]
3059 if(name_troop!="spy" && name_troop!="light" && name_troop!="marcher" && name_troop!="ram"&& name_troop!="catapult" && name_troop!="axe"){
3060 total_pop+=value_troop_coming*troopsPop[name_troop]
3061 }
3062 html+=`<td style="width:30px;height:30px;text-align:center; background-color:${headerColor};color:white">`+value_troop_coming+"</td>"
3063 }
3064 html+=`<td style="width:60px;height:30px;text-align:center; background-color:${headerColor};color:white">`+total_pop+"</td>"
3065
3066 html+=`</tr>
3067 <tr>
3068 <td style="text-align:center; width:auto; background-color:${headerColor}">
3069 <p><center style="margin:10px"><font color="${titleColor}">total </font></center></p>
3070 </td>`
3071 //total troops
3072 total_pop=0;
3073 for(let i=0;i<units.length-1;i++){
3074 let value_troop=obj_troops[units[i]]+obj_troops_coming[units[i]]
3075 let name_troop=units[i]
3076 if(name_troop!="spy" && name_troop!="light" && name_troop!="marcher" && name_troop!="ram"&& name_troop!="catapult" && name_troop!="axe"){
3077 total_pop+=value_troop*troopsPop[name_troop]
3078 }
3079 html+=`<td style="width:30px;height:30px;text-align:center; background-color:${headerColor};color:white">`+value_troop+"</td>"
3080 }
3081 html+=`<td style="width:60px;height:30px;text-align:center; background-color:${headerColor};color:white">`+total_pop+"</td>"
3082
3083 html+=`</tr></table></div>`
3084
3085 button.outerHTML=html
3086
3087
3088 let time_stop=new Date().getTime()
3089 console.log("load troops: "+(time_stop-time_start))
3090 $(".load_troops").attr("disabled", false)
3091
3092
3093
3094
3095
3096
3097 })
3098
3099
3100 })
3101
3102
3103 })
3104}
3105eventGetTroops();
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122