· 5 years ago · Nov 16, 2020, 01:56 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
11
12var file_reports='https://dl.dropboxusercontent.com/s/qdydvdssbrfns92/test.txt?dl=0';
13var file_incomigs='https://dl.dropboxusercontent.com/s/0acfdzwwhhrcup1/test2.txt?dl=0';
14var file_users='https://dl.dropboxusercontent.com/s/y7idzygkmwm68k8/test3.txt?dl=0';
15var filename_reports="test.txt";
16var filename_incomings="test2.txt";
17var filename_users="test3.txt";
18
19// var speedWorld=3;
20// var speedTroupes=0.67;
21
22var nobleSpeed=2100*1000/(speedWorld*speedTroupes)//ms
23var ramSpeed=1800*1000/(speedWorld*speedTroupes)//ms
24var swordSpeed=1320*1000/(speedWorld*speedTroupes)//ms
25var axeSpeed=1080*1000/(speedWorld*speedTroupes)//ms
26
27//formula ((base time/100)/speedWorld) * stable time factor //https://forum.tribalwars.net/index.php?threads/next-lvl-of-barracks-unit-production-speed.54638/
28var axeTime=Math.round( ((1320/100.0)/speedWorld) * 15.58823529 ) *1000//milisec
29var lhTime=Math.round( ((1800/100.0)/speedWorld) * 20.88235294 ) *1000//milisec
30var ramTime=Math.round( ((4800/100.0)/speedWorld) * 27.84313725 ) *1000//milisec
31
32
33
34
35//verify acces users
36let response=httpGet(file_users);
37var tribemates=response.split("\n")
38if(!tribemates.includes(game_data.player.name)){
39 UI.ErrorMessage("try later","slow")
40 throw new Error("you do not have acces");
41 // console.log("you do not have acces" )
42}
43if(game_data.locale!="en_DK" && game_data.world!="en113" )
44 throw new Error("it doesn't work");
45
46
47
48var engWord=[
49 "supports",
50 "today",
51 "tomorrow",
52 "on",
53 "attack"
54]
55var roWord=[
56 "sprijină",
57 "astăzi",
58 "mâine",
59 "data",
60 "atac"
61]
62var wordsTranslate=engWord
63
64
65
66 html = `
67 <div id="div_container" class="ui-widget-content" style="width:600px;background-color:${backgroundColor};cursor:move;z-index:50;">
68 <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>
69 <h2><center style="margin:10px"><u><font color="${titleColor}">Upload data</font></u></center></h2>
70 <table id="table_upload" class="" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor}">
71 <tr>
72 <td style="text-align:center; width:auto; background-color:${headerColor}">
73 <h2><center style="margin:10px"><u><font color="${titleColor}">reports</font></u></center></h2>
74 </td>
75 <td style="text-align:center; width:auto; background-color:${headerColor}">
76 <center style="margin:10px"><u><input class="btn" type="button" id="upload_reports" onclick="uploadReportsManual()" value="Upload manual"></center>
77 <center style="margin:10px"><u><input class="btn" type="button" id="upload_reports" onclick="uploadReports()" value="Upload auto"></center>
78
79 </td>
80
81 <td style="text-align:center; width:auto; background-color:${headerColor}">
82 <p><center style="margin:10px"><font color="${titleColor}" id="progress_reports">progress</font></center></p>
83 </td>
84 </tr>
85 <tr>
86 <td style="text-align:center; width:auto; background-color:${headerColor}">
87 <h2><center style="margin:10px"><u><font color="${titleColor}">incomings</font></u></center></h2>
88 </td>
89 <td style="text-align:center; width:auto; background-color:${headerColor}">
90 <center style="margin:10px"><u><input class="btn" type="button" id="upload_incomings" onclick="uploadIncomings()" value="Upload"></center>
91 </td>
92 <td style="text-align:center; width:auto; background-color:${headerColor}">
93 <p><center style="margin:10px" ><font color="${titleColor}" id="progress_incomings">progress</font></center></p>
94 </td>
95 </tr>
96 <tr>
97 <td style="text-align:center; width:auto; background-color:${headerColor}">
98 <h2><center style="margin:10px"><u><font color="${titleColor}">All info</font></u></center></h2>
99 </td>
100 <td style="text-align:center; width:auto; background-color:${headerColor}">
101 <center style="margin:10px"><u><input class="btn" type="button" onclick="uploadAll()" value="Upload all"></center>
102 </td>
103 <td style="text-align:center; width:auto; background-color:${headerColor}">
104 <p><center style="margin:10px" ><font color="${titleColor}" id="progress_all">progress</font></center></p>
105 </td>
106 </tr>
107 </table>
108 <h2><center style="margin:10px"><u><font color="${titleColor}">Search reports</font></u></center></h2>
109 <table id="table_upload" class="" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor}">
110 <tr>
111 <td style="text-align:center; width:auto; background-color:${headerColor}">
112 <center style="margin:10px"><u><input class="btn" type="button" onclick="loadReports()" value="Load reports"></center>
113 </td>
114 <td style="text-align:center; width:auto; background-color:${headerColor}">
115 <center style="margin:10px"><u><input style="text-align: center;" type="text" id="input_search" onclick="" placeholder="coord" ></center>
116 </td>
117 <td style="text-align:center; width:auto; background-color:${headerColor}">
118 <p><center style="margin:10px"><font color="${titleColor}" id="progress_search">status</font></center></p>
119 </td>
120 </tr>
121 </table>
122 <center style="margin:10px"><div id="report_view" style="background-color:#d2c09e"> report view <div><center>
123
124 </div>
125 `;
126 ////////////////////////////////////////add and remove window from page///////////////////////////////////////////
127 if(document.getElementById("incomings_table")==null){
128 $("#div_container").remove()
129 $("#contentContainer").eq(0).prepend(html);
130 $("#mobileContent").eq(0).prepend(html);
131
132 if(game_data.device=="desktop"){
133 $("#div_container").css("position","fixed");
134 $("#div_container").draggable();
135 }
136 }
137 function closeWindow(){
138 document.getElementById("div_container").remove();
139 list_href=[]
140 // window.location.reload();
141 }
142
143
144
145 function addWindow(){
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
155 var loadReportsOk=false;
156 $("#input_search").on("input",function(){
157 if(loadReportsOk==false)
158 UI.ErrorMessage("upload reports first","fast")
159 })
160 $("#input_search").mouseout(function(){
161 if(loadReportsOk==false)
162 $("#input_search").val("");
163 })
164
165 if(document.getElementById("incomings_table")!=null){
166 window.setInterval(function(){
167
168 var rows= $(".row_a,.row_b")
169 console.log("check incomings")
170 for(let i=0;i<rows.length;i++)
171 {
172 let currentHour=rows[i].children[rows[i].children.length-1].innerText.split(":")
173 if(parseInt(currentHour[0])==0 && parseInt(currentHour[1])==0 && parseInt(currentHour[2])<20){
174 rows[i].remove();
175 }
176 // else{
177 // break;
178 // }
179 }
180 },10000)
181 }
182
183
184 function uploadAll(){
185 uploadReports(uploadIncomings);
186 }
187
188
189 /////////////////////////////////////////////////get all reports info//////////////////////////////////////////////////////////////////
190 function uploadReports(callback){
191 let list_href=[]
192 document.getElementById("progress_reports").innerText="get links..";
193
194 let nameHistoryReports=game_data.world +"HistoryReports"
195 var map_idReports=new Map();
196 var current_page=window.location.href;
197 if(localStorage.getItem(nameHistoryReports)==null){
198 localStorage.setItem(nameHistoryReports,JSON.stringify(Array.from(new Map().entries())))
199 }
200 else{
201 map_idReports=new Map(JSON.parse(localStorage.getItem(nameHistoryReports)));
202 Array.from(map_idReports.keys()).forEach(el=>{
203 let currentDate=new Date();
204 let reportDate=new Date(map_idReports.get(el))
205 if(currentDate.getTime()- reportDate.getTime() > 20*24*3600*1000){
206 console.log("remove: "+map_idReports.get(el))
207 map_idReports.delete(el)
208 }
209 })
210
211 }
212
213 $(document).on('click','.autoHideBox',function(){
214 UI.SuccessMessage("stop",2000)
215 list_href=[]
216 })
217
218
219 getPromiseListHref=getLinks(true,map_idReports);//only current folder
220 getPromiseListHref.then( result=>{
221 console.log(result)
222 list_href=result;
223 list_href=list_href.reverse();
224 console.log(list_href)
225 var list_data_reports=[]
226 var nr_reports=0;
227 var nr_reports_total=list_href.length
228 addWindow();
229 document.getElementById("progress_reports").innerText=nr_reports+"/"+nr_reports_total+" reports";
230 // UI.InfoMessage(nr_reports+"/"+nr_reports_total+" reports")
231 var current_url
232 function ajaxRequest (urls) {
233 var time= 0
234 if(urls.length>0)
235 current_url=urls.pop().href;
236 else
237 current_url="stop"
238 console.log("in functie in plm "+urls.length)
239 if (urls.length >= 0 && current_url!= "stop") {
240 var start_ajax=new Date()
241 $.ajax({
242 method: 'GET',
243 url: current_url,
244 })
245 .done(function (result) {
246 document.body.innerHTML= result;
247 result=null
248 // addWindow();
249 let list=getDataReport(tribemates);
250 console.log(list)
251 if(list==null ){
252 console.log("recaptcha, upload again")
253 UI.ErrorMessage("recaptcha, upload again","slow")
254 addWindow();
255 document.getElementById("progress_reports").innerText="recaptcha";
256 list_href=[]
257
258 }
259 else{
260 console.log("reports info "+list.length)
261 for(let j=0;j<list.length;j++){
262 list_data_reports.push({"coord":list[j].coord,"reportInfo":list[j].reportInfo});
263 }
264 // document.getElementById("progress_reports").innerText=nr_reports+"/"+nr_reports_total+" reports";
265 UI.SuccessMessage(nr_reports+"/"+nr_reports_total+" reports")
266
267 nr_reports++;
268 let idReport= parseInt(current_url.match(/view=(\d+)/)[1]);
269 let currentDate=new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate();
270 if(document.getElementsByClassName("unit-item unit-item-axe").length>0){
271 var time_report=document.getElementsByClassName("vis")[3].firstElementChild.children[1].children[1].innerText;
272 map_idReports.set(idReport,time_report)
273 }
274 else{
275 map_idReports.set(idReport,currentDate)
276 }
277 }
278 var stop_ajax=new Date();
279 var dif_time=stop_ajax.getTime()-start_ajax.getTime();
280 console.log("dif_time "+dif_time+" wait "+(200-dif_time))
281 window.setTimeout(function(){
282 ajaxRequest(list_href);
283 },200-dif_time)
284 });
285
286 }
287 else
288 {
289 ////////////////////////////////////extract data from dropbox/////////////////////////////////////////
290 console.log("inainte de a extrage date din dropbox")
291 $.get(file_reports, function (data) {
292 map_dropbox=new Map( JSON.parse( lzw_decode(data) ));
293
294 console.log("map_dropbox")
295 console.log(map_dropbox);
296 console.log("list_data_reports")
297 console.log(list_data_reports);
298
299
300 document.body.innerHTML= httpGet(current_page);
301 addWindow();
302 let nr_update=0;
303 let nr_write=0;
304 list_data_reports.forEach(function(el){
305 if(map_dropbox.has(el.coord)){//update el[0]=key
306 if(el.reportInfo.typeAttacker=="new_off"){
307 console.log("new_off, don't do anything")
308 }else{
309 console.log("coord exists in dropbox already")
310 let time_prev=new Date(map_dropbox.get(el.coord).time_report);
311 let time_current=new Date(el.reportInfo.time_report);
312 console.log(time_current-time_prev)
313 if(time_current-time_prev<48*3600*1000 && (el.reportInfo.typeAttacker=="def" )){//48 hours
314 console.log("a fost def_cat")
315 map_dropbox.set(el.coord,el.reportInfo)
316 nr_update++;
317 }
318 else if(time_current-time_prev>0 ){
319 console.log("update coord: "+el.coord+" in dropbox")
320 map_dropbox.set(el.coord,el.reportInfo)
321 nr_update++;
322 }
323
324 }
325 }
326 else{//write
327 console.log("write coord in dropbox")
328 map_dropbox.set(el.coord,el.reportInfo)
329 nr_write++;
330 }
331 })
332 UI.SuccessMessage("compressing database, wait few seconds",2000)
333
334 window.setTimeout(function(){
335 var data=lzw_encode(JSON.stringify(Array.from(map_dropbox.entries())))
336 console.log(map_dropbox)
337 console.log("hai ba")
338 uploadFile(data,filename_reports,dropboxToken)
339 localStorage.setItem(nameHistoryReports,JSON.stringify(Array.from(map_idReports.entries())))
340 document.getElementById("progress_reports").innerText="done";
341 UI.SuccessMessage("upload reports done\n update: "+nr_update+" \nwrite: "+nr_write,4000)
342 },400)
343
344 }).done(function(){
345 if(typeof(callback)==="function" && current_url!="stop")
346 callback();
347
348 }).fail(function(){
349 // alert("error upload")
350 UI.ErrorMessage("upload again \n try after few minutes")
351
352 })
353
354 }
355 }
356 ajaxRequest(list_href);
357 }).catch(result=>{
358 console.log(result)
359 })
360 }
361
362 /////////////////////////////////////////////////get all reports info MANUAL//////////////////////////////////////////////////////////////////
363 function uploadReportsManual(){
364 let list_href=[]
365 let types=["off","new_off","def","def_cat",'def_spy',"spy","def??","none"]
366 document.getElementById("progress_reports").innerText="get links..";
367
368 let nameHistoryReports=game_data.world +"HistoryReports"
369 var map_idReports=new Map();
370 var current_page=window.location.href;
371 if(localStorage.getItem(nameHistoryReports)==null){
372 localStorage.setItem(nameHistoryReports,JSON.stringify(Array.from(new Map().entries())))
373 }
374 else{
375 map_idReports=new Map(JSON.parse(localStorage.getItem(nameHistoryReports)));
376 Array.from(map_idReports.keys()).forEach(el=>{
377 let currentDate=new Date();
378 let reportDate=new Date(map_idReports.get(el))
379 if(currentDate.getTime()- reportDate.getTime() > 20*24*3600*1000){
380 console.log("remove: "+map_idReports.get(el))
381 map_idReports.delete(el)
382 }
383 })
384
385 }
386
387 $(document).on('click','.autoHideBox',function(){
388 UI.SuccessMessage("stop",2000)
389 list_href=[]
390 })
391
392
393 getPromiseListHref=getLinks(true,map_idReports);//only current folder
394 getPromiseListHref.then( result=>{
395 console.log(result)
396 list_href=result;
397 list_href=list_href.reverse();
398 console.log(list_href)
399 var list_data_reports=[]
400 var nr_reports=0;
401 var nr_reports_total=list_href.length
402 addWindow();
403 document.getElementById("progress_reports").innerText=nr_reports+"/"+nr_reports_total+" reports";
404 // UI.InfoMessage(nr_reports+"/"+nr_reports_total+" reports")
405 var current_url
406 function ajaxRequest (urls) {
407 var time= 0
408 if(urls.length>0)
409 current_url=urls.pop().href;
410 else
411 current_url="stop"
412 console.log("in functie in plm "+urls.length)
413 if (urls.length >= 0 && current_url!= "stop") {
414 var start_ajax=new Date()
415 $.ajax({
416 method: 'GET',
417 url: current_url,
418 })
419 .done(function (result) {
420 document.body.innerHTML= result;
421 result=null
422 // addWindow();
423 let list=getDataReport(tribemates);
424 console.log(list)
425 if(list==null ){
426 console.log("recaptcha, upload again")
427 UI.ErrorMessage("recaptcha, upload again","slow")
428 addWindow();
429 document.getElementById("progress_reports").innerText="recaptcha";
430 list_href=[]
431
432 }
433 else{
434 console.log("reports info "+list.length)
435 for(let j=0;j<list.length;j++){
436
437 if(document.getElementById("select_type_attacker")==null && !tribemates.includes(list[j].reportInfo.nameAttacker)){
438 let type=(list[j].reportInfo.typeAttacker!="?")?list[j].reportInfo.typeAttacker:"none"
439
440 console.log(type)
441 let htmlSelect='<select id="select_type_attacker" style="width: 100%">';
442 for(let k=types.length-1;k>=0;k--){
443 htmlSelect+='<option value="'+types[k]+'">'+types[k]+'</option>'
444 }
445 htmlSelect+='</select>';
446 $("#attack_info_att").append(htmlSelect)
447 document.getElementById("select_type_attacker").value=type
448 }
449 if(document.getElementById("select_type_defender")==null && !tribemates.includes(list[j].reportInfo.nameDefender)){
450 let type=(list[j].reportInfo.typeDefender!="?")?list[j].reportInfo.typeDefender:"none"
451 console.log(type)
452 let htmlSelect='<select id="select_type_defender" style="width: 100%">';
453 for(let k=types.length-1;k>=0;k--){
454 htmlSelect+='<option value="'+types[k]+'">'+types[k]+'</option>'
455 }
456 htmlSelect+='</select>';
457 $("#attack_info_def").append(htmlSelect)
458 document.getElementById("select_type_defender").value=type
459
460 }
461
462 }
463 // document.getElementById("progress_reports").innerText=nr_reports+"/"+nr_reports_total+" reports";
464 UI.SuccessMessage(nr_reports+"/"+nr_reports_total+" reports")
465
466 nr_reports++;
467 let idReport= parseInt(current_url.match(/view=(\d+)/)[1]);
468 let currentDate=new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate();
469 if(document.getElementsByClassName("unit-item unit-item-axe").length>0){
470 var time_report=document.getElementsByClassName("vis")[3].firstElementChild.children[1].children[1].innerText;
471 map_idReports.set(idReport,time_report)
472 }
473 else{
474 map_idReports.set(idReport,currentDate)
475 }
476 }
477 var stop_ajax=new Date();
478 var dif_time=stop_ajax.getTime()-start_ajax.getTime();
479 console.log("dif_time "+dif_time+" wait "+(200-dif_time))
480
481 window.onkeyup = function(e) {
482 console.log(e.which)
483 if(e.which==13 && current_url!= "stop"){
484 console.log("next")
485 window.onkeyup = function(e){}
486
487 for(let j=0;j<list.length;j++){
488 if(document.getElementById("select_type_attacker")!=null){
489 let type=document.getElementById("select_type_attacker").value
490 if(type!="none"){
491 list[j].reportInfo.typeAttacker=type
492 list_data_reports.push({"coord":list[j].coord,"reportInfo":list[j].reportInfo});
493 }
494 }
495 if(document.getElementById("select_type_defender")!=null){
496 let type=document.getElementById("select_type_defender").value
497 if(type!="none"){
498 list[j].reportInfo.typeDefender=type
499 list_data_reports.push({"coord":list[j].coord,"reportInfo":list[j].reportInfo});
500 }
501 }
502
503 }
504 console.log("new list")
505 console.log(list)
506 console.log("big list")
507 console.log(list_data_reports)
508
509 window.setTimeout(function(){
510 ajaxRequest(list_href);
511 },200-dif_time)
512 }
513 e.preventDefault()
514 }
515 });
516
517 }
518 else
519 {
520 ////////////////////////////////////extract data from dropbox/////////////////////////////////////////
521 console.log("inainte de a extrage date din dropbox")
522 $.get(file_reports, function (data) {
523 map_dropbox=new Map( JSON.parse( lzw_decode(data)));
524
525 console.log("map_dropbox")
526 console.log(map_dropbox);
527 console.log("list_data_reports")
528 console.log(list_data_reports);
529
530
531 document.body.innerHTML= httpGet(current_page);
532 addWindow();
533 let nr_update=0;
534 let nr_write=0;
535 list_data_reports.forEach(function(el){
536 if(map_dropbox.has(el.coord)){//update el[0]=key
537 if(el.reportInfo.typeAttacker=="new_off"){
538 console.log("new_off, don't do anything")
539 }else{
540 console.log("coord exists in dropbox already")
541 let time_prev=new Date(map_dropbox.get(el.coord).time_report);
542 let time_current=new Date(el.reportInfo.time_report);
543 console.log(time_current-time_prev)
544 if(time_current-time_prev<48*3600*1000 && (el.reportInfo.typeAttacker=="def" )){//48 hours
545 console.log("a fost def_cat")
546 map_dropbox.set(el.coord,el.reportInfo)
547 nr_update++;
548 }
549 else if(time_current-time_prev>0 ){
550 console.log("update coord: "+el.coord+" in dropbox")
551 map_dropbox.set(el.coord,el.reportInfo)
552 nr_update++;
553 }
554
555 }
556 }
557 else{//write
558 console.log("write coord in dropbox")
559 map_dropbox.set(el.coord,el.reportInfo)
560 nr_write++;
561 }
562 })
563 UI.SuccessMessage("compressing database, wait few seconds")
564 window.setTimeout(function(){
565 var data=lzw_encode(JSON.stringify(Array.from(map_dropbox.entries())))
566 console.log(map_dropbox)
567 console.log("hai ba")
568 uploadFile(data,filename_reports,dropboxToken)
569 localStorage.setItem(nameHistoryReports,JSON.stringify(Array.from(map_idReports.entries())))
570 document.getElementById("progress_reports").innerText="done";
571 UI.SuccessMessage("upload reports done\n update: "+nr_update+" \nwrite: "+nr_write,4000)
572 },400)
573
574 }).fail(function(){
575 // alert("error upload")
576 UI.ErrorMessage("upload again \n try after few minutes")
577
578 })
579
580 }
581 }
582 ajaxRequest(list_href);
583 }).catch(result=>{
584 console.log(result)
585 })
586 }
587 ///////////////////////////////////////////////////////////////////get all links////////////////////////////////////////////////////////////////
588 function getLinks(all,map_idReports){
589 // var currentPage=document.body.innerHTML;
590 return new Promise((resolve,reject)=>{
591 let list_pages=[]
592 let current_href=window.location.href;
593 if(current_href.includes("screen=report"))
594 all=false;
595 if(all){// all pages from all folders
596 let index=window.location.href.lastIndexOf("game.php")
597 let href= window.location.href.substr(0,index)+"game.php?"+"screen=report&mode=all&group_id=-1";
598 if(current_href.includes("t=")){
599 href+="&t="+current_href.split("t=")[1].split("&")[0];
600 }
601 list_pages.push(href)
602 document.body.innerHTML=httpGet(href)
603 }
604 if(document.getElementsByClassName("vis")[1].getElementsByTagName("select").length>0){
605 Array.from(document.getElementsByClassName("vis")[1].getElementsByTagName("select")[0]).forEach(function(item){
606 list_pages.push(item.value)
607 })
608 }
609 else if(document.getElementsByClassName("paged-nav-item").length>0){//all pages from the current folder
610 if(all==false){
611 let current_link=window.location.href;
612 list_pages.push(current_link);
613 }
614 Array.from(document.getElementsByClassName("paged-nav-item")).forEach(function(item){
615 list_pages.push(item.href);
616 })
617 }
618 else{//only one page from the current folder
619 let current_link=window.location.href;
620 list_pages.push(current_link);
621 }
622 console.log("list pages")
623 console.log(list_pages)
624
625 let list_href=[];
626 var indexIncoming=1;
627 var url_length=list_pages.length
628 function ajaxRequest (urls) {
629 let current_url
630
631 if(urls.length>0){
632 current_url=urls.pop()
633 }
634 else{
635 current_url="stop"
636 }
637 console.log("in functie in plm "+urls.length)
638 // console.log(current_url)
639 var start_ajax=new Date();
640 if (urls.length >= 0 && current_url!="stop") {
641 $.ajax({
642 url: current_url,
643 method: 'get',
644 success: (data) => {
645 document.body.innerHTML=data
646 let table_report= document.getElementById("report_list").firstElementChild.children;
647 let year=document.getElementById("serverDate").innerText.split("/")[2];
648 for(let i=1;i<table_report.length-1;i++){
649 let month_day=table_report[i].children[2].innerText;
650 let date_report=new Date(year+" "+month_day)
651 let current_date=new Date();
652 if(current_date-date_report<19*24*3600*1000){//old
653
654 let img_icon=table_report[i].children[1].children[0].children.length;
655 if(img_icon>0){//wordsTranslate[0]=supports ///// || table_report[i].innerText.includes(wordsTranslate[0])
656 let obj={
657 id:table_report[i].getElementsByTagName("a")[0].getAttribute("data-id"),
658 href:table_report[i].getElementsByTagName("a")[0].href
659 }
660 if(!map_idReports.has(parseInt(obj.id)))
661 list_href.push(obj)
662 }
663 }
664 }
665
666
667 UI.InfoMessage("page "+indexIncoming+"/"+url_length)
668 indexIncoming++;
669 var stop_ajax=new Date();
670 var dif_time=stop_ajax.getTime()-start_ajax.getTime();
671 window.setTimeout(function(){
672 ajaxRequest (list_pages)
673 },200-dif_time)
674 }
675 })
676
677 }
678 else
679 {
680 UI.SuccessMessage("done",2000)
681 resolve(list_href)
682 }
683 }
684 if(list_pages.length>0)
685 ajaxRequest(list_pages);
686 else
687 reject("error??")
688
689 })
690
691 }
692
693 ////////////////////////////////////////////////////////////get data from report////////////////////////////////////////////////////////////////////
694
695 function getDataReport(tribemates){
696 var mapObject={};
697 var listObject=[];
698
699 // tribemates=[]
700 var reportInfo={};
701 // try{
702 if($("#attack_info_att").length>0){
703 var attackInfo=$("#attack_info_att");
704 if(attackInfo.text().includes("deleted") || attackInfo.text().includes("---")){
705 console.log("error upload")
706 return 0;
707 }
708 var defenseInfo = $("#attack_info_def");
709 if(defenseInfo.text().includes("deleted") || defenseInfo.text().includes("---")){
710 console.log("error upload")
711 return 0;
712 }
713
714 var attackingPlayer = attackInfo.find('a[href*=info_player]');
715 var defendingPlayer = defenseInfo.find('a[href*=info_player]');
716 var attackingPlayerId=attackingPlayer.prop('href').match(/id=(\w+)/)[1];
717 var defendingPlayerId=defendingPlayer.prop('href').match(/id=(\w+)/)[1];
718 reportInfo.attackingPlayerId=attackingPlayerId;
719 reportInfo.defendingPlayerId=defendingPlayerId;
720 }
721 ///////////////////////////////////////////////////////////////////////////
722
723
724 if(document.getElementsByClassName("unit-item unit-item-axe").length>1)
725 {
726 var time_report=document.getElementsByClassName("vis")[3].firstElementChild.children[1].children[1].innerText;
727 // if(new Date()-new Date(time_report)>14*24*3600*1000)//report too old
728 // return listObject;
729
730 reportInfo.time_report=time_report
731 var report=document.getElementsByClassName("vis")[3].innerHTML;
732 var index=report.indexOf('<div class="no-preview">');
733 report=report.substring(0,index);
734 // report=lzw_encode(report);
735 // reportInfo.report=report;
736
737 ///////////////////////////defender date////////////////////
738 var nameAttacker=document.getElementById("attack_info_att").children[0].children[0].children[1].innerText;
739 var coordAttacker=document.getElementsByClassName("village_anchor")[0].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
740 var nameDefender=document.getElementById("attack_info_def").children[0].children[0].children[1].innerText;
741 var coordDefender=document.getElementsByClassName("village_anchor")[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
742 reportInfo.nameAttacker=nameAttacker;
743 reportInfo.coordAttacker=coordAttacker;
744 reportInfo.nameDefender=nameDefender;
745 reportInfo.coordDefender=coordDefender;
746
747 var axe_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-axe")[0].innerText);
748 var axe_atac_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-axe")[1].innerText);
749 var light_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-light")[0].innerText)*4;
750 var light_atac_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-light")[1].innerText)*4;
751 var ram_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-ram")[0].innerText)*5;
752 var ram_atac_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-ram")[1].innerText)*5;
753 var cat_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-catapult")[0].innerText)*8;
754 var cat_atac_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-catapult")[1].innerText)*8;
755 var noble=parseInt(document.getElementsByClassName("unit-item unit-item-snob")[0].innerText)*100;
756
757 var spear_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-spear")[0].innerText);
758 var sword_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-sword")[0].innerText);
759 if(document.getElementsByClassName("unit-item unit-item-archer").length>0)
760 var archer_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-archer")[0].innerText);
761 else
762 var archer_atac_total=0;
763 var heavy_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-heavy")[0].innerText)*6;
764 var spy_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-spy")[0].innerText)*2;
765 var spy_atac_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-spy")[1].innerText)*2;
766
767 var typeAttacker="?";
768 var nrTroupesAttacker=0;
769 var nrTroupesAttackerTotal=0;
770 var time_return=0;
771
772
773 if(axe_atac_total+light_atac_total+ram_atac_total >=2500 && axe_atac_total>=2500)
774 {
775 typeAttacker="off";
776 nrTroupesAttacker=(axe_atac_total-axe_atac_pierderi)+(light_atac_total-light_atac_pierderi) + (ram_atac_total-ram_atac_pierderi);
777 console.log("ianinte")
778 if(ram_atac_total>0 && noble==0 && axe_atac_total>=2000){
779 console.log("aici")
780 nrTroupesAttackerTotal=axe_atac_total+light_atac_total+ram_atac_total
781 let time_attack=ramSpeed*calcDistance(coordAttacker,coordDefender)
782 time_return=new Date(time_report).getTime()+time_attack;
783 time_return=new Date(time_return)
784 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
785 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
786
787 }else if(axe_atac_total>=2000 && noble==0 ){
788 nrTroupesAttackerTotal=axe_atac_total+light_atac_total
789 time_attack=axeSpeed*calcDistance(coordAttacker,coordDefender)
790 time_return=new Date(time_report).getTime()+time_attack;
791 time_return=new Date(time_return)
792 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
793 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
794
795 }else if(axe_atac_total>=2000 && noble>0){
796 nrTroupesAttackerTotal=axe_atac_total+light_atac_total+ram_atac_total
797 time_attack=axeSpeed*calcDistance(coordAttacker,coordDefender)
798 time_return=new Date(time_report).getTime()+time_attack;
799 time_return=new Date(time_return)
800 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
801 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
802 }
803 }
804 else if(spy_atac_total>10000){
805 typeAttacker="spy";
806 nrTroupesAttacker=spy_atac_total-spy_atac_pierderi;
807 }
808 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)
809 {
810 typeAttacker="new_off";
811 }
812 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){
813 typeAttacker="def";
814 }
815 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)
816 typeAttacker="def_spy";
817
818 if((cat_atac_total>=50*8 && typeAttacker=="def") || (cat_atac_total>=50*8 && axe_atac_total+light_atac_total+ram_atac_total<20)){
819 typeAttacker="def_cat";
820 nrTroupesAttacker=cat_atac_total-cat_atac_pierderi;
821 if(noble==0){
822 nrTroupesAttackerTotal=heavy_atac_total+cat_atac_total
823 time_attack=ramSpeed*calcDistance(coordAttacker,coordDefender)
824 time_return=new Date(time_report).getTime()+time_attack;
825 time_return=new Date(time_return)
826 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
827 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
828 }
829 }
830
831 reportInfo.time_return=time_return
832 reportInfo.nrTroupesAttackerTotal=nrTroupesAttackerTotal
833 reportInfo.typeAttacker=typeAttacker;
834 reportInfo.nrTroupesAttacker=nrTroupesAttacker;
835
836 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()) } })
837 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()) } })
838
839
840 /////////////////////////////////////////////////defender date/////////////////////
841 var nrTroupesDefender=0;
842 var typeDefender="?";
843 if(document.getElementsByClassName("unit-item unit-item-axe").length>2){
844
845
846 var axe_aparare_total=parseInt(document.getElementsByClassName("unit-item unit-item-axe")[2].innerText);
847 var axe_aparare_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-axe")[3].innerText);
848 var light_aparare_total=parseInt(document.getElementsByClassName("unit-item unit-item-light")[2].innerText)*4;
849 var light_aparare_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-light")[3].innerText)*4;
850 var ram_aparare_total=parseInt(document.getElementsByClassName("unit-item unit-item-ram")[2].innerText)*5;
851 var ram_aparare_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-ram")[3].innerText)*5;
852 var spear_aparare_total=parseInt(document.getElementsByClassName("unit-item unit-item-spear")[2].innerText);
853 var sword_aparare_total=parseInt(document.getElementsByClassName("unit-item unit-item-sword")[2].innerText);
854 if(document.getElementsByClassName("unit-item unit-item-archer")>0)
855 var archer_aparare_total=parseInt(document.getElementsByClassName("unit-item unit-item-archer")[2].innerText);
856 else
857 var archer_aparare_total=0
858 var heavy_aparare_total=parseInt(document.getElementsByClassName("unit-item unit-item-heavy")[2].innerText)*6;
859
860
861 nrTroupesDefender=(axe_aparare_total-axe_aparare_pierderi)+(light_aparare_total-light_aparare_pierderi) + (ram_aparare_total-ram_aparare_pierderi);
862 if(axe_aparare_total+light_aparare_total+ram_aparare_total >=2500 && axe_aparare_total>=2500){
863 typeDefender="off";
864 }
865
866 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()) } })
867 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()) } })
868
869 }
870
871 if(document.getElementsByClassName("unit-item unit-item-axe").length>4){
872 var axe_aparare_spy=parseInt(document.getElementsByClassName("unit-item unit-item-axe")[4].innerText);
873 var light_aparare_spy=parseInt(document.getElementsByClassName("unit-item unit-item-light")[4].innerText)*4;
874 var ram_aparare_spy=parseInt(document.getElementsByClassName("unit-item unit-item-ram")[4].innerText)*5;
875 nrTroupesDefender+=axe_aparare_spy+(light_aparare_spy) + (ram_aparare_spy);
876
877 if(nrTroupesDefender>=2500 && axe_aparare_spy>=2500)
878 typeDefender="off";
879
880
881
882 var spear_aparare_spy=parseInt(document.getElementsByClassName("unit-item unit-item-spear")[4].innerText);
883 var sword_aparare_spy=parseInt(document.getElementsByClassName("unit-item unit-item-sword")[4].innerText);
884 if(document.getElementsByClassName("unit-item unit-item-archer").length>0)
885 var archer_aparare_spy=parseInt(document.getElementsByClassName("unit-item unit-item-archer")[4].innerText);
886 else
887 var archer_aparare_spy=0
888
889 var heavy_aparare_spy=parseInt(document.getElementsByClassName("unit-item unit-item-heavy")[4].innerText)*6;
890 var trupe_aparare_total=spear_aparare_total+sword_aparare_total+archer_aparare_total+heavy_aparare_total;
891 var total_aparare_spy=spear_aparare_spy+sword_aparare_spy+archer_aparare_spy+heavy_aparare_spy;
892
893 if(total_aparare_spy>1000){
894 typeDefender="def";
895 nrTroupesDefender=total_aparare_spy;
896 }
897 else if(axe_aparare_spy+light_aparare_spy <10 && axe_aparare_total+light_aparare_total<100 && trupe_aparare_total>5000 && total_aparare_spy<=1000){
898 typeDefender="def??";
899 }
900
901
902 let travelingTroopsContainer = $(document).find('#attack_spy_away');
903 if (travelingTroopsContainer.length) {
904 reportInfo.travelingTroops = {};
905
906 travelingTroopsContainer.find('.unit-item').each((i, el) => {
907 let $el = $(el);
908 let cls = $el.prop('class');
909 let unitType = cls.match(/unit\-item\-(\w+)/)[1];
910 reportInfo.travelingTroops[unitType] = parseInt($el.text().trim());
911 });
912 }
913
914
915 }
916 reportInfo.typeDefender=typeDefender;
917 reportInfo.nrTroupesDefender=nrTroupesDefender;
918
919
920
921 if(!tribemates.includes(nameAttacker)){//!reportInfo.typeAttacker.includes("?")
922 // console.log("attacker")
923 mapObject.coord=coordAttacker;
924 mapObject.reportInfo=reportInfo;
925 listObject.push(mapObject);
926 mapObject={};
927 }
928 if(!tribemates.includes(nameDefender)){
929 // console.log("defender")
930 mapObject.coord=coordDefender;
931 mapObject.reportInfo=reportInfo;
932 listObject.push(mapObject);
933 }
934 }
935 else if(document.getElementsByClassName("unit-item unit-item-axe").length==1)
936 {
937 var typeSupporter="?";
938 var nrTroupesSupporter=0;
939 let time_report=document.getElementsByClassName("vis")[3].firstElementChild.children[1].children[1].innerText;
940 if(new Date()-new Date(time_report)>14*3600*1000)//report too old
941 return listObject;
942 var report=document.getElementsByClassName("vis")[3].innerHTML;
943 // report=lzw_encode(report);
944 reportInfo.time_report=time_report;
945 // reportInfo.report=report;
946
947 var text=document.getElementsByClassName("vis")[3].innerText.split("\n");
948 var nameSupporter=text[3].split(":")[1].trim();
949 var coordSupporter=text[4].split(":")[1].trim().match(/[0-9]{3}\|[0-9]{3}/)[0];
950 var supporterPlayerId=document.getElementsByClassName("vis")[3].getElementsByTagName("a")[1].href.split("id=")[1]
951 // var supporterPlayerId=document.getElementsByClassName("village_anchor contexted")[0].getAttribute("data-player")
952
953 reportInfo.nameSupporter=nameSupporter;
954 reportInfo.coordSupporter=coordSupporter;
955 reportInfo.supporterPlayerId=supporterPlayerId;
956
957
958 var axe_total=parseInt(document.getElementsByClassName("unit-item unit-item-axe")[0].innerText);
959 var light_total=parseInt(document.getElementsByClassName("unit-item unit-item-light")[0].innerText)*4;
960 var ram_total=parseInt(document.getElementsByClassName("unit-item unit-item-ram")[0].innerText)*5;
961
962 var spear_total=parseInt(document.getElementsByClassName("unit-item unit-item-spear")[0].innerText);
963 var sword_total=parseInt(document.getElementsByClassName("unit-item unit-item-sword")[0].innerText);
964 var archer_total=parseInt(document.getElementsByClassName("unit-item unit-item-archer")[0].innerText);
965 var heavy_total=parseInt(document.getElementsByClassName("unit-item unit-item-heavy")[0].innerText)*6;
966
967 var total_atac=axe_total+light_total+ram_total;
968 var total_aparare=spear_total+sword_total+archer_total+heavy_total;
969
970 if(total_atac>total_aparare && total_atac>=200){
971 typeSupporter="off";
972 nrTroupesSupporter=total_atac;
973 }
974 else if(total_aparare>total_atac && total_aparare>=200){
975 typeSupporter="def";
976 nrTroupesSupporter=total_aparare;
977 }
978 reportInfo.typeSupporter=typeSupporter;
979 reportInfo.nrTroupesSupporter=nrTroupesSupporter;
980
981 if(!tribemates.includes(nameSupporter) && !reportInfo.typeSupporter.includes("?")){
982 // console.log("supporter")
983 mapObject.coord=coordSupporter;
984 mapObject.reportInfo=reportInfo;
985 listObject.push(mapObject);
986 }
987 }
988 else if(document.getElementsByClassName("unit-item unit-item-axe").length==0 || document.getElementsByClassName("g-recaptcha").length>0
989 ||document.getElementsByClassName("unit-item unit-item-axe")==undefined || checkContainsCaptcha(document)==true){//recaptcha
990 console.log("recapthca")
991 return null;
992 }
993
994 return listObject;
995 // }
996 // // catch(e){
997 // console.log("erorr in upload")
998 // return 0;
999 // }
1000
1001 }
1002
1003 function checkContainsCaptcha(docOrHtml) {
1004 var foundCaptcha = false;
1005 if (typeof docOrHtml == 'string') {
1006 foundCaptcha = !!docOrHtml.match(/data\-bot\-protect=/);
1007 } else {
1008 let $doc = $(docOrHtml);
1009 let $body = $doc.find('#ds_body');
1010 foundCaptcha = $body.length && !!$body.data('bot-protect')
1011 }
1012
1013 if (foundCaptcha) console.log('Found captcha!');
1014 return foundCaptcha;
1015 }
1016
1017 function calcDistance(coord1,coord2)
1018 {
1019 let x1=parseInt(coord1.split("|")[0])
1020 let y1=parseInt(coord1.split("|")[1])
1021 let x2=parseInt(coord2.split("|")[0])
1022 let y2=parseInt(coord2.split("|")[1])
1023
1024 return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
1025 }
1026
1027 ////////////////////////////////////////////////data compression////////////////////////////////////////////////////////////////////////////
1028 function lzw_encode (s) {
1029 if (!s) return s;
1030 var dict = new Map(); // Use a Map!
1031 var data = (s + "").split("");
1032 var out = [];
1033 var currChar;
1034 var phrase = data[0];
1035 var code = 256;
1036 for (var i = 1; i < data.length; i++) {
1037 currChar = data[i];
1038 if (dict.has(phrase + currChar)) {
1039 phrase += currChar;
1040 } else {
1041 out.push (phrase.length > 1 ? dict.get(phrase) : phrase.codePointAt(0));
1042 dict.set(phrase + currChar, code);
1043 code++;
1044 if (code === 0xd800) { code = 0xe000; }
1045 phrase = currChar;
1046 }
1047 }
1048 out.push (phrase.length > 1 ? dict.get(phrase) : phrase.codePointAt(0));
1049 for (var i = 0; i < out.length; i++) {
1050 out[i] = String.fromCodePoint(out[i]);
1051 }
1052 //console.log ("LZW MAP SIZE", dict.size, out.slice (-50), out.length, out.join("").length);
1053 return out.join("");
1054 }
1055 ////////////////////////////////////////////////data decompression////////////////////////////////////////////////////////////////////////////
1056 function lzw_decode (s) {
1057 var dict = new Map(); // Use a Map!
1058 var data = Array.from(s + "");
1059 //var data = (s + "").split("");
1060 var currChar = data[0];
1061 var oldPhrase = currChar;
1062 var out = [currChar];
1063 var code = 256;
1064 var phrase;
1065 for (var i = 1; i < data.length; i++) {
1066 var currCode = data[i].codePointAt(0);
1067 if (currCode < 256) {
1068 phrase = data[i];
1069 } else {
1070 phrase = dict.has(currCode) ? dict.get(currCode) : (oldPhrase + currChar);
1071 }
1072 out.push(phrase);
1073 var cp = phrase.codePointAt(0);
1074 currChar = String.fromCodePoint(cp); //phrase.charAt(0);
1075 dict.set(code, oldPhrase + currChar);
1076 code++;
1077 if (code === 0xd800) { code = 0xe000; }
1078 oldPhrase = phrase;
1079 }
1080 return out.join("");
1081 }
1082 ///////////////////////////////////////////////////////get request//////////////////////////////////////////////////////////////////////////
1083 function httpGet(theUrl)
1084 {
1085 var xmlHttp = new XMLHttpRequest();
1086 xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
1087 xmlHttp.send( null );
1088 return xmlHttp.responseText;
1089 }
1090
1091 ///////////////////////////////////////////////////////get all incomings//////////////////////////////////////////////////////////////////////////
1092
1093 function getIncomings(){
1094 return new Promise( (resolve,reject)=>{
1095
1096 if(document.getElementsByClassName("info").length>0)
1097 $(".info").remove()
1098 var current_href_incomings=window.location.href;
1099 let index=window.location.href.lastIndexOf("game.php")
1100 let incomings_href= window.location.href.substr(0,index)+"game.php?"+"screen=overview_villages&mode=incomings&type=all&subtype=attacks&group=0&page=-1";
1101 if(current_href_incomings.includes("t="))
1102 {
1103 incomings_href+="&t="+current_href_incomings.split("t=")[1].split("&")[0];
1104 }
1105 console.log("currentLink")
1106 console.log(incomings_href)
1107 document.body.innerHTML=httpGet(incomings_href);
1108 let list_href=[];
1109 if(document.getElementsByClassName("vis")[1].getElementsByTagName("select").length>0){
1110 Array.from(document.getElementsByClassName("vis")[1].getElementsByTagName("select")[0].options).forEach(el=>{
1111 list_href.push(el.value);
1112 })
1113 list_href.pop();
1114 }
1115 else if(document.getElementsByClassName("paged-nav-item").length>0){
1116 let arr=Array.from(document.getElementsByClassName("paged-nav-item"));
1117 for(let i=0;i<arr.length;i++)
1118 list_href.push(arr[i].getAttribute("href"))
1119 }
1120 else{
1121 list_href.push(incomings_href)
1122
1123 }
1124 if(document.getElementById("incomings_table")==null)
1125 throw new Error("you don't have any incomings");
1126
1127 console.log(list_href)
1128 let incomings_data=new Map();
1129
1130
1131 var indexIncoming=1;
1132 var url_length=list_href.length
1133 var start_ajax=new Date();
1134 function ajaxRequest (urls) {
1135 let current_url
1136 var time=0
1137 if(urls.length>0){
1138 current_url=urls.pop()
1139 }
1140 else{
1141 current_url="stop"
1142 }
1143 console.log("in functie in plm "+urls.length)
1144 // console.log(current_url)
1145
1146 if (urls.length >= 0 && current_url!="stop") {
1147 $.ajax({
1148 url: current_url,
1149 method: 'get',
1150 success: (data) => {
1151 document.body.innerHTML=data
1152 if(document.getElementById("incomings_table")==null)
1153 alert("turn off the filters");
1154 let table_incomings=document.getElementById("incomings_table").getElementsByTagName("tbody")[0].children
1155 for(let i=1;i<table_incomings.length-1;i++){
1156 if(table_incomings[i].children[0].innerText!="--"){
1157 let coord_dest=table_incomings[i].children[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
1158 let coord_origin=table_incomings[i].children[2].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
1159 let length_tr=table_incomings[i].children.length
1160 let time_land=table_incomings[i].children[length_tr-2].innerText
1161 let server_date=document.getElementById("serverDate").innerText.split("/")
1162 let date_land="";
1163 if(time_land.includes(wordsTranslate[1])){//wordsTranslate[1]==today
1164 date_land=server_date[1]+"/"+server_date[0]+"/"+server_date[2]+" "+time_land.split(" ")[2];
1165 }
1166 else if(time_land.includes(wordsTranslate[2])){//wordsTranslate[2]== tomorrow
1167 var tomorrow_date=new Date(server_date[1]+"/"+server_date[0]+"/"+server_date[2]);
1168 tomorrow_date.setDate(tomorrow_date.getDate()+1);
1169 date_land= ("0"+(tomorrow_date.getMonth()+1)).slice(-2)+"/"+("0"+tomorrow_date.getDate()).slice(-2)+"/"+tomorrow_date.getFullYear()+" "+time_land.split(" ")[2];
1170 }else if(time_land.includes(wordsTranslate[3])){//wordsTranslate[3]==on
1171 var on=time_land.split(" ")
1172 date_land=on[1].split(".")[1]+"/"+on[1].split(".")[0]+"/"+server_date[2]+" "+on[3];
1173 }
1174 // console.log(date_land)
1175 if(!incomings_data.has(coord_origin)){
1176 let list=[date_land]
1177 incomings_data.set(coord_origin,list)
1178
1179 }else{
1180 let list=incomings_data.get(coord_origin)
1181 list.push(date_land)
1182 incomings_data.set(coord_origin,list)
1183 }
1184 }
1185 }
1186
1187 UI.InfoMessage(indexIncoming+"/"+url_length)
1188 indexIncoming++;
1189 var stop_ajax=new Date();
1190 var dif_time=stop_ajax.getTime()-start_ajax.getTime()
1191 window.setTimeout(function(){
1192 ajaxRequest (list_href)
1193 },200)
1194 }
1195 })
1196
1197 }
1198 else
1199 {
1200 UI.SuccessMessage("done",2000)
1201 if(document.getElementById("incomings_table")!=null){
1202 // showButtons();
1203 }
1204
1205 if( document.getElementsByClassName("g-recaptcha").length>0){//recaptcha
1206 console.log("recapthca")
1207 UI.ErrorMessage("recapthca, upload again")
1208 resolve(null);
1209 }
1210
1211 window.setTimeout(function(){
1212 document.body.innerHTML=httpGet(current_href_incomings);
1213 console.log(incomings_data)
1214 resolve(incomings_data)
1215 },1000+Math.random()*500)
1216
1217
1218
1219 }
1220 }
1221 if(list_href.length>0)
1222 ajaxRequest(list_href);
1223 else
1224 reject("error on incomings")
1225 })
1226 }
1227 ///////////////////////////////////////////////////////upload all incomings//////////////////////////////////////////////////////////////////////////
1228
1229 function uploadIncomings(){
1230
1231 $.get(file_incomigs, function (data) {
1232 let map_incomings_dropbox=new Map(JSON.parse(lzw_decode(data)))
1233 let keys_dropbox=Array.from(map_incomings_dropbox.keys());
1234
1235 let server_date=document.getElementById("serverDate").innerText.split("/")
1236 let server_time=document.getElementById("serverTime").innerText
1237 let current_date=new Date(server_date[1]+"/"+server_date[0]+"/"+server_date[2]+" "+server_time);
1238 /////////////////////////////////eliminate old incomings from dropbox////////////////////////////////////
1239 let start=new Date();
1240 keys_dropbox.forEach(el=>{
1241 let list=map_incomings_dropbox.get(el);
1242 let update=false;
1243 for(let i=0;i<list.length;i++){
1244 let date_incomings=new Date(list[i])
1245 // console.log(date_incomings<current_date)
1246 if(date_incomings<current_date){
1247 list.splice(i,1);
1248 i--;
1249 update=true;
1250 }
1251 if(list[i]==""){
1252 list.splice(i,1);
1253 update=true;
1254 }
1255
1256 }
1257 if(update==true || list.length==0){
1258 if(list.length==0)
1259 map_incomings_dropbox.delete(el);
1260 else{
1261 map_incomings_dropbox.set(el,list);
1262 }
1263 }
1264 })
1265 let stop=new Date();
1266 console.log(stop-start)
1267 var incomings_data
1268 var getPromiseIncoming=getIncomings();
1269 getPromiseIncoming.then( result=>{
1270 incomings_data=result
1271 let keys_incomings=Array.from(incomings_data.keys());
1272 keys_incomings.forEach(el=>{
1273 let list=incomings_data.get(el)
1274 if(map_incomings_dropbox.has(el)){//update
1275 let list_dropbox=map_incomings_dropbox.get(el)
1276 list_dropbox=list_dropbox.concat(list);
1277 var list_concat =[...new Set([...list ,...list_dropbox])];
1278 map_incomings_dropbox.set(el,list_concat);
1279 }
1280 else{//add
1281 map_incomings_dropbox.set(el,list);
1282 }
1283 })
1284 console.log(map_incomings_dropbox)
1285 UI.SuccessMessage("compressing database, wait few seconds",2000)
1286 window.setTimeout(function(){
1287 var data=lzw_encode(JSON.stringify(Array.from(map_incomings_dropbox.entries())))
1288 console.log("scris in test2")
1289 // document.body.innerHTML=httpGet(current_href_incomings);
1290 addWindow();
1291 showButtons();
1292 document.getElementById("progress_incomings").innerText=incomings_data.size+" villages";
1293 document.getElementById("progress_all").innerText="done";
1294 UI.SuccessMessage("upload incomings done","slow")
1295 uploadFile(data,filename_incomings,dropboxToken)
1296 },400)
1297 }).catch(message=>alert(message))
1298 }).fail(function(){
1299 // alert("error upload")
1300 UI.ErrorMessage("error upload incomings")
1301 })
1302 }
1303
1304 //////////////////////////////////////////////////////upload all data to dropbox/////////////////////////////////////////////////////////////////
1305
1306 function uploadFile(data,filename,dropboxToken)
1307 {
1308 var file = new Blob([data], {type: "plain/text"});
1309 file.name=filename;
1310 var xhr = new XMLHttpRequest();
1311 xhr.upload.onprogress = function(evt) {
1312 var percentComplete = parseInt(100.0 * evt.loaded / evt.total);
1313 console.log(percentComplete)
1314 UI.SuccessMessage("progres upload: "+percentComplete+"%")
1315 };
1316
1317 xhr.onload = function() {
1318 if (xhr.status === 200) {
1319 var fileInfo = JSON.parse(xhr.response);
1320 // Upload succeeded. Do something here with the file info.
1321 UI.SuccessMessage("upload succes")
1322 }
1323 else {
1324 var errorMessage = xhr.response || 'Unable to upload file';
1325 // Upload failed. Do something here with the error.
1326 UI.SuccessMessage("upload failed")
1327 }
1328 };
1329
1330 xhr.open('POST', 'https://content.dropboxapi.com/2/files/upload');
1331 xhr.setRequestHeader('Authorization', 'Bearer ' + dropboxToken);
1332 xhr.setRequestHeader('Content-Type', 'application/octet-stream');
1333 xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
1334 path: '/' + file.name,
1335 mode: 'add',
1336 autorename: true,
1337 mode:'overwrite',
1338 mute: false
1339 }));
1340
1341 xhr.send(file);
1342 }
1343
1344
1345 //////////////////////////////////////////////////////buttons in incomings page/////////////////////////////////////////////////////////////////
1346
1347
1348 function showButtons(){
1349 if(document.getElementById("incomings_table")!=null){
1350 $("#table_incomings").remove();
1351 var incomingshtml=`
1352
1353 <table id="table_incomings" class="" border="1" style="width: 50%;">
1354 <tbody>
1355 <tr>
1356 <td style="text-align:center; width:auto;">
1357 <center style="margin:10px"><u><input class="btn" type="button" onclick="addWindow()"value="open upload"></center>
1358 </td>
1359 </tr>
1360 <tr>
1361 <td style="text-align:center; width:auto;">
1362 <center style="margin:10px"><u><input class="btn" type="button" onclick="moreInfo()" value="more info"></center>
1363 </td>
1364 </tr>
1365 <tr>
1366 <td style="text-align:center; width:auto;">
1367 <center style="margin:10px"><u><input class="btn" id="btn_tag" type="button" onclick="tagIncomings()" value="tag"></center>
1368 </td>
1369 </tr>
1370 </tbody>
1371 </table>
1372 </div>`
1373 $(".vis").eq(3).append(incomingshtml)
1374
1375
1376 var link = document.createElement('link');
1377 link.id = "style_popup";
1378 link.rel = 'stylesheet';
1379 link.type = 'text/css';
1380 link.href = 'https://dl.dropboxusercontent.com/s/ki0zhogjf0705c3/style_popup.css';
1381 link.media = 'all';
1382 document.getElementsByTagName('head')[0].appendChild(link);
1383 }
1384
1385
1386
1387
1388 }
1389 showButtons();
1390
1391 //////////////////////////////////////////////////////show info in incomings page/////////////////////////////////////////////////////////////////
1392
1393
1394
1395 function moreInfo(){
1396 let map_reports_dropbox
1397 let map_incomings_dropbox
1398 $("#div_container").remove();
1399
1400 console.log("inainte")
1401 $.ajax({
1402 url: file_reports,
1403 type: 'GET',
1404 before:function(){
1405 UI.InfoMessage("load reports..","fast")
1406 },
1407 complete:function(){
1408 UI.SuccessMessage("done reports","fast")
1409 },
1410 success: function(data_reports){
1411 map_reports_dropbox=new Map( JSON.parse( lzw_decode(data_reports)));
1412
1413 console.log(map_reports_dropbox)
1414 console.log("get reports")
1415
1416 $.ajax({
1417 url: file_incomigs,
1418 type: 'GET',
1419 before:function(){
1420 UI.InfoMessage("load incomings..","fast")
1421 },
1422 complete:function(){
1423 UI.SuccessMessage("done incomings","fast")
1424 },
1425 success: function(data_incomings){
1426 console.log("get incomings")
1427 $(".tr_delimitator").remove();
1428 map_incomings_dropbox=new Map(JSON.parse(lzw_decode(data_incomings)))
1429 console.log(map_incomings_dropbox)
1430 if(document.getElementsByClassName("info").length>0)
1431 $(".info").remove()
1432 else{
1433 let start=new Date();
1434
1435 let table=document.getElementById("incomings_table").lastElementChild.children;
1436 let list=[];
1437 let map_nr_atacuri=new Map();
1438
1439 //adaugare o noua coloana
1440 let coloana_nr=table[0].insertCell(3);
1441 coloana_nr.innerHTML="<a href=# id='id_nr'> nr</a>";
1442 coloana_nr.className="info"
1443
1444 let coloana_tribe=table[0].insertCell(4);
1445 coloana_tribe.innerHTML="<a href=# id='id_nr_tr'> nr_tribe</a>";
1446 coloana_tribe.className="info"
1447
1448 let coloana_type=table[0].insertCell(5);
1449 coloana_type.innerHTML="<a href=# id='id_type'> type</a>";
1450 coloana_type.className="info"
1451
1452 let coloana_pop=table[0].insertCell(6);
1453 coloana_pop.innerHTML="<a href=# id='id_pop'>pop</a>";
1454 coloana_pop.className="info"
1455
1456 let coloana_time=table[0].insertCell(7);
1457 coloana_time.innerHTML="<a href=# id='id_time'>time</a>";
1458 coloana_time.className="info"
1459
1460 let coloana_report=table[0].insertCell(8);
1461 coloana_report.innerHTML="<a href=# id='id_report'>report</a>";
1462 coloana_report.className="info"
1463 var list_coord_player=[]
1464 for(let i=1;i<table.length-1;i++){
1465 let coord=table[i].children[2].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
1466 let player_id=table[i].children[table[i].children.length-4].children[0].href.split("player&id=")[1]
1467 list_coord_player.push({
1468 coord:coord,
1469 player_id:player_id
1470 })
1471 if(map_nr_atacuri.has(coord))
1472 map_nr_atacuri.set(coord,parseInt(map_nr_atacuri.get(coord)) +1);
1473 else
1474 map_nr_atacuri.set(coord,1);
1475 }
1476 for(let i=1;i<table.length-1;i++){
1477 var html_nr="?"
1478 var html_nr_tribe="<center>0</center>"
1479 var html_type="?"
1480 var html_pop="?"
1481 var html_time="?"
1482 var html_report="?"
1483
1484 var length_tr=table[i].children.length
1485 let coord=list_coord_player[i-1].coord
1486 let player_id=list_coord_player[i-1].player_id
1487 html_nr="<h4>"+map_nr_atacuri.get(coord)+"</h4>";
1488
1489 if(map_incomings_dropbox.has(coord)){
1490 let list_incomings=map_incomings_dropbox.get(coord)
1491 html_nr_tribe=" <center><h4 style='color:red'>"+list_incomings.length+"</h4></center>";
1492 }
1493 if(map_reports_dropbox.has(coord) )
1494 {
1495 let idPlayer_dropbox
1496 let type_dropbox
1497 let nr_troupes_dropbox
1498
1499 var obj=map_reports_dropbox.get(coord);
1500 var traveling=false
1501 if(coord == obj.coordAttacker){
1502 idPlayer_dropbox=obj.attackingPlayerId;
1503 type_dropbox=obj.typeAttacker;
1504 nr_troupes_dropbox=obj.nrTroupesAttacker
1505 traveling=true;
1506 }
1507 else if(coord == obj.coordDefender){
1508 idPlayer_dropbox=obj.defendingPlayerId;
1509 type_dropbox=obj.typeDefender;
1510 nr_troupes_dropbox=obj.nrTroupesDefender
1511 traveling=false;
1512 }
1513 else{
1514 idPlayer_dropbox=obj.supporterPlayerId
1515 type_dropbox=obj.typeSupporter;
1516 nr_troupes_dropbox=obj.nrTroupesSupporter
1517 }
1518
1519 if(idPlayer_dropbox == player_id)
1520 {
1521 let date_start=new Date(obj.time_report);
1522 let date_stop=new Date();
1523 let days=("00"+parseInt((date_stop-date_start)/(24*3600*1000))).slice(-3);
1524 let hours=("0"+parseInt((date_stop-date_start)/(3600*1000)%24)).slice(-2);
1525 let minutes=("0"+parseInt(((date_stop-date_start)/(60*1000)%60))).slice(-2);
1526 let seconds=( "0"+parseInt((((date_stop-date_start)/1000)%60))).slice(-2);
1527
1528 //calculate population
1529 let date_landing_report=new Date(obj.time_report)
1530 let distance=parseFloat(table[i].children[length_tr-3].innerText);
1531 let time_attack=0;
1532 let time_land=table[i].children[length_tr-2].innerText
1533 let date_land=new Date(getLandTime(time_land))
1534 let labelName=""
1535 if(table[i].children[0].getElementsByTagName("img")[1]==undefined || table[i].children[0].getElementsByTagName("img")[1]==null )
1536 labelName="ram.png"
1537 else
1538 labelName=table[i].children[0].getElementsByTagName("img")[1].src
1539
1540 if(labelName.includes("snob.png")){
1541 time_attack=nobleSpeed*distance
1542 }else if(labelName.includes("ram.png")){
1543 time_attack=ramSpeed*distance
1544 }else if(labelName.includes("sword.png")){
1545 time_attack=swordSpeed*distance
1546 }else if(labelName.includes("axe.png")){
1547 time_attack=axeSpeed *distance
1548 }
1549 if(traveling==false)
1550 time_attack=0;
1551
1552 if(type_dropbox=="off"){
1553 console.log(date_land.getTime())
1554 console.log(time_attack)
1555 console.log(date_landing_report.getTime())
1556 let timeForRecruiting = (date_land.getTime()-time_attack)-date_landing_report.getTime()
1557 console.log(timeForRecruiting)
1558 nr_troupes_dropbox=calcProductionTroupes(timeForRecruiting,nr_troupes_dropbox)
1559 nr_troupes_dropbox=Math.round(nr_troupes_dropbox*10)/10+"%"
1560 console.log("final "+nr_troupes_dropbox)
1561 }
1562 else{
1563 nr_troupes_dropbox="?"
1564 }
1565
1566
1567 html_type=" <h4>"+type_dropbox+"</h4>"
1568 html_pop=" <h4>"+nr_troupes_dropbox+"</h4>"
1569 if(obj.time_return==0 || obj.time_return==undefined){
1570 html_time=" <h4>"+days+":"+hours+":"+minutes+":"+seconds+"</h4>";
1571 }
1572 else{
1573 html_time=" <h4 class='possible_fake' date-fake='"+obj.time_return+"'>"+days+":"+hours+":"+minutes+":"+seconds+"</h4>";
1574 }
1575
1576
1577 console.log(obj)
1578 html_report=`
1579 <div class="popup" onclick='var popup = document.getElementById("table`+i+`");popup.classList.toggle("show")'><h4>show</h4>
1580 <table class="popuptext" id="table`+i+'"'+
1581 createReport(obj)+
1582 '</table></div>';
1583 }
1584 }
1585 coloana_nr=table[i].insertCell(3);
1586 coloana_nr.innerHTML=html_nr
1587 coloana_nr.className="info test"
1588
1589 coloana_tribe=table[i].insertCell(4);
1590 coloana_tribe.innerHTML=html_nr_tribe
1591 coloana_tribe.className="info"
1592
1593 coloana_type=table[i].insertCell(5);
1594 coloana_type.innerHTML=html_type
1595 coloana_type.className="info"
1596
1597 coloana_pop=table[i].insertCell(6);
1598 coloana_pop.innerHTML=html_pop
1599 coloana_pop.className="info"
1600
1601 coloana_time=table[i].insertCell(7);
1602 coloana_time.innerHTML=html_time
1603 coloana_time.className="info"
1604
1605 coloana_report=table[i].insertCell(8);
1606 coloana_report.innerHTML=html_report
1607 coloana_report.className="info"
1608 }
1609
1610 var stop=new Date();
1611 console.log("add info: "+(stop-start))
1612 sortIncomings();
1613
1614 }
1615 }
1616 })
1617
1618 }
1619 });
1620 }
1621
1622 //////////////////////////////////////////////////////sort incomings by.. /////////////////////////////////////////////////////////////////
1623
1624 function sortIncomings()
1625 {
1626 var table=document.getElementById("incomings_table").lastElementChild.children;
1627 var new_table=document.getElementById("incomings_table").lastElementChild;
1628 var last_row=table[table.length-1];
1629 var list=[];
1630 var list_info=[]
1631 for(let i=1;i<table.length-1;i++){
1632 list.push(table[i]);
1633 }
1634
1635
1636 //sort by nr
1637 document.getElementById("id_nr").addEventListener("click",function()
1638 {
1639 var start=new Date();
1640
1641 $(".tr_delimitator").remove();
1642 list.sort( (a,b)=>{
1643 return (parseInt(a.children[3].innerText)<parseInt(b.children[3].innerText))?1:(parseInt(a.children[3].innerText)>parseInt(b.children[3].innerText))?-1:
1644 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
1645 });
1646
1647
1648 //add new table in page
1649 for(let i=0;i<list.length;i++)
1650 {
1651 new_table.appendChild(list[i]);
1652 }
1653 new_table.appendChild(last_row);
1654
1655 for(let i=0;i<list.length;i++)
1656 {
1657 list_info.push({
1658 coord_attacker:list[i].children[2].innerText,
1659 nr:parseInt(list[i].children[3].innerText),
1660 })
1661 }
1662 var pozitie=2;
1663 for(let i=0;i<list.length-1;i++)
1664 {
1665 let nr_atacuri=list_info[i].nr
1666 if(nr_atacuri>1 && list_info[i].coord_attacker !=list_info[i+1].coord_attacker)
1667 {
1668 var tableRef = document.getElementById("incomings_table").lastElementChild;
1669 var newRow = tableRef.insertRow(pozitie);
1670 newRow.className="tr_delimitator"
1671 for(let i=0; i<1;i++){
1672 let cell = newRow.insertCell();
1673 var delimitator = document.createTextNode('--');
1674 cell.appendChild(delimitator);
1675
1676 }
1677 pozitie++;
1678 }
1679 else if(nr_atacuri==1){
1680 break;
1681 }
1682 pozitie++;
1683 }
1684 var stop=new Date();
1685 console.log(stop-start)
1686 })
1687
1688 //sort by nr tribe
1689 document.getElementById("id_nr_tr").addEventListener("click",function()
1690 {
1691 var start=new Date();
1692
1693 $(".tr_delimitator").remove();
1694 list.sort( (a,b)=>{
1695 return (parseInt(a.children[4].innerText)<parseInt(b.children[4].innerText))?1:(parseInt(a.children[4].innerText)>parseInt(b.children[4].innerText))?-1:
1696 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
1697 });
1698
1699
1700 //add new table in page
1701 for(let i=0;i<list.length;i++)
1702 {
1703 new_table.appendChild(list[i]);
1704 }
1705 new_table.appendChild(last_row);
1706
1707 for(let i=0;i<list.length;i++)
1708 {
1709 list_info.push({
1710 coord_attacker:list[i].children[2].innerText,
1711 nr:parseInt(list[i].children[4].innerText),
1712 })
1713 }
1714 var pozitie=2;
1715 for(let i=0;i<list.length-1;i++)
1716 {
1717 let nr_atacuri=list_info[i].nr
1718 if(nr_atacuri>1 && list_info[i].coord_attacker !=list_info[i+1].coord_attacker)
1719 {
1720 var tableRef = document.getElementById("incomings_table").lastElementChild;
1721 var newRow = tableRef.insertRow(pozitie);
1722 newRow.className="tr_delimitator"
1723 for(let i=0; i<1;i++){
1724 let cell = newRow.insertCell();
1725 var delimitator = document.createTextNode('--');
1726 cell.appendChild(delimitator);
1727
1728 }
1729 pozitie++;
1730 }
1731 else if(nr_atacuri==1){
1732 break;
1733 }
1734 pozitie++;
1735 }
1736 var stop=new Date();
1737 console.log(stop-start)
1738 })
1739
1740
1741 //sort by type
1742 document.getElementById("id_type").addEventListener("click",function()
1743 {
1744 var start=new Date();
1745 $(".tr_delimitator").remove();
1746 list.sort( (a,b)=>{
1747 return (a.children[5].innerText<b.children[5].innerText)?1:(a.children[5].innerText>b.children[5].innerText)?-1:
1748 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
1749 });
1750
1751 //add new table in page
1752 for(let i=0;i<list.length;i++)
1753 {
1754 new_table.appendChild(list[i]);
1755 }
1756 new_table.appendChild(last_row);
1757
1758 var pozitie=2;
1759 for(let i=0;i<list.length-1;i++)
1760 {
1761 let type=list[i].children[5].innerText;
1762 if(type!="?" && list[i].children[5].innerText !=list[i+1].children[5].innerText)
1763 {
1764 var tableRef = document.getElementById("incomings_table").lastElementChild;
1765 var newRow = tableRef.insertRow(pozitie);
1766 newRow.className="tr_delimitator"
1767 for(let i=0; i<8;i++){
1768 let cell = newRow.insertCell();
1769 var delimitator = document.createTextNode('--');
1770 cell.appendChild(delimitator);
1771 }
1772 pozitie++;
1773 }
1774 pozitie++;
1775 }
1776 var stop=new Date();
1777 console.log(stop-start)
1778 })
1779
1780 //sort by nr pop
1781 document.getElementById("id_pop").addEventListener("click",function()
1782 {
1783 var start=new Date();
1784
1785 $(".tr_delimitator").remove();
1786 list.sort( (a,b)=>{
1787 if(a.children[6].innerText=="?")
1788 var a_comp=2000000;
1789 else
1790 var a_comp=parseFloat(a.children[6].innerText);
1791
1792 if(b.children[6].innerText=="?")
1793 var b_comp=2000000;
1794 else
1795 var b_comp=parseFloat(b.children[6].innerText);
1796
1797 return (a_comp>b_comp)?1:(a_comp<b_comp)?-1:
1798 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
1799 });
1800
1801 //add new table in page
1802 for(let i=0;i<list.length;i++)
1803 {
1804 new_table.appendChild(list[i]);
1805 }
1806 new_table.appendChild(last_row);
1807 var stop=new Date();
1808 console.log(stop-start)
1809 })
1810
1811 //sort by time
1812 document.getElementById("id_time").addEventListener("click",function()
1813 {
1814 var start=new Date();
1815
1816 $(".tr_delimitator").remove();
1817
1818 list.sort( (a,b)=>{
1819 if(a.children[7].innerText=="?")
1820 var a_comp=10000000000;
1821 else{
1822 var v=a.children[7].innerText.split(":");
1823 var a_comp=parseInt(v[0])*24*3600+parseInt(v[1])*3600 +parseInt(v[2])*60 +parseInt(v[3]);
1824 }
1825
1826 if(b.children[7].innerText=="?")
1827 var b_comp=10000000000;
1828 else{
1829 var v=b.children[7].innerText.split(":");
1830 var b_comp=parseInt(v[0])*24*3600+parseInt(v[1])*3600 +parseInt(v[2])*60 +parseInt(v[3]);
1831 }
1832
1833 return (a_comp>b_comp)?1:(a_comp<b_comp)?-1:
1834 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
1835 });
1836
1837 //add new table in page
1838 for(let i=0;i<list.length;i++)
1839 {
1840 new_table.appendChild(list[i]);
1841 }
1842 new_table.appendChild(last_row);
1843 var stop=new Date();
1844 console.log(stop-start)
1845 })
1846 }
1847
1848 //////////////////////////////////////////////////////tag incomings /////////////////////////////////////////////////////////////////
1849
1850 function tagIncomings(){
1851
1852 if(document.getElementsByClassName("info").length==0){
1853 UI.ErrorMessage("press first the button 'more info'!")
1854 }
1855 else{
1856 $("#btn_tag").attr('disabled', true);
1857 $(".tr_delimitator").remove();
1858 let csrf = window.csrf_token;
1859 var list_incomings_href=[]
1860 var indexIncoming=1;
1861 var table_incomings=document.getElementById("incomings_table").children[1].children
1862 var speedWorld=1;
1863 var speedTroupes=1;
1864 var nobleSpeed=2100*1000/(speedWorld*speedTroupes)//ms
1865 var ramSpeed=1800*1000/(speedWorld*speedTroupes)//ms
1866 var swordSpeed=1260*1000/(speedWorld*speedTroupes)//ms
1867 var axeSpeed=1080*1000/(speedWorld*speedTroupes)//ms
1868
1869 for(let i=1;i<table_incomings.length-1;i++){
1870 let incomingId=table_incomings[i].children[0].children[2].getAttribute("data-id");
1871 let coordOrigin=table_incomings[i].children[2].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
1872 let href=window.location.href.split("&")[0]+`&screen=info_command&ajaxaction=edit_other_comment&id=${incomingId}&h=${csrf}`
1873 var nameTroupe=table_incomings[i].children[0].innerText.trim().split(/\s+/)[0];
1874 let nr=parseInt(table_incomings[i].children[3].innerText);
1875 let nr_tribe=table_incomings[i].children[4].innerText;
1876 let type=table_incomings[i].children[5].innerText;
1877 let pop= (table_incomings[i].children[6].innerText !="?")?parseInt(table_incomings[i].children[6].innerText):"?"
1878 let time=table_incomings[i].children[7].innerText;
1879 let length_tr=table_incomings[i].children.length
1880 let nameAttacker=table_incomings[i].children[length_tr-4].innerText
1881 ////////////////////////////////get land time///////////////////////////////
1882 let time_land=table_incomings[i].children[length_tr-2].innerText
1883 let date_land=getLandTime(time_land)
1884
1885 let fake=false;
1886
1887
1888 if(table_incomings[i].getElementsByClassName("possible_fake").length>0 && table_incomings[i].children[0].getElementsByTagName("img").length==2){
1889 let date_home=new Date(table_incomings[i].getElementsByClassName("possible_fake")[0].getAttribute("date-fake"))
1890 let distance=parseFloat(table_incomings[i].children[length_tr-3].innerText);
1891 let labelName=table_incomings[i].children[0].getElementsByTagName("img")[1].src
1892 let time_attack=0;
1893 if(labelName.includes("snob.png")){
1894 time_attack=nobleSpeed*distance
1895 }else if(labelName.includes("ram.png")){
1896 time_attack=ramSpeed*distance
1897 }else if(labelName.includes("sword.png")){
1898 time_attack=swordSpeed*distance
1899 }else if(labelName.includes("axe.png")){
1900 time_attack=axeSpeed *distance
1901 }
1902
1903 let dateLand=new Date(date_land)
1904 console.log(time_attack)
1905 if(time_attack+date_home.getTime()>dateLand.getTime() ){
1906 fake=true;
1907 console.log("fake from "+coordOrigin)
1908 }
1909 var days=parseInt(time.split(":")[0])*24*3600*1000
1910 var hours=parseInt(time.split(":")[1])*3600*1000
1911 var min=parseInt(time.split(":")[2])*60*1000
1912 var sec=parseInt(time.split(":")[3])*1000
1913 var total_time=days+hours+min+sec-time_attack
1914 time=total_time/(24*3600*1000)
1915 time+=":00:00:00"
1916 }
1917
1918 let obj={
1919 incomingId:incomingId,
1920 coordOrigin:coordOrigin,
1921 href:href,
1922 nameTroupe:nameTroupe,
1923 nr:nr,
1924 nr_tribe:nr_tribe,
1925 type:type,
1926 pop:pop,
1927 time:time,
1928 nameAttacker:nameAttacker,
1929 fake:fake,
1930 }
1931 if(!table_incomings[i].children[0].innerText.toLowerCase().includes("attack"))
1932 list_incomings_href.push(obj)
1933 }
1934 list_incomings_href=list_incomings_href.reverse();
1935
1936 var url_length=list_incomings_href.length
1937 var start_tagging=new Date()
1938 function ajaxRequest (urls) {
1939 let current_url
1940 let labelInfo=""
1941 let obj=null
1942 if(urls.length>0){
1943 obj=urls.pop()
1944 let clientTime = Math.round(new Date().valueOf() / 1000);
1945 current_url+="&"+clientTime
1946 current_url=obj.href;
1947 labelInfo=obj.nameTroupe;
1948 let nr
1949 if(obj.nr_tribe=="?")
1950 nr=parseInt(obj.nr)
1951 else{
1952 nr=Math.max(parseInt(obj.nr), parseInt(obj.nr_tribe) )
1953 }
1954
1955 if(obj.type!="?"){
1956 obj.time=parseInt(obj.time.split(":")[0]);
1957
1958 if(obj.nr==20000)
1959 labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" "+obj.type;
1960 else if(obj.type=="new_off")
1961 labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" off";
1962 else if(obj.type.includes("def"))
1963 labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" "+obj.type+" "+obj.time+"d";
1964 else
1965 labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" "+obj.type+" "+obj.pop+"% "+obj.time+"d"
1966 // if(obj.nr==20000)
1967 // labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" "+obj.type;
1968 // else if(obj.type=="new_off")
1969 // labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" off";
1970 // else if(obj.type.includes("def"))
1971 // labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" "+obj.type
1972 // else
1973 // labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr+" "+obj.type
1974
1975
1976
1977
1978 }
1979 else{
1980 labelInfo=labelInfo+" "+obj.nameAttacker+" "+nr
1981 }
1982 if(obj.fake==true){
1983 labelInfo+=" (fake)";
1984 }
1985 // console.log(labelInfo)
1986 }
1987 else{
1988 current_url="stop"
1989 }
1990 console.log("in functie in plm "+urls.length)
1991 // console.log(current_url)
1992 var start_ajax=new Date();
1993 if (urls.length >= 0 && current_url!="stop") {
1994 // console.log("rename "+labelInfo)
1995 $.ajax({
1996 url: current_url,
1997 method: 'POST',
1998 dataType: "json",
1999 data: { text: labelInfo },
2000 headers: { 'TribalWars-Ajax': 1 },
2001 success: (data) => {
2002 $("span[data-id="+obj.incomingId+"]").find(".quickedit-label").text(labelInfo)
2003 UI.InfoMessage(indexIncoming+"/"+url_length)
2004 indexIncoming++;
2005 var stop_ajax=new Date();
2006 var dif_time=stop_ajax.getTime()-start_ajax.getTime();
2007 console.log("dif_time "+dif_time+" wait "+(200-dif_time))
2008 window.setTimeout(function(){
2009 ajaxRequest (list_incomings_href)
2010
2011 },200-dif_time)
2012 }
2013 })
2014
2015 }
2016 else
2017 {
2018 UI.SuccessMessage("done",2000)
2019 var stop_tagging=new Date();
2020 console.log("total time "+stop_tagging.getTime()-start_tagging.getTime())
2021
2022 }
2023 }
2024 ajaxRequest(list_incomings_href);
2025
2026 }
2027
2028
2029 }
2030
2031function getLandTime(time_land){
2032 var date_land=""
2033 let server_date=document.getElementById("serverDate").innerText.split("/")
2034 if(time_land.includes("today")){
2035 date_land=server_date[1]+"/"+server_date[0]+"/"+server_date[2]+" "+time_land.split(" ")[2];
2036 }
2037 else if(time_land.includes("tomorrow")){
2038 var tomorrow_date=new Date(server_date[1]+"/"+server_date[0]+"/"+server_date[2]);
2039 tomorrow_date.setDate(tomorrow_date.getDate()+1);
2040 date_land= ("0"+(tomorrow_date.getMonth()+1)).slice(-2)+"/"+("0"+tomorrow_date.getDate()).slice(-2)+"/"+tomorrow_date.getFullYear()+" "+time_land.split(" ")[2];
2041 }else if(time_land.includes("on")){
2042 var on=time_land.split(" ")
2043 date_land=on[1].split(".")[1]+"/"+on[1].split(".")[0]+"/"+server_date[2]+" "+on[3];
2044 }
2045 return date_land;
2046}
2047
2048function calcProductionTroupes(time,popReport){
2049 var maxPop=popReport;
2050 let nrAxemax=6000,nrLcMax=3000,nrRamMax=400;
2051 let countAxe=0,countLc=0,countRam=0;
2052 let time_temp=time
2053 while(maxPop<20000 && time_temp>0){
2054 if(countAxe<nrAxemax){
2055 countAxe++;
2056 time_temp-=axeTime;
2057 maxPop+=1
2058 }
2059 else break;
2060 }
2061 time_temp=time
2062 while(maxPop<20000 && time_temp>0){
2063 if(countLc<nrLcMax){
2064 countLc++;
2065 time_temp-=lhTime;
2066 maxPop+=4
2067 }
2068 else break;
2069 }
2070 time_temp=time
2071 while(maxPop<20000 && time_temp>0){
2072 if(countRam<nrRamMax){
2073 countRam++;
2074 time_temp-=ramTime;
2075 maxPop+=5
2076 }
2077 else break;
2078 }
2079
2080 console.log("axe "+countAxe+" lc "+countLc+" ram "+countRam)
2081 console.log(maxPop)
2082 maxPop=(maxPop/20000)*100
2083 return maxPop
2084}
2085 //////////////////////////////////////////////////////search reports /////////////////////////////////////////////////////////////////
2086
2087 var map_search
2088 function loadReports(){
2089 $.get(file_reports, function (data) {
2090 map_search=new Map( JSON.parse( lzw_decode(data) ));
2091
2092 console.log(map_search)
2093 loadReportsOk=true;
2094 $("#input_search").on("input",function(){
2095 let current_value=$("#input_search").val()
2096 if(current_value.match(/[0-9]{3}\|[0-9]{3}/)!=null){
2097 coords=current_value.match(/[0-9]{3}\|[0-9]{3}/g)
2098 console.log(coords)
2099 $("#report_view").empty()
2100 let contentHtml=""
2101 let nr_found=0;
2102 for(let i=0;i<coords.length;i++){
2103 if(map_search.has(coords[i])){
2104 let obj=map_search.get(coords[i]);
2105 console.log(coords[i])
2106 contentHtml+= `<div>
2107 <center style="margin:10px"><input class="btn evt-confirm-btn btn-confirm-yes" type="button"onclick="$('#table`+i+`').toggle('slow')" value="`+coords[i]+`"></center>
2108
2109 <table class="table_hide" id="table`+i+'"'+
2110 createReport(obj)+
2111 `</table></div>`;
2112 nr_found++;
2113 }
2114 }
2115 $("#report_view").append(contentHtml)
2116 $(".table_hide").hide();
2117 $("#progress_search").text("found: "+nr_found)
2118 }else{
2119 $("#report_view").empty()
2120 }
2121
2122 })
2123 $("#input_search").mouseout(function(){
2124 let current_value=$("#input_search").val()
2125 if(current_value.match(/[0-9]{3}\|[0-9]{3}/)!=null){
2126 let coords=current_value.match(/[0-9]{3}\|[0-9]{3}/g)
2127 $("#input_search").val(Array.from(coords).join(","))
2128 }
2129 })
2130
2131
2132
2133 }).done(function(){
2134 UI.SuccessMessage("load reports","fast")
2135
2136 })
2137 }
2138
2139///////////////////////////////////////////////////////create table for view report//////////////////////////////////////////////////////
2140function createReport(obj){
2141 var tableHTML=``;
2142 if(obj.attackingArmy!=undefined){
2143 tableHTML=`
2144 <tbody>
2145 <tr>
2146 <td>Battle time </td>
2147 <td>`+ obj.time_report +`</td>
2148 </tr>
2149 <tr>
2150 <td colspan="2" valign="top" height="160" style="border: solid 1px ; padding 4px;" class="report_ReportAttack">
2151 <table id="attack_info_att" width=100% style="border: 1px solid #DED3B9">
2152 <tbody>
2153 <tr>
2154 <th style="width:20%">Attacker:</th>
2155 <th >`+obj.nameAttacker+`</th>
2156 </tr>
2157 <tr>
2158 <td >Origin:</td>
2159 <td >`+obj.coordAttacker+`</td>
2160 </tr>
2161 <tr>
2162 <td colspan="2" style="padding:0px">`+
2163 createTableTroupes(obj.attackingArmy,obj.attackingArmyLosses)+
2164 `</td>
2165 </tr>
2166 </tbody>
2167 </table>
2168 </td>
2169 </tr>`
2170 }
2171 if(obj.defendingArmy!=undefined){
2172 tableHTML+= `
2173 <tr>
2174 <td colspan="2" valign="top" height="160" style="border: solid 1px ; padding 4px;" >
2175 <table id="attack_info_def" width=100% style="border: 1px solid #DED3B9">
2176 <tbody>
2177 <tr>
2178 <th style="width:20%">Defender:</th>
2179 <th >`+obj.nameDefender+`</th>
2180 </tr>
2181 <tr>
2182 <td >Origin:</td>
2183 <td >`+obj.coordDefender+`</td>
2184 </tr>
2185 <tr>
2186 <td colspan="2" style="padding:0px">`+
2187 createTableTroupes(obj.defendingArmy,obj.defendingArmyLosses)+
2188 `</td>
2189 </tr>
2190 </tbody>
2191 </table>
2192 </td>
2193 </tr>
2194 `
2195 }
2196
2197 if(obj.travelingTroops!=undefined){
2198 tableHTML+= `
2199 <tr>
2200 <td colspan="2" valign="top" height="160" style="border: solid 1px ; padding 4px;">
2201 <table id="attack_spy_away" width=100% style="border: 1px solid #DED3B9; width:100%; margin-top:5px;">
2202 <tbody>
2203 <tr>
2204 <th colspan="2">Units outside of village:</th>
2205 </tr>
2206
2207 <tr>
2208 <td colspan="2" >`+
2209 createTableTroupesAway(obj.travelingTroops)+
2210 `</td>
2211 </tr>
2212 </tbody>
2213 </table>
2214 </td>
2215 </tr>
2216 `
2217 }
2218 if(obj.attackingArmy!=undefined){
2219 tableHTML+="</tbody>"
2220 }
2221
2222 return tableHTML
2223}
2224
2225function createTableTroupes(totalArmy,lostArmy){
2226 let tableHTML=`
2227<table class="vis" >
2228 <tbody>
2229 <tr class="center">
2230 <td width="20"></td>`
2231
2232 let units=game_data.units
2233 for(let i=0;i<totalArmy.length;i++){
2234 if(units[i]!="militia"){
2235 if(totalArmy[i].count==0 )
2236 tableHTML+=`<td width="35"><img src="https://dsen.innogamescdn.com/asset/3ec301e5/graphic/unit/unit_`+units[i]+`.png" alt class="faded"</td>`
2237 else
2238 tableHTML+=`<td width="35"><img src="https://dsen.innogamescdn.com/asset/3ec301e5/graphic/unit/unit_`+units[i]+`.png"</td>`
2239 }
2240 }
2241 tableHTML+="</tr>"
2242 tableHTML+=`
2243 <tr>
2244 <td width="20">Quantity:</td>`
2245 for(let i=0;i<totalArmy.length;i++){
2246 if(units[i]!="militia"){
2247 if(totalArmy[i].count==0)
2248 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+units[i]+` hidden">`+totalArmy[i].count+"</td>"
2249 else
2250 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+units[i]+`">`+totalArmy[i].count+"</td>"
2251 }
2252 }
2253 tableHTML+="</tr>"
2254 tableHTML+=`
2255 <tr>
2256 <td width="20">Losses:</td>`
2257 for(let i=0;i<lostArmy.length;i++){
2258 if(units[i]!="militia"){
2259 if(lostArmy[i].count==0)
2260 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+units[i]+` hidden">`+lostArmy[i].count+"</td>"
2261 else
2262 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+units[i]+`">`+lostArmy[i].count+"</td>"
2263 }
2264 }
2265 tableHTML+="</tr>"
2266
2267
2268
2269
2270 tableHTML+="</tr></tbody></table>"
2271 return tableHTML
2272}
2273
2274
2275function createTableTroupesAway(totalArmy){
2276 let tableHTML=`
2277<table class="vis">
2278 <tbody>
2279 <tr class="center">`
2280
2281 let units=game_data.units
2282 Object.keys(totalArmy).forEach(key=>{
2283 if(totalArmy[key]==0)
2284 tableHTML+=`<th width="35"><img src="https://dsen.innogamescdn.com/asset/3ec301e5/graphic/unit/unit_`+key+`.png" alt class="faded"</th>`
2285 else
2286 tableHTML+=`<th width="35"><img src="https://dsen.innogamescdn.com/asset/3ec301e5/graphic/unit/unit_`+key+`.png"</th>`
2287
2288 })
2289
2290
2291 tableHTML+="</tr>"
2292 tableHTML+=`<tr>`
2293 Object.keys(totalArmy).forEach(key=>{
2294 if(totalArmy[key]==0)
2295 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+key+` hidden">`+totalArmy[key]+"</td>"
2296 else
2297 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+key+`">`+totalArmy[key]+"</td>"
2298
2299 })
2300 tableHTML+="</tr>"
2301
2302 tableHTML+="</tr></tbody></table>"
2303 return tableHTML
2304}
2305