· 5 years ago · Oct 07, 2020, 01:10 PM
1//////////////////////////////////////////////create interface//////////////////////////////////////////////////////////
2var backgroundColor = "#36393f";
3var borderColor = "#3e4147";
4var headerColor = "#202225";
5var titleColor = "#ffffdf";
6var dropboxToken='voeQxDKEfdAAAAAAAAAAAWmeVbsqR6fFyKdfA2gXF05UhEt-ztkJqkFZY6PkMTzk';
7var file_reports='https://dl.dropboxusercontent.com/s/qdydvdssbrfns92/test.txt?dl=0';
8var file_incomigs='https://dl.dropboxusercontent.com/s/0acfdzwwhhrcup1/test2.txt?dl=0';
9var file_users='https://dl.dropboxusercontent.com/s/y7idzygkmwm68k8/test3.txt?dl=0';
10var filename_reports="test.txt";
11var filename_incomings="test2.txt";
12var filename_users="test3.txt";
13
14var speedWorld=3;
15var speedTroupes=0.67;
16var nobleSpeed=2100*1000/(speedWorld*speedTroupes)//ms
17var ramSpeed=1800*1000/(speedWorld*speedTroupes)//ms
18var swordSpeed=1260*1000/(speedWorld*speedTroupes)//ms
19var axeSpeed=1080*1000/(speedWorld*speedTroupes)//ms
20
21//verify acces users
22let response=httpGet(file_users);
23tribemates=response.split("\n")
24if(!tribemates.includes(game_data.player.name)){
25 // UI.ErrorMessage("try later","slow")
26 // throw new Error("you do not have acces");
27 console.log("you do not have acces")
28}
29if(game_data.locale!="en_DK")
30 throw new Error("it doesn't work");
31
32
33 html = `
34 <div id="div_container" class="ui-widget-content" style="width:600px;background-color:${backgroundColor};cursor:move;z-index:50;">
35 <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>
36 <h2><center style="margin:10px"><u><font color="${titleColor}">Upload data</font></u></center></h2>
37 <table id="table_upload" class="" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor}">
38 <tr>
39 <td style="text-align:center; width:auto; background-color:${headerColor}">
40 <h2><center style="margin:10px"><u><font color="${titleColor}">reports</font></u></center></h2>
41 </td>
42 <td style="text-align:center; width:auto; background-color:${headerColor}">
43 <center style="margin:10px"><u><input class="btn" type="button" id="upload_reports" onclick="uploadReports()" value="Upload"></center>
44 </td>
45 <td style="text-align:center; width:auto; background-color:${headerColor}">
46 <p><center style="margin:10px"><font color="${titleColor}" id="progress_reports">progress</font></center></p>
47 </td>
48 </tr>
49 <tr>
50 <td style="text-align:center; width:auto; background-color:${headerColor}">
51 <h2><center style="margin:10px"><u><font color="${titleColor}">incomings</font></u></center></h2>
52 </td>
53 <td style="text-align:center; width:auto; background-color:${headerColor}">
54 <center style="margin:10px"><u><input class="btn" type="button" id="upload_incomings" onclick="uploadIncomings()" value="Upload"></center>
55 </td>
56 <td style="text-align:center; width:auto; background-color:${headerColor}">
57 <p><center style="margin:10px" ><font color="${titleColor}" id="progress_incomings">progress</font></center></p>
58 </td>
59 </tr>
60 <tr>
61 <td style="text-align:center; width:auto; background-color:${headerColor}">
62 <h2><center style="margin:10px"><u><font color="${titleColor}">All info</font></u></center></h2>
63 </td>
64 <td style="text-align:center; width:auto; background-color:${headerColor}">
65 <center style="margin:10px"><u><input class="btn" type="button" onclick="uploadAll()" value="Upload all"></center>
66 </td>
67 <td style="text-align:center; width:auto; background-color:${headerColor}">
68 <p><center style="margin:10px" ><font color="${titleColor}" id="progress_all">progress</font></center></p>
69 </td>
70 </tr>
71 </table>
72 <h2><center style="margin:10px"><u><font color="${titleColor}">Search reports</font></u></center></h2>
73 <table id="table_upload" class="" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor}">
74 <tr>
75 <td style="text-align:center; width:auto; background-color:${headerColor}">
76 <center style="margin:10px"><u><input class="btn" type="button" onclick="loadReports()" value="Load reports"></center>
77 </td>
78 <td style="text-align:center; width:auto; background-color:${headerColor}">
79 <center style="margin:10px"><u><input style="text-align: center;" type="text" id="input_search" onclick="" placeholder="coord" ></center>
80 </td>
81 <td style="text-align:center; width:auto; background-color:${headerColor}">
82 <p><center style="margin:10px"><font color="${titleColor}" id="progress_search">status</font></center></p>
83 </td>
84 </tr>
85 </table>
86 <center style="margin:10px"><div id="report_view" style="background-color:#d2c09e"> report view <div><center>
87
88 </div>
89 `;
90 ////////////////////////////////////////add and remove window from page///////////////////////////////////////////
91 if(document.getElementById("incomings_table")==null){
92 $("#div_container").remove()
93 $("#contentContainer").eq(0).prepend(html);
94 $("#mobileContent").eq(0).prepend(html);
95
96 if(game_data.device=="desktop"){
97 $("#div_container").css("position","fixed");
98 $("#div_container").draggable();
99 }
100 }
101 function closeWindow(){
102 document.getElementById("div_container").remove();
103 list_href=[]
104 }
105
106
107
108 function addWindow(){
109 $("#contentContainer").eq(0).prepend(html);
110 $("#mobileContent").eq(0).prepend(html);
111
112 if(game_data.device=="desktop"){
113 $("#div_container").css("position","fixed");
114 $("#div_container").draggable();
115 }
116 }
117
118 var loadReportsOk=false;
119 $("#input_search").on("input",function(){
120 if(loadReportsOk==false)
121 UI.ErrorMessage("upload reports first","fast")
122 })
123 $("#input_search").mouseout(function(){
124 if(loadReportsOk==false)
125 $("#input_search").val("");
126 })
127
128 if(document.getElementById("incomings_table")!=null){
129 window.setInterval(function(){
130
131 var rows= $(".row_a,.row_b")
132 console.log("check incomings")
133 for(let i=0;i<rows.length;i++)
134 {
135 let currentHour=rows[i].children[rows[i].children.length-1].innerText.split(":")
136 if(parseInt(currentHour[0])==0 && parseInt(currentHour[1])==0 && parseInt(currentHour[2])<5){
137 rows[i].remove();
138 }
139 else{
140 break;
141 }
142 }
143 },5000)
144 }
145
146
147
148 function uploadAll(){
149 uploadReports(uploadIncomings);
150 }
151
152
153 /////////////////////////////////////////////////get all reports info//////////////////////////////////////////////////////////////////
154 function uploadReports(callback){
155 let list_href=[]
156 document.getElementById("progress_reports").innerText="get links..";
157
158 let nameHistoryReports=game_data.world +"HistoryReports"
159 var map_idReports=new Map();
160 var current_page=window.location.href;
161 if(localStorage.getItem(nameHistoryReports)==null){
162 localStorage.setItem(nameHistoryReports,JSON.stringify(Array.from(new Map().entries())))
163 }
164 else{
165 map_idReports=new Map(JSON.parse(localStorage.getItem(nameHistoryReports)));
166 Array.from(map_idReports.keys()).forEach(el=>{
167 let currentDate=new Date();
168 let reportDate=new Date(map_idReports.get(el))
169 if(currentDate.getTime()- reportDate.getTime() > 15*24*3600*1000){
170 console.log("remove: "+map_idReports.get(el))
171 map_idReports.delete(el)
172 }
173 })
174
175 }
176
177 $(document).on('click','.autoHideBox',function(){
178 UI.SuccessMessage("stop",2000)
179 list_href=[]
180 })
181
182
183 list_href=getLinks(true,map_idReports);//only current folder
184 console.log(list_href)
185 var list_data_reports=[]
186 var nr_reports=0;
187 var nr_reports_total=list_href.length
188 addWindow();
189 document.getElementById("progress_reports").innerText=nr_reports+"/"+nr_reports_total+" reports";
190 // UI.InfoMessage(nr_reports+"/"+nr_reports_total+" reports")
191 var current_url
192 function ajaxRequest (urls) {
193 if(urls.length>0)
194 current_url=urls.pop().href;
195 else
196 current_url="stop"
197 console.log("in functie in plm "+urls.length)
198 if (urls.length > 0 && current_url!= "stop") {
199 $.ajax({
200 method: 'GET',
201 url: current_url,
202 })
203 .done(function (result) {
204 document.body.innerHTML= result;
205 result=null
206 // addWindow();
207 let list=getDataReport(tribemates);
208 console.log(list)
209 if(list==null ){
210 console.log("recaptcha, upload again")
211 UI.ErrorMessage("recaptcha, upload again","slow")
212 addWindow();
213 document.getElementById("progress_reports").innerText="recaptcha";
214 list_href=[]
215
216 }
217 else{
218 console.log("reports info "+list.length)
219 for(let j=0;j<list.length;j++){
220 list_data_reports.push({"coord":list[j].coord,"reportInfo":list[j].reportInfo});
221 }
222 // document.getElementById("progress_reports").innerText=nr_reports+"/"+nr_reports_total+" reports";
223 UI.SuccessMessage(nr_reports+"/"+nr_reports_total+" reports")
224
225 nr_reports++;
226 let idReport= parseInt(current_url.match(/view=(\d+)/)[1]);
227 let currentDate=new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate();
228 if(document.getElementsByClassName("unit-item unit-item-axe").length>0){
229 var time_report=document.getElementsByClassName("vis")[3].firstElementChild.children[1].children[1].innerText;
230 map_idReports.set(idReport,time_report)
231 }
232 else{
233 map_idReports.set(idReport,currentDate)
234 }
235 }
236 ajaxRequest(list_href);
237 });
238
239 }
240 else
241 {
242 ////////////////////////////////////extract data from dropbox/////////////////////////////////////////
243 console.log("inainte de a extrage date din dropbox")
244 $.get(file_reports, function (data) {
245 console.log("map_dropbox")
246 console.log(JSON.parse(data));
247 console.log("list_data_reports")
248 console.log(list_data_reports);
249 map_dropbox=new Map(JSON.parse(data));
250 document.body.innerHTML= httpGet(current_page);
251 addWindow();
252 let nr_update=0;
253 let nr_write=0;
254 list_data_reports.slice().reverse().forEach(function(el){
255 if(map_dropbox.has(el.coord)){//update el[0]=key
256 if(el.typeAttacker=="new_off"){
257 console.log("new_off, don't do anything")
258 }else{
259 console.log("coord exists in dropbox already")
260 let time_prev=new Date(map_dropbox.get(el.coord).time_report);
261 let time_current=new Date(el.reportInfo.time_report);
262 console.log(time_current-time_prev)
263 if(time_current-time_prev<48*3600*1000 && (el.typeAttacker=="def" )){//48 hours
264 console.log("a fost def_cat")
265 map_dropbox.set(el.coord,el.reportInfo)
266 nr_update++;
267 }
268 else if(time_current-time_prev>0 ){
269 console.log("update coord: "+el.coord+" in dropbox")
270 map_dropbox.set(el.coord,el.reportInfo)
271 nr_update++;
272 }
273
274 }
275 }
276 else{//write
277 console.log("write coord in dropbox")
278 map_dropbox.set(el.coord,el.reportInfo)
279 nr_write++;
280 }
281 })
282
283 var data=JSON.stringify(Array.from(map_dropbox.entries()))
284 console.log(map_dropbox)
285 console.log("hai ba")
286 uploadFile(data,filename_reports,dropboxToken)
287 localStorage.setItem(nameHistoryReports,JSON.stringify(Array.from(map_idReports.entries())))
288 document.getElementById("progress_reports").innerText="done";
289 UI.SuccessMessage("upload reports done\n update: "+nr_update+" \nwrite: "+nr_write,4000)
290
291 }).done(function(){
292 if(typeof(callback)==="function" && current_url!="stop")
293 callback();
294
295 }).fail(function(){
296 // alert("error upload")
297 UI.ErrorMessage("upload again \n try after few minutes")
298
299 })
300
301 }
302 }
303 ajaxRequest(list_href);
304
305 }
306
307
308 ///////////////////////////////////////////////////////////////////get all links////////////////////////////////////////////////////////////////
309 function getLinks(all,map_idReports){
310 // var currentPage=document.body.innerHTML;
311
312 let list_pages=[]
313 let current_href=window.location.href;
314 if(current_href.includes("screen=report"))
315 all=false;
316 if(all){// all pages from all folders
317 let index=window.location.href.lastIndexOf("game.php")
318 let href= window.location.href.substr(0,index)+"game.php?"+"screen=report&mode=all&group_id=-1";
319 if(current_href.includes("t=")){
320 href+="&t="+current_href.split("t=")[1].split("&")[0];
321 }
322 list_pages.push(href)
323 document.body.innerHTML=httpGet(href)
324 }
325 if(document.getElementsByClassName("vis")[1].getElementsByTagName("select").length>0){
326 Array.from(document.getElementsByClassName("vis")[1].getElementsByTagName("select")[0]).forEach(function(item){
327 list_pages.push(item.value)
328 })
329 }
330 else if(document.getElementsByClassName("paged-nav-item").length>0){//all pages from the current folder
331 if(all==false){
332 let current_link=window.location.href;
333 list_pages.push(current_link);
334 }
335 Array.from(document.getElementsByClassName("paged-nav-item")).forEach(function(item){
336 list_pages.push(item.href);
337 })
338 }
339 else{//only one page from the current folder
340 let current_link=window.location.href;
341 list_pages.push(current_link);
342 }
343 console.log("list pages")
344 console.log(list_pages)
345
346 let list_href=[];
347 list_pages.forEach(function(href){
348 document.body.innerHTML= httpGet(href);
349
350 let table_report= document.getElementById("report_list").firstElementChild.children;
351 let year=document.getElementById("serverDate").innerText.split("/")[2];
352 for(let i=1;i<table_report.length-1;i++){
353 let month_day=table_report[i].children[2].innerText;
354 let date_report=new Date(year+" "+month_day)
355 let current_date=new Date();
356 if(current_date-date_report<200*24*3600*1000){//old
357
358 let img_icon=table_report[i].children[1].children[0].children.length;
359 if(img_icon>0 || table_report[i].innerText.includes("supports")){
360 let obj={
361 id:table_report[i].getElementsByTagName("a")[0].getAttribute("data-id"),
362 href:table_report[i].getElementsByTagName("a")[0].href
363 }
364 if(!map_idReports.has(parseInt(obj.id)))
365 list_href.push(obj)
366 }
367 }
368 }
369 })
370 console.log(list_href)
371 // document.body.innerHTML=currentPage;
372 return list_href
373 }
374
375 ////////////////////////////////////////////////////////////get data from report////////////////////////////////////////////////////////////////////
376
377 function getDataReport(tribemates){
378 var mapObject={};
379 var listObject=[];
380 for(let i=0;i<tribemates.length;i++)
381 tribemates[i]=tribemates[i].replace(/\./g, '_');
382 // tribemates=[]
383 var reportInfo={};
384 try{
385 if($("#attack_info_att").length>0){
386 var attackInfo=$("#attack_info_att");
387 if(attackInfo.text().includes("deleted") || attackInfo.text().includes("---")){
388 console.log("error upload")
389 return 0;
390 }
391 var defenseInfo = $("#attack_info_def");
392 if(defenseInfo.text().includes("deleted") || defenseInfo.text().includes("---")){
393 console.log("error upload")
394 return 0;
395 }
396
397 var attackingPlayer = attackInfo.find('a[href*=info_player]');
398 var defendingPlayer = defenseInfo.find('a[href*=info_player]');
399 var attackingPlayerId=attackingPlayer.prop('href').match(/id=(\w+)/)[1];
400 var defendingPlayerId=defendingPlayer.prop('href').match(/id=(\w+)/)[1];
401 reportInfo.attackingPlayerId=attackingPlayerId;
402 reportInfo.defendingPlayerId=defendingPlayerId;
403 }
404 ///////////////////////////////////////////////////////////////////////////
405
406
407 if(document.getElementsByClassName("unit-item unit-item-axe").length>1)
408 {
409 var time_report=document.getElementsByClassName("vis")[3].firstElementChild.children[1].children[1].innerText;
410 // if(new Date()-new Date(time_report)>14*24*3600*1000)//report too old
411 // return listObject;
412
413 reportInfo.time_report=time_report
414 var report=document.getElementsByClassName("vis")[3].innerHTML;
415 var index=report.indexOf('<div class="no-preview">');
416 report=report.substring(0,index);
417 report=lzw_encode(report);
418 reportInfo.report=report;
419
420 ///////////////////////////defender date////////////////////
421 var nameAttacker=document.getElementById("attack_info_att").children[0].children[0].children[1].innerText.replace(/\./g, '_');
422 var coordAttacker=document.getElementsByClassName("village_anchor")[0].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
423 var nameDefender=document.getElementById("attack_info_def").children[0].children[0].children[1].innerText.replace(/\./g, '_');;
424 var coordDefender=document.getElementsByClassName("village_anchor")[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
425 reportInfo.nameAttacker=nameAttacker;
426 reportInfo.coordAttacker=coordAttacker;
427 reportInfo.nameDefender=nameDefender;
428 reportInfo.coordDefender=coordDefender;
429
430 var axe_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-axe")[0].innerText);
431 var axe_atac_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-axe")[1].innerText);
432 var light_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-light")[0].innerText)*4;
433 var light_atac_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-light")[1].innerText)*4;
434 var ram_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-ram")[0].innerText)*5;
435 var ram_atac_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-ram")[1].innerText)*5;
436 var cat_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-catapult")[0].innerText)*8;
437 var cat_atac_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-catapult")[1].innerText)*8;
438 var noble=parseInt(document.getElementsByClassName("unit-item unit-item-snob")[0].innerText)*100;
439
440 var spear_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-spear")[0].innerText);
441 var sword_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-sword")[0].innerText);
442 var archer_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-archer")[0].innerText);
443 var heavy_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-heavy")[0].innerText)*6;
444 var spy_atac_total=parseInt(document.getElementsByClassName("unit-item unit-item-spy")[0].innerText)*2;
445 var spy_atac_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-spy")[1].innerText)*2;
446
447 var typeAttacker="?";
448 var nrTroupesAttacker=0;
449 var nrTroupesAttackerTotal=0;
450 var time_return=0;
451 if(axe_atac_total+light_atac_total+ram_atac_total >1000)
452 {
453 typeAttacker="off";
454 nrTroupesAttacker=(axe_atac_total-axe_atac_pierderi)+(light_atac_total-light_atac_pierderi) + (ram_atac_total-ram_atac_pierderi);
455 console.log("ianinte")
456 if(ram_atac_total>0 && noble==0){
457 console.log("aici")
458 nrTroupesAttackerTotal=axe_atac_total+light_atac_total+ram_atac_total
459 let time_attack=ramSpeed*calcDistance(coordAttacker,coordDefender)
460 time_return=new Date(time_report).getTime()+time_attack;
461 time_return=new Date(time_return)
462 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
463 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
464
465 }else if(axe_atac_total>0 && noble==0){
466 nrTroupesAttackerTotal=axe_atac_total+light_atac_total
467 time_attack=axeSpeed*calcDistance(coordAttacker,coordDefender)
468 time_return=new Date(time_report).getTime()+time_attack;
469 time_return=new Date(time_return)
470 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
471 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
472
473 }else if(axe_atac_total+light_atac_total+ram_atac_total>10000 && noble>0){
474 nrTroupesAttackerTotal=axe_atac_total+light_atac_total+ram_atac_total
475 time_attack=axeSpeed*calcDistance(coordAttacker,coordDefender)
476 time_return=new Date(time_report).getTime()+time_attack;
477 time_return=new Date(time_return)
478 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
479 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
480 }
481 }
482 else if(spy_atac_total>10000){
483 typeAttacker="spy";
484 nrTroupesAttacker=spy_atac_total-spy_atac_pierderi;
485 }
486 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)
487 {
488 typeAttacker="new_off";
489 }
490 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){
491 typeAttacker="def";
492 }
493 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)
494 typeAttacker="def_spy";
495
496 if((cat_atac_total>=50*8 && typeAttacker=="def") || (cat_atac_total>=50*8 && axe_atac_total+light_atac_total+ram_atac_total<20)){
497 typeAttacker="def_cat";
498 nrTroupesAttacker=cat_atac_total-cat_atac_pierderi;
499 if(noble==0){
500 nrTroupesAttackerTotal=heavy_atac_total+cat_atac_total
501 time_attack=ramSpeed*calcDistance(coordAttacker,coordDefender)
502 time_return=new Date(time_report).getTime()+time_attack;
503 time_return=new Date(time_return)
504 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
505 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0] }
506 }
507
508 reportInfo.time_return=time_return
509 reportInfo.nrTroupesAttackerTotal=nrTroupesAttackerTotal
510 reportInfo.typeAttacker=typeAttacker;
511 reportInfo.nrTroupesAttacker=nrTroupesAttacker;
512
513
514 /////////////////////////////////////////////////defender date/////////////////////
515 var nrTroupesDefender=0;
516 var typeDefender="?";
517 if(document.getElementsByClassName("unit-item unit-item-axe").length>2){
518
519
520 var axe_aparare_total=parseInt(document.getElementsByClassName("unit-item unit-item-axe")[2].innerText);
521 var axe_aparare_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-axe")[3].innerText);
522 var light_aparare_total=parseInt(document.getElementsByClassName("unit-item unit-item-light")[2].innerText)*4;
523 var light_aparare_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-light")[3].innerText)*4;
524 var ram_aparare_total=parseInt(document.getElementsByClassName("unit-item unit-item-ram")[2].innerText)*5;
525 var ram_aparare_pierderi=parseInt(document.getElementsByClassName("unit-item unit-item-ram")[3].innerText)*5;
526 var spear_aparare_total=parseInt(document.getElementsByClassName("unit-item unit-item-spear")[2].innerText);
527 var sword_aparare_total=parseInt(document.getElementsByClassName("unit-item unit-item-sword")[2].innerText);
528 var archer_aparare_total=parseInt(document.getElementsByClassName("unit-item unit-item-archer")[2].innerText);
529 var heavy_aparare_total=parseInt(document.getElementsByClassName("unit-item unit-item-heavy")[2].innerText)*6;
530
531
532 nrTroupesDefender=(axe_aparare_total-axe_aparare_pierderi)+(light_aparare_total-light_aparare_pierderi) + (ram_aparare_total-ram_aparare_pierderi);
533 if(axe_aparare_total+light_aparare_total+ram_aparare_total >1000){
534 typeDefender="off";
535 }
536 }
537
538 if(document.getElementsByClassName("unit-item unit-item-axe").length>4){
539 var axe_aparare_spy=parseInt(document.getElementsByClassName("unit-item unit-item-axe")[4].innerText);
540 var light_aparare_spy=parseInt(document.getElementsByClassName("unit-item unit-item-light")[4].innerText)*4;
541 var ram_aparare_spy=parseInt(document.getElementsByClassName("unit-item unit-item-ram")[4].innerText)*5;
542 nrTroupesDefender+=axe_aparare_spy+(light_aparare_spy) + (ram_aparare_spy);
543
544 if(nrTroupesDefender>1000)
545 typeDefender="off";
546
547
548
549 var spear_aparare_spy=parseInt(document.getElementsByClassName("unit-item unit-item-spear")[4].innerText);
550 var sword_aparare_spy=parseInt(document.getElementsByClassName("unit-item unit-item-sword")[4].innerText);
551 var archer_aparare_spy=parseInt(document.getElementsByClassName("unit-item unit-item-archer")[4].innerText);
552 var heavy_aparare_spy=parseInt(document.getElementsByClassName("unit-item unit-item-heavy")[4].innerText)*6;
553 var trupe_aparare_total=spear_aparare_total+sword_aparare_total+archer_aparare_total+heavy_aparare_total;
554 var total_aparare_spy=spear_aparare_spy+sword_aparare_spy+archer_aparare_spy+heavy_aparare_spy;
555
556 if(total_aparare_spy>1000){
557 typeDefender="def";
558 nrTroupesDefender=total_aparare_spy;
559 }
560 else if(axe_aparare_spy+light_aparare_spy <10 && axe_aparare_total+light_aparare_total<100 && trupe_aparare_total>5000 && total_aparare_spy<=1000){
561 typeDefender="def??";
562 }
563
564
565 }
566 reportInfo.typeDefender=typeDefender;
567 reportInfo.nrTroupesDefender=nrTroupesDefender;
568
569
570
571 if(!tribemates.includes(nameAttacker) && !reportInfo.typeAttacker.includes("?")){
572 // console.log("attacker")
573 mapObject.coord=coordAttacker;
574 mapObject.reportInfo=reportInfo;
575 listObject.push(mapObject);
576 mapObject={};
577 }
578 if(!tribemates.includes(nameDefender) && !reportInfo.typeDefender.includes("?")){
579 // console.log("defender")
580 mapObject.coord=coordDefender;
581 mapObject.reportInfo=reportInfo;
582 listObject.push(mapObject);
583 }
584 }
585 else if(document.getElementsByClassName("unit-item unit-item-axe").length==1)
586 {
587 var typeSupporter="?";
588 var nrTroupesSupporter=0;
589 let time_report=document.getElementsByClassName("vis")[3].firstElementChild.children[1].children[1].innerText;
590 if(new Date()-new Date(time_report)>14*3600*1000)//report too old
591 return listObject;
592 var report=document.getElementsByClassName("vis")[3].innerHTML;
593 report=lzw_encode(report);
594 reportInfo.time_report=time_report;
595 reportInfo.report=report;
596
597 var text=document.getElementsByClassName("vis")[3].innerText.split("\n");
598 var nameSupporter=text[3].split(":")[1].trim();
599 var coordSupporter=text[4].split(":")[1].trim().match(/[0-9]{3}\|[0-9]{3}/)[0];
600 var supporterPlayerId=document.getElementsByClassName("vis")[3].getElementsByTagName("a")[1].href.split("id=")[1]
601 // var supporterPlayerId=document.getElementsByClassName("village_anchor contexted")[0].getAttribute("data-player")
602
603 reportInfo.nameSupporter=nameSupporter;
604 reportInfo.coordSupporter=coordSupporter;
605 reportInfo.supporterPlayerId=supporterPlayerId;
606
607
608 var axe_total=parseInt(document.getElementsByClassName("unit-item unit-item-axe")[0].innerText);
609 var light_total=parseInt(document.getElementsByClassName("unit-item unit-item-light")[0].innerText)*4;
610 var ram_total=parseInt(document.getElementsByClassName("unit-item unit-item-ram")[0].innerText)*5;
611
612 var spear_total=parseInt(document.getElementsByClassName("unit-item unit-item-spear")[0].innerText);
613 var sword_total=parseInt(document.getElementsByClassName("unit-item unit-item-sword")[0].innerText);
614 var archer_total=parseInt(document.getElementsByClassName("unit-item unit-item-archer")[0].innerText);
615 var heavy_total=parseInt(document.getElementsByClassName("unit-item unit-item-heavy")[0].innerText)*6;
616
617 var total_atac=axe_total+light_total+ram_total;
618 var total_aparare=spear_total+sword_total+archer_total+heavy_total;
619
620 if(total_atac>total_aparare && total_atac>=200){
621 typeSupporter="off";
622 nrTroupesSupporter=total_atac;
623 }
624 else if(total_aparare>total_atac && total_aparare>=200){
625 typeSupporter="def";
626 nrTroupesSupporter=total_aparare;
627 }
628 reportInfo.typeSupporter=typeSupporter;
629 reportInfo.nrTroupesSupporter=nrTroupesSupporter;
630
631 if(!tribemates.includes(nameSupporter) && !reportInfo.typeSupporter.includes("?")){
632 // console.log("supporter")
633 mapObject.coord=coordSupporter;
634 mapObject.reportInfo=reportInfo;
635 listObject.push(mapObject);
636 }
637 }
638 else if(document.getElementsByClassName("unit-item unit-item-axe").length==0 || document.getElementsByClassName("g-recaptcha").length>0
639 ||document.getElementsByClassName("unit-item unit-item-axe")==undefined || checkContainsCaptcha(document)==true){//recaptcha
640 console.log("recapthca")
641 return null;
642 }
643
644 return listObject;
645 }
646 catch(e){
647 console.log("erorr in upload")
648 return 0;
649 }
650
651 }
652
653 function checkContainsCaptcha(docOrHtml) {
654 var foundCaptcha = false;
655 if (typeof docOrHtml == 'string') {
656 foundCaptcha = !!docOrHtml.match(/data\-bot\-protect=/);
657 } else {
658 let $doc = $(docOrHtml);
659 let $body = $doc.find('#ds_body');
660 foundCaptcha = $body.length && !!$body.data('bot-protect')
661 }
662
663 if (foundCaptcha) console.log('Found captcha!');
664 return foundCaptcha;
665 }
666
667 function calcDistance(coord1,coord2)
668 {
669 let x1=parseInt(coord1.split("|")[0])
670 let y1=parseInt(coord1.split("|")[1])
671 let x2=parseInt(coord2.split("|")[0])
672 let y2=parseInt(coord2.split("|")[1])
673
674 return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
675 }
676
677 ////////////////////////////////////////////////data compression////////////////////////////////////////////////////////////////////////////
678 function lzw_encode(s) {
679 var dict = {};
680 var data = (s + "").split("");
681 var out = [];
682 var currChar;
683 var phrase = data[0];
684 var code = 256;
685 for (var i=1; i<data.length; i++) {
686 currChar=data[i];
687 if (dict[phrase + currChar] != null) {
688 phrase += currChar;
689 }
690 else {
691 out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0));
692 dict[phrase + currChar] = code;
693 code++;
694 phrase=currChar;
695 }
696 }
697 out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0));
698 for (var i=0; i<out.length; i++) {
699 out[i] = String.fromCharCode(out[i]);
700 }
701 return out.join("");
702 }
703 ////////////////////////////////////////////////data decompression//////////////////////////////////////////////////////////////////////////
704
705 function lzw_decode(s) {
706 var dict = {};
707 var data = (s + "").split("");
708 var currChar = data[0];
709 var oldPhrase = currChar;
710 var out = [currChar];
711 var code = 256;
712 var phrase;
713 for (var i=1; i<data.length; i++) {
714 var currCode = data[i].charCodeAt(0);
715 if (currCode < 256) {
716 phrase = data[i];
717 }
718 else {
719 phrase = dict[currCode] ? dict[currCode] : (oldPhrase + currChar);
720 }
721 out.push(phrase);
722 currChar = phrase.charAt(0);
723 dict[code] = oldPhrase + currChar;
724 code++;
725 oldPhrase = phrase;
726 }
727 return out.join("");
728 }
729 ///////////////////////////////////////////////////////get request//////////////////////////////////////////////////////////////////////////
730 function httpGet(theUrl)
731 {
732 var xmlHttp = new XMLHttpRequest();
733 xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
734 xmlHttp.send( null );
735 return xmlHttp.responseText;
736 }
737
738 ///////////////////////////////////////////////////////get all incomings//////////////////////////////////////////////////////////////////////////
739
740 function getIncomings(){
741
742 if(document.getElementsByClassName("info").length>0)
743 $(".info").remove()
744 var current_href_incomings=window.location.href;
745 let index=window.location.href.lastIndexOf("game.php")
746 let incomings_href= window.location.href.substr(0,index)+"game.php?"+"screen=overview_villages&mode=incomings&type=all&subtype=attacks&group=0&page=-1";
747 if(current_href_incomings.includes("t="))
748 {
749 incomings_href+="&t="+current_href_incomings.split("t=")[1].split("&")[0];
750 }
751 console.log("currentLink")
752 console.log(incomings_href)
753 document.body.innerHTML=httpGet(incomings_href);
754 let list_href=[];
755 if(document.getElementsByClassName("vis")[1].getElementsByTagName("select").length>0){
756 Array.from(document.getElementsByClassName("vis")[1].getElementsByTagName("select")[0].options).forEach(el=>{
757 list_href.push(el.value);
758 })
759 list_href.pop();
760 }
761 else if(document.getElementsByClassName("paged-nav-item").length>0){
762 let arr=Array.from(document.getElementsByClassName("paged-nav-item"));
763 for(let i=0;i<arr.length;i++)
764 list_href.push(arr[i].getAttribute("href"))
765 }
766 else{
767 list_href.push(incomings_href)
768
769 }
770 if(document.getElementById("incomings_table")==null)
771 throw new Error("you don't have any incomings");
772
773 console.log(list_href)
774 let incomings_data=new Map();
775 list_href.forEach(href=>{
776 console.log(href)
777 document.body.innerHTML=httpGet(href)
778 let table_incomings=document.getElementById("incomings_table").getElementsByTagName("tbody")[0].children
779 for(let i=1;i<table_incomings.length-1;i++){
780 if(table_incomings[i].children[0].innerText!="--"){
781 let coord_dest=table_incomings[i].children[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
782 let coord_origin=table_incomings[i].children[2].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
783 let length_tr=table_incomings[i].children.length
784 let time_land=table_incomings[i].children[length_tr-2].innerText
785 let server_date=document.getElementById("serverDate").innerText.split("/")
786 let date_land="";
787 if(time_land.includes("today")){
788 date_land=server_date[1]+"/"+server_date[0]+"/"+server_date[2]+" "+time_land.split(" ")[2];
789 }
790 else if(time_land.includes("tomorrow")){
791 var tomorrow_date=new Date(server_date[1]+"/"+server_date[0]+"/"+server_date[2]);
792 tomorrow_date.setDate(tomorrow_date.getDate()+1);
793 date_land= ("0"+(tomorrow_date.getMonth()+1)).slice(-2)+"/"+("0"+tomorrow_date.getDate()).slice(-2)+"/"+tomorrow_date.getFullYear()+" "+time_land.split(" ")[2];
794 }else if(time_land.includes("on")){
795 var on=time_land.split(" ")
796 date_land=on[1].split(".")[1]+"/"+on[1].split(".")[0]+"/"+server_date[2]+" "+on[3];
797 }
798 // console.log(date_land)
799 if(!incomings_data.has(coord_origin)){
800 let list=[date_land]
801 incomings_data.set(coord_origin,list)
802
803 }else{
804 let list=incomings_data.get(coord_origin)
805 list.push(date_land)
806 incomings_data.set(coord_origin,list)
807 }
808 }
809 }
810 })
811 if(document.getElementById("incomings_table")!=null){
812 showButtons();
813 }
814
815 if( document.getElementsByClassName("g-recaptcha").length>0){//recaptcha
816 console.log("recapthca")
817 UI.ErrorMessage("recapthca, upload again")
818
819 return null;
820 }
821 document.body.innerHTML=httpGet(current_href_incomings);
822 return incomings_data;
823 }
824 ///////////////////////////////////////////////////////upload all incomings//////////////////////////////////////////////////////////////////////////
825
826 function uploadIncomings(){
827
828 $.get(file_incomigs, function (data) {
829 let map_incomings_dropbox=new Map(JSON.parse(data))
830 let keys_dropbox=Array.from(map_incomings_dropbox.keys());
831
832 let server_date=document.getElementById("serverDate").innerText.split("/")
833 let server_time=document.getElementById("serverTime").innerText
834 let current_date=new Date(server_date[1]+"/"+server_date[0]+"/"+server_date[2]+" "+server_time);
835 /////////////////////////////////eliminate old incomings from dropbox////////////////////////////////////
836 let start=new Date();
837 keys_dropbox.forEach(el=>{
838 let list=map_incomings_dropbox.get(el);
839 let update=false;
840 for(let i=0;i<list.length;i++){
841 let date_incomings=new Date(list[i])
842 console.log(date_incomings<current_date)
843 if(date_incomings<current_date){
844 list.splice(i,1);
845 i--;
846 update=true;
847 }
848 if(list[i]==""){
849 list.splice(i,1);
850 update=true;
851 }
852
853 }
854 if(update==true || list.length==0){
855 if(list.length==0)
856 map_incomings_dropbox.delete(el);
857 else{
858 map_incomings_dropbox.set(el,list);
859 }
860 }
861 })
862 let stop=new Date();
863 console.log(stop-start)
864 var incomings_data=getIncomings();
865 let keys_incomings=Array.from(incomings_data.keys());
866 keys_incomings.forEach(el=>{
867 let list=incomings_data.get(el)
868 if(map_incomings_dropbox.has(el)){//update
869 let list_dropbox=map_incomings_dropbox.get(el)
870 list_dropbox=list_dropbox.concat(list);
871 var list_concat =[...new Set([...list ,...list_dropbox])];
872 map_incomings_dropbox.set(el,list_concat);
873 }
874 else{//add
875 map_incomings_dropbox.set(el,list);
876 }
877 })
878 console.log(map_incomings_dropbox)
879 var data=JSON.stringify(Array.from(map_incomings_dropbox.entries()))
880 console.log("scris in test2")
881 // document.body.innerHTML=httpGet(current_href_incomings);
882 addWindow();
883 showButtons();
884 document.getElementById("progress_incomings").innerText=incomings_data.size+" villages";
885 document.getElementById("progress_all").innerText="done";
886 UI.SuccessMessage("upload incomings done","slow")
887 uploadFile(data,filename_incomings,dropboxToken)
888 }).fail(function(){
889 // alert("error upload")
890 UI.ErrorMessage("error upload incomings")
891 })
892 }
893
894
895 //////////////////////////////////////////////////////upload all data to dropbox/////////////////////////////////////////////////////////////////
896
897 function uploadFile(data,filename,dropboxToken)
898 {
899 var file = new Blob([data], {type: "plain/text"});
900 file.name=filename;
901 var xhr = new XMLHttpRequest();
902 xhr.upload.onprogress = function(evt) {
903 var percentComplete = parseInt(100.0 * evt.loaded / evt.total);
904 console.log(percentComplete)
905 };
906
907 xhr.onload = function() {
908 if (xhr.status === 200) {
909 var fileInfo = JSON.parse(xhr.response);
910 // Upload succeeded. Do something here with the file info.
911 UI.SuccessMessage("upload succes")
912 }
913 else {
914 var errorMessage = xhr.response || 'Unable to upload file';
915 // Upload failed. Do something here with the error.
916 UI.SuccessMessage("upload failed")
917 }
918 };
919
920 xhr.open('POST', 'https://content.dropboxapi.com/2/files/upload');
921 xhr.setRequestHeader('Authorization', 'Bearer ' + dropboxToken);
922 xhr.setRequestHeader('Content-Type', 'application/octet-stream');
923 xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
924 path: '/' + file.name,
925 mode: 'add',
926 autorename: true,
927 mode:'overwrite',
928 mute: false
929 }));
930
931 xhr.send(file);
932 }
933
934
935 //////////////////////////////////////////////////////buttons in incomings page/////////////////////////////////////////////////////////////////
936
937
938 function showButtons(){
939 if(document.getElementById("incomings_table")!=null){
940 $("#table_incomings").remove();
941 var incomingshtml=`
942
943 <table id="table_incomings" class="" border="1" style="width: 50%;">
944 <tbody>
945 <tr>
946 <td style="text-align:center; width:auto;">
947 <center style="margin:10px"><u><input class="btn" type="button" onclick="addWindow()"value="open upload"></center>
948 </td>
949 </tr>
950 <tr>
951 <td style="text-align:center; width:auto;">
952 <center style="margin:10px"><u><input class="btn" type="button" onclick="moreInfo()" value="more info"></center>
953 </td>
954 </tr>
955 <tr>
956 <td style="text-align:center; width:auto;">
957 <center style="margin:10px"><u><input class="btn" type="button" onclick="tagIncomings()" value="tag"></center>
958 </td>
959 </tr>
960 </tbody>
961 </table>
962 </div>`
963 $(".vis").eq(3).append(incomingshtml)
964
965
966 var link = document.createElement('link');
967 link.id = "style_popup";
968 link.rel = 'stylesheet';
969 link.type = 'text/css';
970 link.href = 'https://dl.dropboxusercontent.com/s/ki0zhogjf0705c3/style_popup.css';
971 link.media = 'all';
972 document.getElementsByTagName('head')[0].appendChild(link);
973 }
974
975
976
977
978 }
979 showButtons();
980
981 //////////////////////////////////////////////////////show info in incomings page/////////////////////////////////////////////////////////////////
982
983
984
985 function moreInfo(){
986 let map_reports_dropbox
987 let map_incomings_dropbox
988 $("#div_container").remove();
989
990 console.log("inainte")
991 $.ajax({
992 url: file_reports,
993 type: 'GET',
994 before:function(){
995 UI.InfoMessage("load reports..","fast")
996 },
997 complete:function(){
998 UI.SuccessMessage("done reports","fast")
999 },
1000 success: function(data_reports){
1001 map_reports_dropbox=new Map(JSON.parse(data_reports))
1002 console.log("get reports")
1003
1004 $.ajax({
1005 url: file_incomigs,
1006 type: 'GET',
1007 before:function(){
1008 UI.InfoMessage("load incomings..","fast")
1009 },
1010 complete:function(){
1011 UI.SuccessMessage("done incomings","fast")
1012 },
1013 success: function(data_incomings){
1014 console.log("get incomings")
1015 $(".tr_delimitator").remove();
1016 map_incomings_dropbox=new Map(JSON.parse(data_incomings))
1017 console.log(map_incomings_dropbox)
1018 if(document.getElementsByClassName("info").length>0)
1019 $(".info").remove()
1020 else{
1021 let start=new Date();
1022
1023 let table=document.getElementById("incomings_table").lastElementChild.children;
1024 let list=[];
1025 let map_nr_atacuri=new Map();
1026
1027 //adaugare o noua coloana
1028 let coloana_nr=table[0].insertCell(3);
1029 coloana_nr.innerHTML="<a href=# id='id_nr'> nr</a>";
1030 coloana_nr.className="info"
1031
1032 let coloana_tribe=table[0].insertCell(4);
1033 coloana_tribe.innerHTML="<a href=# id='id_nr_tr'> nr_tribe</a>";
1034 coloana_tribe.className="info"
1035
1036 let coloana_type=table[0].insertCell(5);
1037 coloana_type.innerHTML="<a href=# id='id_type'> type</a>";
1038 coloana_type.className="info"
1039
1040 let coloana_pop=table[0].insertCell(6);
1041 coloana_pop.innerHTML="<a href=# id='id_pop'>pop</a>";
1042 coloana_pop.className="info"
1043
1044 let coloana_time=table[0].insertCell(7);
1045 coloana_time.innerHTML="<a href=# id='id_time'>time</a>";
1046 coloana_time.className="info"
1047
1048 let coloana_report=table[0].insertCell(8);
1049 coloana_report.innerHTML="<a href=# id='id_report'>report</a>";
1050 coloana_report.className="info"
1051 var list_coord_player=[]
1052 for(let i=1;i<table.length-1;i++){
1053 let coord=table[i].children[2].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
1054 let player_id=table[i].children[table[i].children.length-4].children[0].href.split("player&id=")[1]
1055 list_coord_player.push({
1056 coord:coord,
1057 player_id:player_id
1058 })
1059 if(map_nr_atacuri.has(coord))
1060 map_nr_atacuri.set(coord,parseInt(map_nr_atacuri.get(coord)) +1);
1061 else
1062 map_nr_atacuri.set(coord,1);
1063 }
1064 var html_nr="?"
1065 var html_nr_tribe="0"
1066 var html_type="?"
1067 var html_pop="?"
1068 var html_time="?"
1069 var html_report="?"
1070
1071 for(let i=1;i<table.length-1;i++){
1072 let coord=list_coord_player[i-1].coord
1073 let player_id=list_coord_player[i-1].player_id
1074 html_nr="<h4>"+map_nr_atacuri.get(coord)+"</h4>";
1075
1076 if(map_reports_dropbox.has(coord) )
1077 {
1078 let idPlayer_dropbox
1079 let type_dropbox
1080 let nr_troupes_dropbox
1081 var obj=map_reports_dropbox.get(coord);
1082 if(coord == obj.coordAttacker){
1083 idPlayer_dropbox=obj.attackingPlayerId;
1084 type_dropbox=obj.typeAttacker;
1085 nr_troupes_dropbox=obj.nrTroupesAttacker
1086 }
1087 else if(coord == obj.coordDefender){
1088 idPlayer_dropbox=obj.defendingPlayerId;
1089 type_dropbox=obj.typeDefender;
1090 nr_troupes_dropbox=obj.nrTroupesDefender
1091 }
1092 else{
1093 idPlayer_dropbox=obj.supporterPlayerId
1094 type_dropbox=obj.typeSupporter;
1095 nr_troupes_dropbox=obj.nrTroupesSupporter
1096 }
1097
1098 if(idPlayer_dropbox == player_id)
1099 {
1100 let date_start=new Date(obj.time_report);
1101 let date_stop=new Date();
1102 let days=("00"+parseInt((date_stop-date_start)/(24*3600*1000))).slice(-3);
1103 let hours=("0"+parseInt((date_stop-date_start)/(3600*1000)%24)).slice(-2);
1104 let minutes=("0"+parseInt(((date_stop-date_start)/(60*1000)%60))).slice(-2);
1105 let seconds=( "0"+parseInt((((date_stop-date_start)/1000)%60))).slice(-2);
1106
1107 if(map_incomings_dropbox.has(coord)){
1108 let list_incomings=map_incomings_dropbox.get(coord)
1109 html_nr_tribe=" <center><h4 style='color:red'>"+list_incomings.length+"</h4></center>";
1110 }
1111 html_type=" <h4>"+type_dropbox+"</h4>"
1112 html_pop=" <h4>"+nr_troupes_dropbox+"</h4>"
1113 html_time=" <h4>"+days+":"+hours+":"+minutes+":"+seconds+"</h4>"
1114 html_report=`
1115 <div class="popup" onclick='var popup = document.getElementById("table`+i+`");popup.classList.toggle("show")'><h4>show</h4>
1116 <table class="popuptext" id="table`+i+'"'+
1117 lzw_decode(obj.report)+
1118 '</table></div>';
1119
1120 }
1121 }
1122 coloana_nr=table[i].insertCell(3);
1123 coloana_nr.innerHTML=html_nr
1124 coloana_nr.className="info test"
1125
1126 coloana_tribe=table[i].insertCell(4);
1127 coloana_tribe.innerHTML=html_nr_tribe
1128 coloana_tribe.className="info"
1129
1130 coloana_type=table[i].insertCell(5);
1131 coloana_type.innerHTML=html_type
1132 coloana_type.className="info"
1133
1134 coloana_pop=table[i].insertCell(6);
1135 coloana_pop.innerHTML=html_pop
1136 coloana_pop.className="info"
1137
1138 coloana_time=table[i].insertCell(7);
1139 coloana_time.innerHTML=html_time
1140 coloana_time.className="info"
1141
1142 coloana_report=table[i].insertCell(8);
1143 coloana_report.innerHTML=html_report
1144 coloana_report.className="info"
1145 }
1146
1147 var stop=new Date();
1148 console.log("add info: "+(stop-start))
1149 sortIncomings();
1150
1151 }
1152 }
1153 })
1154
1155 }
1156 });
1157 }
1158
1159 //////////////////////////////////////////////////////sort incomings by.. /////////////////////////////////////////////////////////////////
1160
1161 function sortIncomings()
1162 {
1163 var table=document.getElementById("incomings_table").lastElementChild.children;
1164 var new_table=document.getElementById("incomings_table").lastElementChild;
1165 var last_row=table[table.length-1];
1166 var list=[];
1167 var list_info=[]
1168 for(let i=1;i<table.length-1;i++){
1169 list.push(table[i]);
1170 }
1171
1172
1173 //sort by nr
1174 document.getElementById("id_nr").addEventListener("click",function()
1175 {
1176 var start=new Date();
1177
1178 $(".tr_delimitator").remove();
1179 list.sort( (a,b)=>{
1180 return (parseInt(a.children[3].innerText)<parseInt(b.children[3].innerText))?1:(parseInt(a.children[3].innerText)>parseInt(b.children[3].innerText))?-1:
1181 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
1182 });
1183
1184
1185 //add new table in page
1186 for(let i=0;i<list.length;i++)
1187 {
1188 new_table.appendChild(list[i]);
1189 }
1190 new_table.appendChild(last_row);
1191
1192 for(let i=0;i<list.length;i++)
1193 {
1194 list_info.push({
1195 coord_attacker:list[i].children[2].innerText,
1196 nr:parseInt(list[i].children[3].innerText),
1197 })
1198 }
1199 var pozitie=2;
1200 for(let i=0;i<list.length-1;i++)
1201 {
1202 let nr_atacuri=list_info[i].nr
1203 if(nr_atacuri>1 && list_info[i].coord_attacker !=list_info[i+1].coord_attacker)
1204 {
1205 var tableRef = document.getElementById("incomings_table").lastElementChild;
1206 var newRow = tableRef.insertRow(pozitie);
1207 newRow.className="tr_delimitator"
1208 for(let i=0; i<1;i++){
1209 let cell = newRow.insertCell();
1210 var delimitator = document.createTextNode('--');
1211 cell.appendChild(delimitator);
1212
1213 }
1214 pozitie++;
1215 }
1216 else if(nr_atacuri==1){
1217 break;
1218 }
1219 pozitie++;
1220 }
1221 var stop=new Date();
1222 console.log(stop-start)
1223 })
1224
1225 //sort by nr tribe
1226 document.getElementById("id_nr_tr").addEventListener("click",function()
1227 {
1228 var start=new Date();
1229
1230 $(".tr_delimitator").remove();
1231 list.sort( (a,b)=>{
1232 return (parseInt(a.children[4].innerText)<parseInt(b.children[4].innerText))?1:(parseInt(a.children[4].innerText)>parseInt(b.children[4].innerText))?-1:
1233 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
1234 });
1235
1236
1237 //add new table in page
1238 for(let i=0;i<list.length;i++)
1239 {
1240 new_table.appendChild(list[i]);
1241 }
1242 new_table.appendChild(last_row);
1243
1244 for(let i=0;i<list.length;i++)
1245 {
1246 list_info.push({
1247 coord_attacker:list[i].children[2].innerText,
1248 nr:parseInt(list[i].children[4].innerText),
1249 })
1250 }
1251 var pozitie=2;
1252 for(let i=0;i<list.length-1;i++)
1253 {
1254 let nr_atacuri=list_info[i].nr
1255 if(nr_atacuri>1 && list_info[i].coord_attacker !=list_info[i+1].coord_attacker)
1256 {
1257 var tableRef = document.getElementById("incomings_table").lastElementChild;
1258 var newRow = tableRef.insertRow(pozitie);
1259 newRow.className="tr_delimitator"
1260 for(let i=0; i<1;i++){
1261 let cell = newRow.insertCell();
1262 var delimitator = document.createTextNode('--');
1263 cell.appendChild(delimitator);
1264
1265 }
1266 pozitie++;
1267 }
1268 else if(nr_atacuri==1){
1269 break;
1270 }
1271 pozitie++;
1272 }
1273 var stop=new Date();
1274 console.log(stop-start)
1275 })
1276
1277
1278 //sort by type
1279 document.getElementById("id_type").addEventListener("click",function()
1280 {
1281 var start=new Date();
1282 $(".tr_delimitator").remove();
1283 list.sort( (a,b)=>{
1284 return (a.children[5].innerText<b.children[5].innerText)?1:(a.children[5].innerText>b.children[5].innerText)?-1:
1285 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
1286 });
1287
1288 //add new table in page
1289 for(let i=0;i<list.length;i++)
1290 {
1291 new_table.appendChild(list[i]);
1292 }
1293 new_table.appendChild(last_row);
1294
1295 var pozitie=2;
1296 for(let i=0;i<list.length-1;i++)
1297 {
1298 let type=list[i].children[5].innerText;
1299 if(type!="?" && list[i].children[5].innerText !=list[i+1].children[5].innerText)
1300 {
1301 var tableRef = document.getElementById("incomings_table").lastElementChild;
1302 var newRow = tableRef.insertRow(pozitie);
1303 newRow.className="tr_delimitator"
1304 for(let i=0; i<8;i++){
1305 let cell = newRow.insertCell();
1306 var delimitator = document.createTextNode('--');
1307 cell.appendChild(delimitator);
1308 }
1309 pozitie++;
1310 }
1311 pozitie++;
1312 }
1313 var stop=new Date();
1314 console.log(stop-start)
1315 })
1316
1317 //sort by nr pop
1318 document.getElementById("id_pop").addEventListener("click",function()
1319 {
1320 var start=new Date();
1321
1322 $(".tr_delimitator").remove();
1323 list.sort( (a,b)=>{
1324 if(a.children[6].innerText=="?")
1325 var a_comp=2000000;
1326 else
1327 var a_comp=parseInt(a.children[6].innerText);
1328
1329 if(b.children[6].innerText=="?")
1330 var b_comp=2000000;
1331 else
1332 var b_comp=parseInt(b.children[6].innerText);
1333
1334 return (a_comp>b_comp)?1:(a_comp<b_comp)?-1:
1335 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
1336 });
1337
1338 //add new table in page
1339 for(let i=0;i<list.length;i++)
1340 {
1341 new_table.appendChild(list[i]);
1342 }
1343 new_table.appendChild(last_row);
1344 var stop=new Date();
1345 console.log(stop-start)
1346 })
1347
1348 //sort by time
1349 document.getElementById("id_time").addEventListener("click",function()
1350 {
1351 var start=new Date();
1352
1353 $(".tr_delimitator").remove();
1354
1355 list.sort( (a,b)=>{
1356 if(a.children[7].innerText=="?")
1357 var a_comp=10000000000;
1358 else{
1359 var v=a.children[7].innerText.split(":");
1360 var a_comp=parseInt(v[0])*24*3600+parseInt(v[1])*3600 +parseInt(v[2])*60 +parseInt(v[3]);
1361 }
1362
1363 if(b.children[7].innerText=="?")
1364 var b_comp=10000000000;
1365 else{
1366 var v=b.children[7].innerText.split(":");
1367 var b_comp=parseInt(v[0])*24*3600+parseInt(v[1])*3600 +parseInt(v[2])*60 +parseInt(v[3]);
1368 }
1369
1370 return (a_comp>b_comp)?1:(a_comp<b_comp)?-1:
1371 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
1372 });
1373
1374 //add new table in page
1375 for(let i=0;i<list.length;i++)
1376 {
1377 new_table.appendChild(list[i]);
1378 }
1379 new_table.appendChild(last_row);
1380 var stop=new Date();
1381 console.log(stop-start)
1382 })
1383 }
1384
1385 //////////////////////////////////////////////////////tag incomings /////////////////////////////////////////////////////////////////
1386
1387 function tagIncomings(){
1388
1389 if(document.getElementsByClassName("info").length==0){
1390 UI.ErrorMessage("press first the button 'more info'!")
1391 }
1392 else{
1393 $(".tr_delimitator").remove();
1394 let csrf = window.csrf_token;
1395 var list_incomings_href=[]
1396 var indexIncoming=1;
1397 var table_incomings=document.getElementById("incomings_table").children[1].children
1398 var speedWorld=1;
1399 var speedTroupes=1;
1400 var nobleSpeed=2100*1000/(speedWorld*speedTroupes)//ms
1401 var ramSpeed=1800*1000/(speedWorld*speedTroupes)//ms
1402 var swordSpeed=1260*1000/(speedWorld*speedTroupes)//ms
1403 var axeSpeed=1080*1000/(speedWorld*speedTroupes)//ms
1404
1405 for(let i=1;i<table_incomings.length-1;i++){
1406 let incomingId=table_incomings[i].children[0].children[2].getAttribute("data-id");
1407 let coordOrigin=table_incomings[i].children[2].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
1408 let href=window.location.href.split("&")[0]+`&screen=info_command&ajaxaction=edit_other_comment&id=${incomingId}&h=${csrf}`
1409 var nameTroupe=table_incomings[i].children[0].innerText.trim().split(/\s+/)[0];
1410 let nr=parseInt(table_incomings[i].children[3].innerText);
1411 let nr_tribe=table_incomings[i].children[4].innerText;
1412 let type=table_incomings[i].children[5].innerText;
1413 let pop=parseInt(table_incomings[i].children[6].innerText);
1414 let time=table_incomings[i].children[7].innerText;
1415 let length_tr=table_incomings[i].children.length
1416 let nameAttacker=table_incomings[i].children[length_tr-4].innerText
1417 ////////////////////////////////get land time///////////////////////////////
1418 let time_land=table_incomings[i].children[length_tr-2].innerText
1419 let server_date=document.getElementById("serverDate").innerText.split("/")
1420 let date_land="";
1421 if(time_land.includes("today")){
1422 date_land=server_date[1]+"/"+server_date[0]+"/"+server_date[2]+" "+time_land.split(" ")[2];
1423 }
1424 else if(time_land.includes("tomorrow")){
1425 var tomorrow_date=new Date(server_date[1]+"/"+server_date[0]+"/"+server_date[2]);
1426 tomorrow_date.setDate(tomorrow_date.getDate()+1);
1427 date_land= ("0"+(tomorrow_date.getMonth()+1)).slice(-2)+"/"+("0"+tomorrow_date.getDate()).slice(-2)+"/"+tomorrow_date.getFullYear()+" "+time_land.split(" ")[2];
1428 }else if(time_land.includes("on")){
1429 var on=time_land.split(" ")
1430 date_land=on[1].split(".")[1]+"/"+on[1].split(".")[0]+"/"+server_date[2]+" "+on[3];
1431 }
1432 let fake=false;
1433
1434
1435 if(table_incomings[i].getElementsByClassName("possible_fake").length>0 && table_incomings[i].children[0].getElementsByTagName("img").length==2){
1436 let date_home=new Date(table_incomings[i].getElementsByClassName("possible_fake")[0].getAttribute("date-fake"))
1437 let distance=parseFloat(table_incomings[i].children[length_tr-3].innerText);
1438 let labelName=table_incomings[i].children[0].getElementsByTagName("img")[1].src
1439 let time_attack=0;
1440 if(labelName.includes("snob.png")){
1441 time_attack=nobleSpeed*distance
1442 }else if(labelName.includes("ram.png")){
1443 time_attack=ramSpeed*distance
1444 }else if(labelName.includes("sword.png")){
1445 time_attack=swordSpeed*distance
1446 }else if(labelName.includes("axe.png")){
1447 time_attack=axeSpeed *distance
1448 }
1449
1450 let dateLand=new Date(date_land)
1451 if(time_attack+date_home.getTime()>dateLand.getTime() ){
1452 fake=true;
1453 console.log("fake from "+coordOrigin)
1454 }
1455 console.log(time_attack)
1456 }
1457
1458 let obj={
1459 incomingId:incomingId,
1460 coordOrigin:coordOrigin,
1461 href:href,
1462 nameTroupe:nameTroupe,
1463 nr:nr,
1464 nr_tribe:nr_tribe,
1465 type:type,
1466 pop:pop,
1467 time:time,
1468 nameAttacker:nameAttacker,
1469 fake:fake,
1470 }
1471 if(!table_incomings[i].children[0].innerText.toLowerCase().includes("attack"))
1472 list_incomings_href.push(obj)
1473 }
1474 list_incomings_href=list_incomings_href.reverse();
1475
1476 var url_length=list_incomings_href.length
1477 function ajaxRequest (urls) {
1478 let current_url
1479 let labelInfo=""
1480 let obj=null
1481 if(urls.length>0){
1482 obj=urls.pop()
1483 let clientTime = Math.round(new Date().valueOf() / 1000);
1484 current_url+="&"+clientTime
1485 current_url=obj.href;
1486 labelInfo=obj.nameTroupe;
1487 let nr
1488 if(obj.nr_tribe=="?")
1489 nr=parseInt(obj.nr)
1490 else
1491 nr=parseInt(obj.nr_tribe)
1492
1493 if(obj.type!="?"){
1494 obj.pop= Math.round(((parseInt(obj.pop)/1000)*10)/10)+"k"
1495 obj.time=parseInt(obj.time.split(":")[0]);
1496
1497 if(obj.type=="new_off")
1498 labelInfo=labelInfo+" "+obj.nameAttacker+" nr="+nr+", type= off";
1499 else if(obj.type.includes("def"))
1500 labelInfo=labelInfo+" "+obj.nameAttacker+" nr="+nr+", type= "+obj.type+", time= "+obj.time+" days";
1501 else
1502 labelInfo=labelInfo+" "+obj.nameAttacker+" nr="+nr+", type= "+obj.type+", pop= "+obj.pop+", time= "+obj.time+" days"
1503 }
1504 else{
1505 labelInfo=labelInfo+" "+obj.nameAttacker+" nr= "+nr
1506 }
1507 if(obj.fake==true){
1508 labelInfo+=" (fake)";
1509 }
1510 console.log(labelInfo)
1511 }
1512 else{
1513 current_url="stop"
1514 }
1515 console.log("in functie in plm "+urls.length)
1516 // console.log(current_url)
1517
1518 if (urls.length >= 0 && current_url!="stop") {
1519 console.log("rename "+labelInfo)
1520 $.ajax({
1521 url: current_url,
1522 method: 'POST',
1523 dataType: "json",
1524 data: { text: labelInfo },
1525 headers: { 'TribalWars-Ajax': 1 },
1526 success: (data) => {
1527 $("span[data-id="+obj.incomingId+"]").find(".quickedit-label").text(labelInfo)
1528 UI.InfoMessage(indexIncoming+"/"+url_length)
1529 indexIncoming++;
1530 ajaxRequest (list_incomings_href)
1531 }
1532 })
1533
1534 }
1535 else
1536 {
1537 UI.SuccessMessage("done",2000)
1538
1539 }
1540 }
1541 ajaxRequest(list_incomings_href);
1542
1543 }
1544
1545
1546 }
1547
1548 //////////////////////////////////////////////////////search reports /////////////////////////////////////////////////////////////////
1549
1550 var map_search
1551 function loadReports(){
1552 $.get(file_reports, function (data) {
1553 map_search=new Map(JSON.parse(data));
1554 console.log(map_search)
1555 loadReportsOk=true;
1556 $("#input_search").on("input",function(){
1557 let current_value=$("#input_search").val()
1558 if(current_value.match(/[0-9]{3}\|[0-9]{3}/)!=null){
1559 coords=current_value.match(/[0-9]{3}\|[0-9]{3}/g)
1560 console.log(coords)
1561 $("#report_view").empty()
1562 let contentHtml=""
1563 let nr_found=0;
1564 for(let i=0;i<coords.length;i++){
1565 if(map_search.has(coords[i])){
1566 let obj=map_search.get(coords[i]);
1567 console.log(coords[i])
1568 let report=lzw_decode(obj.report);
1569 contentHtml+= `<div>
1570 <center style="margin:10px"><input class="btn evt-confirm-btn btn-confirm-yes" type="button"onclick="$('#table`+i+`').toggle('slow')" value="`+coords[i]+`"></center>
1571
1572 <table class="table_hide" id="table`+i+'"'+
1573 report+
1574 `</table></div>`;
1575 nr_found++;
1576 }
1577 }
1578 $("#report_view").append(contentHtml)
1579 $(".table_hide").hide();
1580 $("#progress_search").text("found: "+nr_found)
1581 }else{
1582 $("#report_view").empty()
1583 }
1584
1585 })
1586 $("#input_search").mouseout(function(){
1587 let current_value=$("#input_search").val()
1588 if(current_value.match(/[0-9]{3}\|[0-9]{3}/)!=null){
1589 let coords=current_value.match(/[0-9]{3}\|[0-9]{3}/g)
1590 $("#input_search").val(Array.from(coords).join(","))
1591 }
1592 })
1593
1594
1595
1596 }).done(function(){
1597 UI.SuccessMessage("load reports","fast")
1598
1599 })
1600 }
1601
1602