Advertisement
madalino

fakeScriptInterface

Feb 14th, 2022
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 116.86 KB | None | 0 0
  1. var dropboxToken='voeQxDKEfdAAAAAAAAAAAWmeVbsqR6fFyKdfA2gXF05UhEt-ztkJqkFZY6PkMTzk';
  2.  
  3.  
  4.  
  5. var units=game_data.units;
  6. var unitsLength=units.length;
  7. if(units.includes("snob"))
  8. unitsLength--;
  9. if(units.includes("militia"))
  10. unitsLength--;
  11. if(units.includes("knight"))
  12. unitsLength--;
  13.  
  14. var nrTabs=10;
  15.  
  16. var troupesPop = {
  17. spear : 1,
  18. sword : 1,
  19. axe : 1,
  20. archer : 1,
  21. spy : 2,
  22. light : 4,
  23. marcher : 5,
  24. heavy : 6,
  25. ram : 5,
  26. catapult : 8,
  27. knight : 10,
  28. snob : 100
  29. };
  30.  
  31. var databaseName="testFakes/"
  32.  
  33. var filname_ally=`${databaseName}ally.txt`
  34. var filname_admin=`${databaseName}admin.txt`
  35. var filname_ino_db=`${databaseName}ino_database.txt`
  36.  
  37. var filename_fakes1=`${databaseName}fakes1.txt`
  38. var filename_fakes2=`${databaseName}fakes2.txt`
  39. var filename_fakes3=`${databaseName}fakes3.txt`
  40. var filename_fakes4=`${databaseName}fakes4.txt`
  41. var filename_fakes5=`${databaseName}fakes5.txt`
  42. var filename_fakes6=`${databaseName}fakes6.txt`
  43. var filename_fakes7=`${databaseName}fakes7.txt`
  44. var filename_fakes8=`${databaseName}fakes8.txt`
  45. var filename_fakes9=`${databaseName}fakes9.txt`
  46. var filename_fakes10=`${databaseName}fakes10.txt`
  47.  
  48.  
  49.  
  50. var list_filename_fakes=[filename_fakes1, filename_fakes2, filename_fakes3, filename_fakes4, filename_fakes5, filename_fakes6,filename_fakes7,filename_fakes8,filename_fakes9,filename_fakes10]
  51.  
  52. var speedWorld=getSpeedConstant().worldSpeed;
  53. var speedTroupes=getSpeedConstant().unitSpeed;
  54. var nobleSpeed=2100*1000/(speedWorld*speedTroupes)//ms
  55. var ramSpeed=1800*1000/(speedWorld*speedTroupes)//ms
  56. var swordSpeed=1320*1000/(speedWorld*speedTroupes)//ms
  57. var axeSpeed=1080*1000/(speedWorld*speedTroupes)//ms
  58. var lightSpeed=600*1000/(speedWorld*speedTroupes)//ms
  59. var scoutSpeed=540*1000/(speedWorld*speedTroupes)//ms
  60.  
  61. var dropbox_ally=getAlly()
  62. var dropbox_admin=getAdmin()
  63. var nrTroopSelect=13
  64.  
  65. var loginAlly=JSON.parse((dropbox_ally=="")?"[]":dropbox_ally ).map(e=>{return e.allyId})
  66. var loginAdmin=JSON.parse((dropbox_admin=="")?"[]":dropbox_admin ).map(e=>{return e.adminId})
  67. var adminBoss=game_data.player.id
  68. var runWorld=game_data.world
  69. if(!((loginAlly.includes(game_data.player.ally)==true || game_data.player.id==adminBoss ) && game_data.world==runWorld)){
  70. UI.ErrorMessage("try later")
  71. throw new Error('try later');
  72. }
  73.  
  74.  
  75. checkPageRun()
  76.  
  77. var headerWood="#001a33"
  78. var headerWoodEven="#002e5a"
  79. var headerStone="#3b3b00"
  80. var headerStoneEven="#626200"
  81. var headerIron="#1e003b"
  82. var headerIronEven="#3c0076"
  83.  
  84.  
  85. var defaultTheme= '[["theme1",["#E0E0E0","#000000","#C5979D","#2B193D","#2C365E","#484D6D","#4B8F8C"]],["currentTheme","theme1"],["theme2",["#E0E0E0","#000000","#F76F8E","#113537","#37505C","#445552","#294D4A"]],["theme3",["#E0E0E0","#000000","#ACFCD9","#190933","#665687","#7C77B9","#623B5A"]],["theme4",["#E0E0E0","#000000","#181F1C","#60712F","#274029","#315C2B","#214F4B"]],["theme5",["#E0E0E0","#000000","#9AD1D4","#007EA7","#003249","#1F5673","#1C448E"]],["theme6",["#E0E0E0","#000000","#EA8C55","#81171B","#540804","#710627","#9E1946"]],["theme7",["#E0E0E0","#000000","#754043","#37423D","#171614","#3A2618","#523A34"]],["theme8",["#E0E0E0","#000000","#9E0031","#8E0045","#44001A","#600047","#770058"]],["theme9",["#E0E0E0","#000000","#C1BDB3","#5F5B6B","#323031","#3D3B3C","#575366"]],["theme10",["#E0E0E0","#000000","#E6BCCD","#29274C","#012A36","#14453D","#7E52A0"]]]'
  86.  
  87. var localStorageThemeName = "fakesTheme"
  88. var textColor="#ffffff"
  89. var backgroundInput="#000000"
  90.  
  91. var borderColor = "#C5979D";//#026440
  92. var backgroundContainer="#2B193D"
  93. var backgroundHeader="#2C365E"
  94. var backgroundMainTable="#484D6D"
  95. var backgroundInnerTable="#4B8F8C"
  96.  
  97. var widthInterface=50;//percentage
  98. var headerColorDarken=-50 //percentage( how much the header should be darker) if it's with -(darker) + (lighter)
  99. var headerColorAlternateTable=-30;
  100. var headerColorAlternateHover=30;
  101.  
  102. var backgroundAlternateTableEven=backgroundContainer;
  103. var backgroundAlternateTableOdd=getColorDarker(backgroundContainer,headerColorAlternateTable);
  104.  
  105. async function main(){
  106. initializationTheme()
  107. let status = await $.getScript("https://dl.dropboxusercontent.com/s/i5c0so9hwsizogm/styleCSSGlobal.js?dl=0");
  108. console.log("status: "+status)
  109. createMainInterface()
  110. changeTheme()
  111. addEventPanel();
  112. addNewPanel();
  113. getCoordsEvent();
  114. initializationOwnTabs()
  115. saveNrFakes();
  116. initializationNrFakes()
  117. initializationTroupes()
  118. initializationOptionAttack();
  119. getCoordDropbox()
  120. getFakeLimit()
  121.  
  122. console.log("login admin")
  123. console.log(loginAdmin)
  124. if(((loginAdmin.includes(game_data.player.id)==true || game_data.player.id==adminBoss) && game_data.world==runWorld)){
  125. $("#div_ally").show()
  126. $("#div_ally").on("mouseup",()=>{
  127. adminInterfaceAlly()
  128. $("#div_ally").off("mouseup")
  129. })
  130.  
  131. $("#div_admin").show()
  132. $("#div_admin").on("mouseup",()=>{
  133. adminInterface()
  134. $("#div_admin").off("mouseup")
  135. })
  136. }
  137. if(((loginAdmin.includes(game_data.player.id)==true || game_data.player.id==adminBoss) && game_data.world==runWorld)){
  138. saveCoordDropbox();
  139. }
  140.  
  141. }
  142. main()
  143.  
  144.  
  145. function getColorDarker(hexInput, percent) {
  146. let hex = hexInput;
  147.  
  148. // strip the leading # if it's there
  149. hex = hex.replace(/^\s*#|\s*$/g, "");
  150.  
  151. // convert 3 char codes --> 6, e.g. `E0F` --> `EE00FF`
  152. if (hex.length === 3) {
  153. hex = hex.replace(/(.)/g, "$1$1");
  154. }
  155.  
  156. let r = parseInt(hex.substr(0, 2), 16);
  157. let g = parseInt(hex.substr(2, 2), 16);
  158. let b = parseInt(hex.substr(4, 2), 16);
  159.  
  160. const calculatedPercent = (100 + percent) / 100;
  161.  
  162. r = Math.round(Math.min(255, Math.max(0, r * calculatedPercent)));
  163. g = Math.round(Math.min(255, Math.max(0, g * calculatedPercent)));
  164. b = Math.round(Math.min(255, Math.max(0, b * calculatedPercent)));
  165.  
  166. return `#${("00"+r.toString(16)).slice(-2).toUpperCase()}${("00"+g.toString(16)).slice(-2).toUpperCase()}${("00"+b.toString(16)).slice(-2).toUpperCase()}`
  167. }
  168.  
  169.  
  170.  
  171.  
  172. function httpGet(theUrl)
  173. {
  174. var xmlHttp = new XMLHttpRequest();
  175. xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
  176. xmlHttp.send( null );
  177. return xmlHttp.responseText;
  178. }
  179.  
  180.  
  181.  
  182. //////////////////////////////////////////////////////////// interface /////////////////////////////////////////////////////////
  183. function createMainInterface(){
  184. let fakeLimit=getFakeLimit()
  185. console.log("createInterface")
  186.  
  187. html = `
  188. <div id="div_container" class="scriptContainer" >
  189. <div class="scriptHeader">
  190. <div style=" margin-top:10px;"><h2>Fakes/Nukes/Fangs Script</h2></div>
  191. <div style="position:absolute;top:10px;right: 10px;"><a href="#" onclick="$('#div_container').remove()"><img src="https://img.icons8.com/emoji/24/000000/cross-mark-button-emoji.png"/></a></div>
  192. <div style="position:absolute;top:8px;right: 35px;" id="div_minimize"><a href="#"><img src="https://img.icons8.com/plasticine/28/000000/minimize-window.png"/></a></div>
  193. <div style="position:absolute;top:10px;right: 60px;" id="div_theme"><a href="#" onclick="$('#theme_settings').toggle()"><img src="https://img.icons8.com/material-sharp/24/fa314a/change-theme.png"/></a></div>
  194.  
  195. <div class="close-btn" id="page_admin" style="position:absolute;top:10px;left: 10px;">
  196. <div style="background-color:white" id="div_ally" hidden>
  197. <b><a href=#><img src="https://img.icons8.com/emoji/16/000000/plus-emoji.png" onclick="$('#table_admin2').hide();"/></a></b>
  198. </div>
  199. </div>
  200. <div class="close-btn" id="page_admin2" style="position:absolute;top:10px;left: 40px;">
  201. <div style="background-color:white" id="div_admin" hidden>
  202. <b><a href=#><img src="https://img.icons8.com/emoji/16/000000/plus-emoji.png" onclick="$('#table_admin').hide();"/></a></b>
  203. </div>
  204. </div>
  205.  
  206. <div style="margin:0px;position:absolute;top:10px;left: 70px;" class="set_troops">
  207. <select id="select_type_attack">
  208. <option value="fakes">fakes</option>
  209. <option value="nukes">nukes</option>
  210. <option value="fangs">fangs</option>
  211. </select>
  212. </div>
  213. </div>
  214. <div id="theme_settings"></div>
  215.  
  216. <div id="div_body" style="height: 750px; overflow-y: auto">
  217. <br>
  218. <div id="div_admin_show">
  219. </div>
  220. <br>
  221.  
  222.  
  223. <table id="table_upload" class="scriptTable">
  224. <tr>
  225. <td></td>`;
  226. for(let i=0;i<units.length;i++){
  227. if(units[i]!="militia" && units[i]!="snob"){
  228. html+=`<td class="fm_unit hide_${units[i]}"><img src="https://dsen.innogamescdn.com/asset/1d2499b/graphic/unit/unit_${units[i]}.png"></td>`
  229. }
  230. }
  231. //create select for fakes
  232. html+=`</tr>
  233. <tr id="allSelectTroupes" class="set_troops hide_fakes">
  234. <td>send</td>`
  235. for(let i=0;i<units.length;i++){
  236. if(units[i]!="militia" && units[i]!="snob"){
  237. html+=`
  238. <td class="hide_${units[i]}">
  239. <select id="${units[i]}Troupe" class='allTroupes' >
  240. <option value="min" >min</option>`
  241. for(let j=0;j<nrTroopSelect;j++){
  242. html+=`<option value="${j}">${j}</option>
  243. `
  244. }
  245. `</select>
  246. </td>`
  247.  
  248. }
  249. }
  250.  
  251. html+=`
  252. </tr>
  253. <tr class="set_troops hide_fakes" >
  254. <td colspan="6">fakes per village (only if interval time is on)</td>
  255. <td colspan="3">
  256. <input class="scriptInput" type="number" id="nr_fakes_per_village" placeholder="5" value="5">
  257. </td>
  258. </tr>
  259.  
  260.  
  261.  
  262. <tr class="set_troops hide_fakes">
  263. <td colspan="3">
  264. <input type="checkbox" value="land_specific"><font color="${textColor}"> attacks land between:</font>
  265. </td>
  266. <td colspan="3">
  267. <input type="datetime-local" class="start_window" style="text-align:center;" >
  268. </td>
  269. <td colspan="3">
  270. <input type="datetime-local" class="stop_window" style="text-align:center;" >
  271. </td>
  272. </tr>
  273. `
  274.  
  275. //create inputs for nukes
  276. html+=`<tr hidden> </tr>
  277. <tr class="set_troops hide_nukes allinputTroops" >
  278. <td>send</td>`
  279.  
  280. for(let i=0;i<units.length;i++){
  281. if( units[i]!="militia" && units[i]!="snob"){
  282. html+=`
  283. <td class="hide_${units[i]}">
  284. <input class="scriptInput" type="number" placeholder="0" value="0">
  285. </td>`
  286.  
  287. }
  288. }
  289. html+=`</tr>
  290. <tr class="set_troops hide_nukes allinputTroopsRes">
  291. <td>reserve</td>`
  292. for(let i=0;i<units.length;i++){
  293. if(units[i]!="militia" && units[i]!="snob"){
  294. html+=`
  295. <td class="hide_${units[i]}">
  296. <input class="scriptInput" type="number" placeholder="0" value="0">
  297. </td>`
  298.  
  299. }
  300. }
  301. html+=`
  302. </tr>
  303. <tr class="set_troops hide_nukes" >
  304. <td colspan="5">min population(nukes/fangs only)</td>
  305. <td colspan="4">
  306. <input class="scriptInput" type="number" class="min_pop" placeholder="500" value="500">
  307. </td>
  308. </tr>
  309.  
  310. <tr class="set_troops hide_nukes">
  311. <td colspan="3">
  312. <input type="checkbox" value="land_specific"><font color="${textColor}"> attacks land between:</font>
  313. </td>
  314. <td colspan="3">
  315. <input type="datetime-local" class="start_window" style="text-align:center;" >
  316. </td>
  317. <td colspan="3">
  318. <input type="datetime-local" class="stop_window" style="text-align:center;" >
  319. </td>
  320. </tr>
  321.  
  322. `
  323. //create inputs for fangs
  324. html+=`</tr >
  325. <tr class="set_troops hide_fangs allinputTroops" >
  326. <td>send</td>`
  327.  
  328. for(let i=0;i<units.length;i++){
  329. if( units[i]!="militia" && units[i]!="snob"){
  330. html+=`
  331. <td align='center' class="hide_${units[i]}">
  332. <input class="scriptInput" type="number" placeholder="0" value="0">
  333. </td>`
  334. }
  335. }
  336. html+=`</tr>
  337. <tr class="set_troops hide_fangs allinputTroopsRes">
  338. <td>reserve</td>`
  339. for(let i=0;i<units.length;i++){
  340. if(units[i]!="militia" && units[i]!="snob"){
  341. html+=`
  342. <td class="hide_${units[i]}">
  343. <input class="scriptInput" type="number" placeholder="0" value="0">
  344. </td>`
  345. }
  346. }
  347.  
  348.  
  349.  
  350.  
  351. html+=`
  352. <tr class="set_troops hide_fangs" >
  353. <td colspan="5">min population(nukes/fangs only)</td>
  354. <td colspan="4">
  355. <input class="scriptInput" type="number" class="min_pop" placeholder="500" value="500">
  356. </td>
  357. </tr>
  358. <tr class="set_troops hide_fangs">
  359. <td colspan="3">
  360. <input type="checkbox" value="land_specific"><font color="${textColor}"> attacks land between:</font>
  361. </td>
  362. <td colspan="3">
  363. <input type="datetime-local" class="start_window" style="text-align:center;" >
  364. </td>
  365. <td colspan="3">
  366. <input type="datetime-local" class="stop_window" style="text-align:center;" >
  367. </td>
  368. </tr>
  369. </table>
  370. <br>
  371. `
  372.  
  373.  
  374.  
  375.  
  376. //create panels
  377. html+=`
  378.  
  379. <div class="tab-panels" id="tabs_coord" >
  380. <ul class="tabs">
  381. <li class="update_tab own active" rel="panel${nrTabs}" ><font >panel${nrTabs} </font > <img class="remove_tab" src="https://img.icons8.com/doodle/16/000000/delete-sign.png"/> </li>
  382. <li id="add_tab"><img src="https://img.icons8.com/color/16/000000/add-tab.png"/> </li>
  383. </ul>
  384.  
  385. <div id="all_tabs">`
  386. for(let i=0;i<nrTabs;i++){
  387. html+=`
  388. <div id="panel${i}" class="panel">
  389. <p style="color:${textColor};font-weight: bold;">saved by player on date</p>
  390. <p style="color:${textColor};font-weight: bold;">nr coords:</p>
  391. <center style="margin:5px"><textarea class="scriptInput" rows="10">panelTribe${i}</textarea></center>`
  392. if(((loginAdmin.includes(game_data.player.id)==true || game_data.player.id==adminBoss) && game_data.world==runWorld)){
  393. html+=`<center style="margin:5px"><input class="btn evt-confirm-btn btn-confirm-yes" type="button" value="Save"></center>`
  394. }
  395. html+='</div>'
  396. }
  397. html+=`
  398. <div id="panel${nrTabs}" class="panel own active">
  399. <p style="color:${textColor};font-weight: bold;">nr coords:</p>
  400. <center style="margin:5px"><textarea class="scriptInput" rows="10">panel${nrTabs}</textarea><center>
  401. </div>
  402. </div>
  403.  
  404. <ul class="tabs">`
  405.  
  406. for(let i=0;i<nrTabs;i++){
  407. html+=`<li class="li_tribe" rel="panel${i}" ><font>panelTribe${i}</font></li>`
  408. }
  409.  
  410.  
  411. html+=`</ul>
  412.  
  413. <br>
  414. <table class="scriptTableAlternate" style="width:95%">
  415. <tr hidden><tr>
  416. <tr >
  417. <td class="hide_fakes">nr fakes:</td>
  418. <td class="hide_fakes"><input class="scriptInput" id="nr_fakes" type="number" value="1"></td>
  419. <td class="hide_fakes"></td>
  420. <td class="hide_fakes"></td>
  421. </tr>
  422. <tr >
  423. <td>split tabs:</td>
  424. <td><input class="scriptInput" id="nr_split" type="number" value="20"></td>
  425. <td>
  426. <select id="select_option_fakes" >
  427. <option value="open tabs">open tabs</option>
  428. <option value="go to rally">go to rally</option>
  429. </select>
  430. </td >
  431. <td><input class="btn evt-confirm-btn btn-confirm-yes" type="button" id="btn_start" onclick="startFakes()" value="Start"></td>
  432. <td class="hide_btn_show" hidden><input class="btn evt-confirm-btn btn-confirm-yes" type="button" id="btn_show" value="Show" ></td>
  433. <td class="hide_btn_delete" hidden><input class="btn evt-confirm-btn btn-confirm-yes" type="button" id="btn_delete" value="Delete" ></td>
  434. </tr>
  435. <tr >
  436. <td>delay open tabs[ms]:</td>
  437. <td><input class="scriptInput" id="delay_tabs" type="number" value="200"></td>
  438. <td></td>
  439. <td></td>
  440. </tr>
  441. </table>
  442.  
  443. <div id="div_open_tabs" >
  444. <h2 id="h2_tabs"><center style="margin:10px"><u><font color="${textColor}">Open Tabs</font></u></center></h2>
  445. </div>
  446. </div>
  447. </div>
  448. <div class="scriptFooter">
  449. <div style=" margin-top:5px;"><h5>made by Costache</h5></div>
  450. </div>
  451. </div>
  452.  
  453. `;
  454. ////////////////////////////////////////add and remove window from page///////////////////////////////////////////
  455.  
  456.  
  457.  
  458. $("#div_container").remove()
  459. $("#contentContainer").eq(0).prepend(html);
  460. $("#mobileContent").eq(0).prepend(html);
  461.  
  462.  
  463. $("#div_container").css("position","fixed");
  464. $("#div_container").draggable();
  465.  
  466.  
  467. $("#div_minimize").on("click",()=>{
  468. let currentWidthPercentage=Math.ceil($('#div_container').width() / $('body').width() * 100);
  469. if(currentWidthPercentage >=widthInterface ){
  470. $('#div_container').css({'width' : '10%'});
  471. $('#div_body').hide();
  472. }
  473. else{
  474. $('#div_container').css({'width' : `${widthInterface}%`});
  475. $('#div_body').show();
  476. }
  477. })
  478. //disable selects if fake limit is off
  479. if(fakeLimit==0){
  480. for(let i=0;i<units.length;i++){
  481. if(units[i]!="spy" && units[i]!="ram" && units[i]!="catapult"){
  482. console.log($(`${units[i]}Troupe`))
  483. $(`#${units[i]}Troupe`).attr("disabled", true);
  484. }
  485. }
  486. }
  487. let select_type=document.getElementById("select_type_attack").value
  488. if(select_type == "fakes" && localStorage.getItem(game_data.world+"troopTemplatesFakes")==null){
  489. $(".hide_nukes").hide()
  490. $(".hide_fangs").hide()
  491. $(".hide_knight").hide()
  492. $(".hide_snob").hide()
  493. }
  494.  
  495.  
  496.  
  497.  
  498. }
  499.  
  500. function changeTheme(){
  501. let html= `
  502.  
  503. <table class="scriptTable" >
  504. <h3 style="color:${textColor};padding-left:10px;padding-top:5px">after theme is selected run the script again<h3>
  505. <tr>
  506. <td>
  507. <select id="select_theme">
  508. <option value="theme1">theme1</option>
  509. <option value="theme2">theme2</option>
  510. <option value="theme3">theme3</option>
  511. <option value="theme4">theme4</option>
  512. <option value="theme5">theme5</option>
  513. <option value="theme6">theme6</option>
  514. <option value="theme7">theme7</option>
  515. <option value="theme8">theme8</option>
  516. <option value="theme9">theme9</option>
  517. <option value="theme10">theme10</option>
  518. </select>
  519. </td>
  520. <td>value</td>
  521. <td >color hex</td>
  522. </tr>
  523. <tr>
  524. <td>textColor</td>
  525. <td style="background-color:${textColor}" class="td_background"></td>
  526. <td><input type="text" class="scriptInput input_theme" value="${textColor}"></td>
  527. </tr>
  528. <tr>
  529. <td>backgroundInput</td>
  530. <td style="background-color:${backgroundInput}" class="td_background"></td>
  531. <td><input type="text" class="scriptInput input_theme" value="${backgroundInput}"></td>
  532. </tr>
  533. <tr>
  534. <td>borderColor</td>
  535. <td style="background-color:${borderColor}" class="td_background"></td>
  536. <td><input type="text" class="scriptInput input_theme" value="${borderColor}"></td>
  537. </tr>
  538. <tr>
  539. <td>backgroundContainer</td>
  540. <td style="background-color:${backgroundContainer}" class="td_background"></td>
  541. <td><input type="text" class="scriptInput input_theme" value="${backgroundContainer}"></td>
  542. </tr>
  543. <tr>
  544. <td>backgroundHeader</td>
  545. <td style="background-color:${backgroundHeader}" class="td_background"></td>
  546. <td><input type="text" class="scriptInput input_theme" value="${backgroundHeader}"></td>
  547. </tr>
  548. <tr>
  549. <td>backgroundMainTable</td>
  550. <td style="background-color:${backgroundMainTable}" class="td_background"></td>
  551. <td><input type="text" class="scriptInput input_theme" value="${backgroundMainTable}"></td>
  552. </tr>
  553. <tr>
  554. <td>backgroundInnerTable</td>
  555. <td style="background-color:${backgroundInnerTable}" class="td_background"></td>
  556. <td><input type="text" class="scriptInput input_theme" value="${backgroundInnerTable}"></td>
  557. </tr>
  558. <tr >
  559. <td><input class="btn evt-confirm-btn btn-confirm-yes" type="button" id="btn_save_theme" value="Save"></td>
  560. <td><input class="btn evt-confirm-btn btn-confirm-yes" type="button" id="btn_reset_theme" value="Default themes"></td>
  561. <td></td>
  562. </tr>
  563.  
  564. </table>
  565. `
  566. $("#theme_settings").append(html)
  567. $("#theme_settings").hide()
  568.  
  569. let selectedTheme = ""
  570. let colours =[]
  571. let mapTheme = new Map()
  572.  
  573. $("#select_theme").on("change",()=>{
  574. if(localStorage.getItem(localStorageThemeName) != undefined){
  575. selectedTheme = $('#select_theme').find(":selected").text();
  576. colours = Array.from($(".input_theme")).map(elem=>elem.value.toUpperCase().trim())
  577. mapTheme = new Map(JSON.parse(localStorage.getItem(localStorageThemeName)))
  578. console.log(selectedTheme)
  579. console.log(mapTheme)
  580. colours = mapTheme.get(selectedTheme)
  581. console.log(colours)
  582. Array.from($(".input_theme")).forEach((elem,index)=>{
  583. elem.value = colours[index]
  584. })
  585. Array.from($(".td_background")).forEach((elem,index)=>{
  586. elem.style.background = colours[index]
  587. })
  588.  
  589. mapTheme.set("currentTheme",selectedTheme)
  590. localStorage.setItem(localStorageThemeName, JSON.stringify(Array.from(mapTheme.entries())))
  591. }
  592. })
  593.  
  594. $("#btn_save_theme").on("click",()=>{
  595. colours = Array.from($(".input_theme")).map(elem=>elem.value.toUpperCase().trim())
  596. selectedTheme = $('#select_theme').find(":selected").text();
  597.  
  598. for(let i=0;i<colours.length;i++){
  599. if(colours[i].match(/#[0-9 A-F]{6}/) == null ){
  600. UI.ErrorMessage("wrong colour: "+colours[i])
  601. throw new Error("wrong colour")
  602. }
  603. }
  604.  
  605. if(localStorage.getItem(localStorageThemeName) != undefined)
  606. mapTheme = new Map(JSON.parse(localStorage.getItem(localStorageThemeName)))
  607.  
  608.  
  609. mapTheme.set(selectedTheme,colours)
  610. mapTheme.set("currentTheme",selectedTheme)
  611.  
  612. localStorage.setItem(localStorageThemeName, JSON.stringify(Array.from(mapTheme.entries())))
  613. console.log("saved colours for: "+selectedTheme)
  614. UI.SuccessMessage(`saved colours for: ${selectedTheme} \n run the script again`,1000)
  615.  
  616.  
  617. })
  618.  
  619. $("#btn_reset_theme").on("click",()=>{
  620. localStorage.setItem(localStorageThemeName, defaultTheme)
  621. UI.SuccessMessage("run the script again",1000)
  622.  
  623. })
  624.  
  625.  
  626.  
  627. if(localStorage.getItem(localStorageThemeName) != undefined){
  628. mapTheme = new Map(JSON.parse(localStorage.getItem(localStorageThemeName)))
  629. let currentTheme=mapTheme.get("currentTheme")
  630. document.querySelector('#select_theme').value=currentTheme
  631. }
  632.  
  633.  
  634. }
  635.  
  636. function initializationTheme(){
  637. if(localStorage.getItem(localStorageThemeName) != undefined){
  638. let mapTheme = new Map(JSON.parse(localStorage.getItem(localStorageThemeName)))
  639. let currentTheme=mapTheme.get("currentTheme")
  640. let colours=mapTheme.get(currentTheme)
  641.  
  642. textColor=colours[0]
  643. backgroundInput=colours[1]
  644.  
  645. borderColor = colours[2]
  646. backgroundContainer=colours[3]
  647. backgroundHeader=colours[4]
  648. backgroundMainTable=colours[5]
  649. backgroundInnerTable=colours[6]
  650.  
  651. backgroundAlternateTableEven=backgroundContainer;
  652. backgroundAlternateTableOdd=getColorDarker(backgroundContainer,headerColorAlternateTable);
  653. console.log("textColor: "+textColor)
  654. console.log("backgroundContainer: "+backgroundContainer)
  655.  
  656. }
  657. else{
  658. localStorage.setItem(localStorageThemeName, defaultTheme)
  659.  
  660. let mapTheme = new Map(JSON.parse(localStorage.getItem(localStorageThemeName)))
  661. let currentTheme=mapTheme.get("currentTheme")
  662. let colours=mapTheme.get(currentTheme)
  663.  
  664. textColor=colours[0]
  665. backgroundInput=colours[1]
  666.  
  667. borderColor = colours[2]
  668. backgroundContainer=colours[3]
  669. backgroundHeader=colours[4]
  670. backgroundMainTable=colours[5]
  671. backgroundInnerTable=colours[6]
  672.  
  673. backgroundAlternateTableEven=backgroundContainer;
  674. backgroundAlternateTableOdd=getColorDarker(backgroundContainer,headerColorAlternateTable);
  675. }
  676.  
  677. }
  678.  
  679.  
  680.  
  681.  
  682. ///////////////////////////////////////////////////////////get admins from dropbox////////////////////////////////////
  683. function getAdmin(){
  684. var result
  685. $.ajax({
  686. url: "https://content.dropboxapi.com/2/files/download",
  687. method: 'POST',
  688. dataType: "text",
  689. async: false,
  690. headers: { 'Authorization': 'Bearer ' + dropboxToken,
  691. 'Dropbox-API-Arg': JSON.stringify({path: "/"+filname_admin})},
  692.  
  693. success: (data) => {
  694. result=data
  695.  
  696. },error:(err)=>{
  697. alert(err)
  698. reject(err)
  699. }
  700. })
  701. return result
  702. }
  703.  
  704. ///////////////////////////////////////////////////////////get ally from dropbox////////////////////////////////////
  705. function getAlly(){
  706. var result
  707. $.ajax({
  708. url: "https://content.dropboxapi.com/2/files/download",
  709. method: 'POST',
  710. dataType: "text",
  711. async: false,
  712. headers: { 'Authorization': 'Bearer ' + dropboxToken,
  713. 'Dropbox-API-Arg': JSON.stringify({path: "/"+filname_ally})},
  714.  
  715. success: (data) => {
  716. result=data
  717.  
  718. },error:(err)=>{
  719. alert(err)
  720. reject(err)
  721. }
  722. })
  723. return result
  724. }
  725.  
  726.  
  727.  
  728.  
  729. ///////////////////////////////////////////////////events for interface tribes///////////////////////////////////////////////
  730. function adminInterfaceAlly(){
  731. $(document).ready(function() {
  732. let admin=true;
  733. let ally_tribe=JSON.parse((dropbox_ally=="")?"[]":dropbox_ally )
  734. let dataTribes=[]
  735. let url=window.location.href.split("/game.php")[0]+"/map/ally.txt"
  736. let data=httpGet(url).replaceAll("+"," ").toLowerCase().split("\n")
  737. let map_tribe=new Map()
  738. for(let i=0;i<data.length;i++){
  739. dataTribes.push(data[i].split(",")[1] )
  740. map_tribe.set(data[i].split(",")[1],data[i].split(",")[0])
  741. }
  742. // console.log("AICI ba")
  743. // console.log(dataTribes)
  744.  
  745. if(admin){
  746. let page_admin=document.getElementById("page_admin")
  747. let htmlTable= `
  748. <div id="table_admin">
  749. <table class="scriptTable" >
  750. <tr>
  751. <td colspan="2" >ally tribes</td>
  752. <td colspan="2">remove ally</td>
  753. </tr>`
  754.  
  755. for(let i=0;i<ally_tribe.length;i++){
  756. htmlTable+=`
  757. <tr>
  758. <td colspan="2"><font class="all_ally"color="${textColor}">${ally_tribe[i].name} </font></td>
  759. <td colspan="2">
  760. <input class="btn evt-confirm-btn btn-confirm-yes" type="button" onclick='$(this).closest("tr").remove()' value="remove">
  761. </td>
  762. </tr>
  763. `
  764. }
  765. htmlTable+=`
  766. <tr>
  767. <td colspan="2">
  768. <input class="scriptInput" type="text" id="name_tribe" placeholder="name tribe" >
  769. </td>
  770.  
  771. <td colspan="2">
  772. <input class="btn evt-confirm-btn btn-confirm-yes" type="button" id="btn_add" value="add">
  773. </td>
  774. </tr>
  775.  
  776.  
  777. </table>
  778. <center style="margin:5px"><input class="btn evt-confirm-btn btn-confirm-yes" id='btn_save_ally' type="button" value="Save"></center>
  779. </div>
  780. `
  781.  
  782. $("#div_admin_show").append(htmlTable)
  783. $("#table_admin").hide();
  784. $("#table_admin2").hide();
  785. $("#page_admin").on("click",()=>{
  786. $("#table_admin").toggle(300)
  787. })
  788.  
  789. autocomplete(document.getElementById("name_tribe"),dataTribes)
  790.  
  791.  
  792.  
  793.  
  794.  
  795. // upload in dropbox
  796. document.getElementById("btn_save_ally").addEventListener("click",function(){
  797. let ally=document.getElementsByClassName("all_ally")
  798. let list_ally=[]
  799. for(let i=0;i<ally.length;i++){
  800. list_ally.push({
  801. name:ally[i].innerText.toLowerCase(),
  802. allyId:map_tribe.get(ally[i].innerText)
  803. })
  804. }
  805. uploadFile(JSON.stringify(list_ally),filname_ally,dropboxToken)
  806. console.log(list_ally)
  807. })
  808.  
  809. document.getElementById("btn_add").addEventListener("click",function(){
  810. let name_tribe=document.getElementById("name_tribe").value.toLowerCase()
  811.  
  812. if(map_tribe.has(name_tribe)){
  813. let table=document.getElementById("table_admin").getElementsByTagName("table")[0]
  814. let tr=table.getElementsByTagName("tr")
  815. let exist=false;
  816. for(let i=1;i<tr.length-1;i++){
  817. console.log(tr[i].innerText.includes(name_tribe))
  818. if(tr[i].innerText.includes(name_tribe)){
  819. exist=true;
  820. break;
  821. }
  822. }
  823. if(exist==false){
  824. let newTr=document.createElement("tr")
  825. newTr.innerHTML=`
  826. <td colspan="2"><font class="all_ally"color="${textColor}">${name_tribe} </font></td>
  827. <td colspan="2"><input class="btn evt-confirm-btn btn-confirm-yes" type="button" onclick='$(this).closest("tr").remove()' value="remove"></td> `
  828. console.log(newTr)
  829. let addTr=table.insertRow(tr.length-1)
  830. addTr.innerHTML=newTr.innerHTML
  831. }
  832. else{
  833. UI.ErrorMessage("this tribe already exist1",1000)
  834. }
  835. }else{
  836. UI.ErrorMessage("this tribe doesn't exist2",1000)
  837. }
  838. })
  839.  
  840.  
  841.  
  842. }
  843.  
  844. });
  845.  
  846. }
  847. /////////////////////////////////////////////////events for interface admin/////////////////////////////////////////////
  848. function adminInterface(){
  849. $(document).ready(function() {
  850. let admin=true;
  851. let admin_tribe=JSON.parse((dropbox_admin=="")?"[]":dropbox_admin )
  852. let dataTribes=[]
  853. let url=window.location.href.split("/game.php")[0]+"/map/player.txt"
  854. let data=httpGet(url).replaceAll("+"," ").toLowerCase().split("\n")
  855. let map_tribe=new Map()
  856. for(let i=0;i<data.length;i++){
  857. dataTribes.push(data[i].split(",")[1] )
  858. map_tribe.set(data[i].split(",")[1],data[i].split(",")[0])
  859. }
  860. // console.log("AICI ba admin")
  861. // console.log(dataTribes)
  862.  
  863. if(admin){
  864. let page_admin=document.getElementById("page_admin2")
  865. let htmlTable= `
  866. <div id="table_admin2">
  867. <table class="scriptTable" >
  868. <tr>
  869. <td colspan="2" >admins</td>
  870. <td colspan="2">remove admin</td>
  871. </tr>`
  872.  
  873. for(let i=0;i<admin_tribe.length;i++){
  874. htmlTable+=`
  875. <tr>
  876. <td colspan="2"><font class="all_admin"color="${textColor}">${admin_tribe[i].name} </font></td>
  877.  
  878. <td colspan="2">
  879. <input class="btn evt-confirm-btn btn-confirm-yes" type="button" onclick='$(this).closest("tr").remove()' value="remove">
  880. </td>
  881. </tr>
  882. `
  883. }
  884. htmlTable+=`
  885. <tr>
  886. <td colspan="2" >
  887. <input class="scriptInput" id="name_admin" placeholder="name player">
  888. </td>
  889. <td colspan="2">
  890. <input class="btn evt-confirm-btn btn-confirm-yes" type="button" id="btn_add_admin" value="add">
  891. </td>
  892. </tr>
  893.  
  894.  
  895. </table>
  896. <center style="margin:5px"><input class="btn evt-confirm-btn btn-confirm-yes" id='btn_save_admin' type="button" value="Save"></center>
  897. </div>
  898. `
  899.  
  900. $("#div_admin_show").append(htmlTable)
  901. $("#table_admin2").hide();
  902. $("#page_admin2").on("click",()=>{
  903. $("#table_admin2").toggle(300)
  904. })
  905.  
  906. autocomplete(document.getElementById("name_admin"),dataTribes)
  907.  
  908.  
  909.  
  910.  
  911.  
  912. // upload in dropbox
  913. document.getElementById("btn_save_admin").addEventListener("click",function(){
  914. let admin=document.getElementsByClassName("all_admin")
  915. let list_admin=[]
  916. for(let i=0;i<admin.length;i++){
  917. list_admin.push({
  918. name:admin[i].innerText.toLowerCase(),
  919. adminId:map_tribe.get(admin[i].innerText)
  920. })
  921. }
  922. uploadFile(JSON.stringify(list_admin),filname_admin,dropboxToken)
  923. console.log(list_admin)
  924. })
  925.  
  926. document.getElementById("btn_add_admin").addEventListener("click",function(){
  927. let name_admin=document.getElementById("name_admin").value.toLowerCase()
  928.  
  929. if(map_tribe.has(name_admin)){
  930. let table=document.getElementById("table_admin2").getElementsByTagName("table")[0]
  931. let tr=table.getElementsByTagName("tr")
  932. let exist=false;
  933. for(let i=1;i<tr.length-1;i++){
  934. console.log(tr[i].innerText.includes(name_admin))
  935. if(tr[i].innerText.includes(name_admin)){
  936. exist=true;
  937. break;
  938. }
  939. }
  940. if(exist==false){
  941. let newTr=document.createElement("tr")
  942. newTr.innerHTML=`
  943. <td colspan="2"><font class="all_admin"color="${textColor}">${name_admin} </font></td>
  944. <td colspan="2"><input class="btn evt-confirm-btn btn-confirm-yes" type="button" onclick='$(this).closest("tr").remove()' value="remove"></td> `
  945. console.log(newTr)
  946. let addTr=table.insertRow(tr.length-1)
  947. addTr.innerHTML=newTr.innerHTML
  948. }
  949. else{
  950. UI.ErrorMessage("this player already exist",1000)
  951. }
  952. }else{
  953. UI.ErrorMessage("this player doesn't exist",1000)
  954. }
  955. })
  956.  
  957.  
  958.  
  959. }
  960.  
  961. });
  962.  
  963. }
  964.  
  965.  
  966.  
  967. function addEventPanel(){
  968. $('.tab-panels .tabs li').each((index,item)=>{
  969. // console.log(item.id)
  970. if(item.id!="add_tab"){
  971. $(item).off("click")
  972. }
  973. })
  974. $('.tab-panels .tabs li').not("#add_tab").on('click', function(event) {
  975. // console.log("addEventPanel")
  976. if(event.target.src==undefined){
  977. // console.log("inside if")
  978. if($(this).hasClass("active")==false ){
  979.  
  980. var $panel = $(this).closest('.tab-panels');
  981. $panel.find('.tabs li.active').removeClass('active');
  982. $(this).addClass('active');
  983.  
  984. //figure out which panel to show
  985. var panelToShow = $(this).attr('rel');
  986. if(panelToShow!=undefined){
  987. //hide current panel
  988. $panel.find('.panel.active').slideUp(300, showNextPanel);
  989.  
  990. //show next panel
  991. function showNextPanel() {
  992. $(this).removeClass('active');
  993.  
  994. $('#'+panelToShow).slideDown(300, function() {
  995. $(this).addClass('active');
  996. });
  997. }
  998. }
  999. }
  1000. else{
  1001. let value=window.prompt("change name tab")
  1002. // console.log(value)
  1003. if(value!="" && value!=null){
  1004. // console.log(this)
  1005. if(this.children.length>0)
  1006. this.children[0].innerText=value
  1007. else
  1008. this.innerText=value
  1009. saveOwnData();
  1010. }
  1011. }
  1012. }
  1013.  
  1014. });
  1015. }
  1016.  
  1017. function addNewPanel(){
  1018. $("#add_tab").on("click",function(){
  1019.  
  1020. let idNewPanel=parseInt($(".tabs").eq(0).find("li").last().prev().attr("rel").replace("panel",""))+1
  1021. let htmlLI=`<li class="update_tab own" rel="panel${idNewPanel}"> <font> panel${idNewPanel}</font> <img class="remove_tab" src="https://img.icons8.com/doodle/16/000000/delete-sign.png"/> </li>`;
  1022. $("#add_tab").before(htmlLI);
  1023.  
  1024. let htmlDIV=`
  1025. <div id="panel`+idNewPanel+`" class="panel">
  1026. <p style="color:${textColor};font-weight: bold;">nr coords:</p>
  1027. <center style="margin:5px"><textarea id="input_coord${idNewPanel}" class="scriptInput" rows="10">panel${idNewPanel}</textarea><center>
  1028. </div>`
  1029.  
  1030. $("#all_tabs").append(htmlDIV)
  1031. addEventPanel();
  1032. removePanel()
  1033. getCoordsEvent();
  1034. })
  1035. }
  1036.  
  1037.  
  1038. function removePanel(){
  1039. $('.remove_tab').off('click');
  1040. $(".remove_tab").on("click",function(){
  1041. var confirm=window.confirm("are you sure?")
  1042. if(confirm==true && $('.remove_tab').length>1){
  1043. let removePanel=$(this).parent().attr('rel')
  1044. $(this).parent().remove();
  1045. $("#"+removePanel).remove();
  1046.  
  1047. if($(".active").length==0){
  1048. let lastTab=$(".update_tab").last()
  1049. lastTab.addClass("active");
  1050. let panelId=lastTab.attr("rel")
  1051. $("#"+panelId).addClass("active");
  1052. $("#"+panelId).slideDown(300);
  1053. }
  1054. }
  1055.  
  1056. })
  1057. }
  1058. ////////////////////////////////////////////////// save and set data /////////////////////////////////////////////////////////////
  1059. function getCoordsEvent(){
  1060. console.log("getCoordEvent")
  1061. $("#all_tabs .panel").off("mouseout");
  1062. $("#all_tabs .panel").mouseout(function(){
  1063. let current_value=this.getElementsByTagName("textarea")[0].value
  1064. if(current_value.match(/[0-9]{3}\|[0-9]{3}/)!=null){
  1065. let coords=current_value.match(/[0-9]{3}\|[0-9]{3}/g)
  1066. this.getElementsByTagName("textarea")[0].value=Array.from(coords).join(" ")
  1067. $(this).find("p").last().text("nr coords: "+coords.length)
  1068. }
  1069. saveOwnData();
  1070. })
  1071. }
  1072.  
  1073.  
  1074.  
  1075. function saveOwnData(){
  1076. // console.log("save coords")
  1077. let name_tabs=$(".tabs").eq(0).find(".own")
  1078. let textarea_tabs=$("#all_tabs").eq(0).find(".own").find("textarea")
  1079. let listInfoTabs=[];
  1080. for(let i=0;i<name_tabs.length;i++){
  1081. let objInfo={};
  1082. objInfo.name=name_tabs.eq(i).text().trim()
  1083. if(textarea_tabs.eq(i).val()!=undefined)
  1084. objInfo.coords=textarea_tabs.eq(i).val();
  1085. else
  1086. objInfo.coords="add coords"
  1087. listInfoTabs.push(objInfo)
  1088. }
  1089. // console.log(listInfoTabs)
  1090. localStorage.setItem(game_data.world+"ownTabs",JSON.stringify(listInfoTabs))
  1091.  
  1092. }
  1093.  
  1094. function initializationOwnTabs(){
  1095. var listInfoTabs=JSON.parse(localStorage.getItem(game_data.world+"ownTabs"))
  1096.  
  1097. if(listInfoTabs.length>0){
  1098. for(let i=0;i<listInfoTabs.length;i++){
  1099. let idNewPanel=parseInt($(".tabs").eq(0).find("li").last().prev().attr("rel").replace("panel",""))+1
  1100. let htmlLI=`<li class="update_tab own" rel="panel${idNewPanel}"> <font> ${listInfoTabs[i].name} </font> <img class="remove_tab" src="https://img.icons8.com/doodle/16/000000/delete-sign.png"/> </li>`;
  1101. $("#add_tab").before(htmlLI);
  1102. let coords=""
  1103.  
  1104. if(listInfoTabs[i].coords!="undefined")
  1105. coords=listInfoTabs[i].coords
  1106. let nrCoords=0;
  1107. if(coords!=undefined)
  1108. if(coords.split(" ")[0]!="")
  1109. nrCoords=coords.split(" ").length
  1110. let htmlDIV=`
  1111. <div id="panel${idNewPanel}" class="panel own">
  1112. <p style="color:${textColor};font-weight: bold;">nr coords: ${nrCoords}</p>
  1113. <center style="margin:5px"><textarea class="scriptInput" rows="10">${coords}</textarea><center>
  1114. </div>`
  1115.  
  1116. $("#all_tabs").append(htmlDIV)
  1117. }
  1118. //remove first own tab
  1119. document.getElementsByClassName("tabs")[0].firstElementChild.remove();
  1120. document.getElementById("all_tabs").getElementsByClassName("active")[0].remove();
  1121. //active last own tab
  1122. document.getElementsByClassName("tabs")[0].lastElementChild.previousSibling.classList.add("active")
  1123. document.getElementById("all_tabs").lastElementChild.classList.add("active")
  1124. }
  1125. console.log("initialization!")
  1126. addEventPanel();
  1127. removePanel()
  1128. getCoordsEvent();
  1129. document.querySelectorAll(".scriptInput").forEach(function(box, index){
  1130. console.log(box)
  1131. box.style.width = "100%";
  1132. })
  1133. document.querySelectorAll(".scriptInput").forEach(function(box, index){
  1134. console.log(box)
  1135. box.classList.add()
  1136. })
  1137. }
  1138.  
  1139.  
  1140. function saveNrFakes(){
  1141. let inputFakes=document.getElementById("nr_fakes")
  1142. let inputSplit=document.getElementById("nr_split")
  1143. let inputDelay=document.getElementById("delay_tabs")
  1144. inputFakes.addEventListener("mouseout",()=>{
  1145. console.log()
  1146. if(inputFakes.value<0 || inputFakes.value=="")
  1147. inputFakes.value=1;
  1148. localStorage.setItem(game_data.world+"nr_fakes",inputFakes.value)
  1149. })
  1150. inputSplit.addEventListener("mouseout",()=>{
  1151. console.log(inputSplit.value)
  1152. if(inputSplit.value<0 || inputSplit.value=="")
  1153. inputSplit.value=5;
  1154. localStorage.setItem(game_data.world+"nr_split",inputSplit.value)
  1155. })
  1156. inputDelay.addEventListener("mouseout",()=>{
  1157. console.log(inputDelay.value)
  1158. if(inputDelay.value<200 || inputDelay.value=="")
  1159. inputDelay.value=200;
  1160. localStorage.setItem(game_data.world+"delay_tabs",inputDelay.value)
  1161. })
  1162.  
  1163. }
  1164.  
  1165. function initializationNrFakes(){
  1166. let nrFakes=localStorage.getItem(game_data.world+"nr_fakes")
  1167. let nrSplit=localStorage.getItem(game_data.world+"nr_split")
  1168. let nrDelay=localStorage.getItem(game_data.world+"delay_tabs")
  1169. if(nrFakes!=undefined){
  1170. document.getElementById("nr_fakes").value=nrFakes
  1171. }
  1172. if(nrSplit!=undefined){
  1173. document.getElementById("nr_split").value=nrSplit
  1174. }
  1175. if(nrSplit!=undefined){
  1176. document.getElementById("delay_tabs").value=nrDelay
  1177. }
  1178. }
  1179.  
  1180.  
  1181.  
  1182. function initializationTroupes(){
  1183. localStorage.removeItem(game_data.world+"troopTemplate")//old variable
  1184.  
  1185. if(localStorage.getItem(game_data.world+"troopTemplatesFakes")!=null ){
  1186. //initialize checkbox
  1187. let list_checkbox=JSON.parse(localStorage.getItem(game_data.world+"troopTemplatesFakes"))[0]
  1188. $('.set_troops input[type=checkbox]').each(function (index,elem) {
  1189. this.checked=list_checkbox[index]
  1190. // console.log(elem.value)
  1191. });
  1192. //initialize dropdown
  1193. let list_select=JSON.parse(localStorage.getItem(game_data.world+"troopTemplatesFakes"))[1]
  1194. $('.set_troops select').each(function (index,elem) {
  1195. this.value=list_select[index]
  1196. // console.log(elem.value)
  1197. });
  1198.  
  1199. //initialize input numbers
  1200. let list_input=JSON.parse(localStorage.getItem(game_data.world+"troopTemplatesFakes"))[2]
  1201. $('.set_troops input[type=number]').each(function (index,elem) {
  1202. // console.log(elem)
  1203. this.value=list_input[index]
  1204. });
  1205. //initialize input datetime-local
  1206. let list_datetime=JSON.parse(localStorage.getItem(game_data.world+"troopTemplatesFakes"))[3]
  1207. $('.set_troops input[type=datetime-local]').each(function (index,elem) {
  1208. // console.log(elem)
  1209. this.value=list_datetime[index]
  1210. });
  1211.  
  1212. //hide for fakes or nukes
  1213. let select_type=document.getElementById("select_type_attack").value
  1214. console.log("select_type22",select_type)
  1215. if(select_type == "fakes"){
  1216. $(".hide_nukes").hide()
  1217. $(".hide_fangs").hide()
  1218. $(".hide_knight").hide()
  1219. $(".hide_snob").hide()
  1220. $(".hide_btn_delete").hide()
  1221. }
  1222. else if(select_type == "nukes"){
  1223. $(".hide_fakes").hide()
  1224. $(".hide_fangs").hide()
  1225. }
  1226. else{
  1227. $(".hide_fakes").hide()
  1228. $(".hide_nukes").hide()
  1229. }
  1230.  
  1231. }
  1232.  
  1233.  
  1234. $(".set_troops select, .set_troops input[type=number], .set_troops input[type=checkbox], .set_troops input[type=datetime-local]").on("click input change",()=>{
  1235. let select_command_value=[]
  1236. let list_input=[]
  1237. let list_checkbox=[]
  1238. let list_datetime=[]
  1239.  
  1240. //save checkbox
  1241. $('.set_troops input[type=checkbox]').each(function () {
  1242. console.log("AICI")
  1243. var checked = this.checked
  1244. console.log(this)
  1245. list_checkbox.push(checked)
  1246. });
  1247. //save dropdown
  1248. $('.set_troops select').each(function () {
  1249. var value = this.value
  1250. select_command_value.push(value)
  1251. });
  1252. //save inputs
  1253. $('.set_troops input[type=number]').each(function () {
  1254. // var checked = this.checked
  1255. var value=this.value
  1256. // console.log(value)
  1257. list_input.push(value)
  1258. });
  1259.  
  1260. //save datetime-local
  1261. $('.set_troops input[type=datetime-local]').each(function () {
  1262. // var checked = this.checked
  1263. var value=this.value
  1264. // console.log(value)
  1265. list_datetime.push(value)
  1266. });
  1267.  
  1268.  
  1269.  
  1270.  
  1271. let list_final=[list_checkbox,select_command_value,list_input,list_datetime]
  1272. let data=JSON.stringify(list_final)
  1273. let data_localStorage=localStorage.getItem(game_data.world+"troopTemplatesFakes")
  1274. console.log(data)
  1275. if(data!=data_localStorage){
  1276. localStorage.setItem(game_data.world+"troopTemplatesFakes",JSON.stringify(list_final))
  1277. }
  1278.  
  1279. // hide fakes or nukes
  1280. let select_type=document.getElementById("select_type_attack").value
  1281. console.log("select_type sa mor",select_type)
  1282. if(select_type == "fakes"){
  1283. $(".hide_nukes").hide()
  1284. $(".hide_fangs").hide()
  1285. $(".hide_fakes").show()
  1286.  
  1287. $(".hide_knight").hide()
  1288. $(".hide_snob").hide()
  1289. $(".hide_btn_delete").hide()
  1290.  
  1291. }
  1292. else if(select_type == "nukes"){
  1293. $(".hide_fakes").hide()
  1294. $(".hide_fangs").hide()
  1295. $(".hide_nukes").show()
  1296.  
  1297. $(".hide_knight").show()
  1298. $(".hide_snob").show()
  1299. }
  1300. else {
  1301. $(".hide_fakes").hide()
  1302. $(".hide_nukes").hide()
  1303. $(".hide_fangs").show()
  1304.  
  1305. $(".hide_knight").show()
  1306. $(".hide_snob").show()
  1307. }
  1308.  
  1309.  
  1310. })
  1311.  
  1312. }
  1313.  
  1314.  
  1315.  
  1316. function initializationOptionAttack(){
  1317. let list_select=document.getElementById("select_option_fakes")
  1318. let list_stored=localStorage.getItem(game_data.world+"optionAttack")
  1319. list_select.value=list_stored
  1320.  
  1321. $("#select_option_fakes").change(()=>{
  1322. console.log("save attack")
  1323. let option=document.getElementById("select_option_fakes").value
  1324. localStorage.setItem(game_data.world+"optionAttack",option)
  1325. })
  1326. }
  1327.  
  1328.  
  1329. function saveCoordDropbox(){
  1330. let tabs_tribe=document.getElementsByClassName("li_tribe")
  1331. // console.log(tabs_tribe)
  1332. for(let i=0;i<tabs_tribe.length;i++){
  1333. let idDivParent=tabs_tribe[i].getAttribute("rel");
  1334. document.getElementById(idDivParent).getElementsByClassName("btn")[0].addEventListener("click",()=>{
  1335. let coords=document.getElementById(idDivParent).getElementsByTagName("textarea")[0].value
  1336. let obj={
  1337. coords:coords,
  1338. playerId:game_data.player.id,
  1339. playerName:game_data.player.name,
  1340. data:document.getElementById("serverDate").innerText+" "+document.getElementById("serverTime").innerText,
  1341. nameTab:tabs_tribe[i].innerText
  1342. }
  1343. console.log("saved")
  1344. console.log(obj)
  1345. uploadFile(JSON.stringify(obj),list_filename_fakes[i],dropboxToken)
  1346. })
  1347. }
  1348. }
  1349.  
  1350.  
  1351.  
  1352. async function getCoordDropbox(){
  1353. let tabs_tribe=document.getElementsByClassName("li_tribe")
  1354. let [file_fakes1, file_fakes2, file_fakes3, file_fakes4, file_fakes5, file_fakes6,file_fakes7,file_fakes8,file_fakes9,file_fakes10]=await Promise.all(
  1355. [readFileDropbox(filename_fakes1),readFileDropbox(filename_fakes2),readFileDropbox(filename_fakes3),readFileDropbox(filename_fakes4),readFileDropbox(filename_fakes5),readFileDropbox(filename_fakes6),readFileDropbox(filename_fakes7),readFileDropbox(filename_fakes8),readFileDropbox(filename_fakes9),readFileDropbox(filename_fakes10)])
  1356.  
  1357. let list_files=[file_fakes1, file_fakes2, file_fakes3, file_fakes4, file_fakes5, file_fakes6,file_fakes7,file_fakes8,file_fakes9,file_fakes10]
  1358.  
  1359. for(let i=0;i<tabs_tribe.length;i++){
  1360. let idDivParent=tabs_tribe[i].getAttribute("rel");
  1361.  
  1362. let textarea=document.getElementById(idDivParent).getElementsByTagName("textarea")[0]
  1363. let paragraph_saved_by=document.getElementById(idDivParent).getElementsByTagName("p")[0]
  1364. let paragraph_nr_coord=document.getElementById(idDivParent).getElementsByTagName("p")[1]
  1365.  
  1366. //initialize panels tribe when mouse is up
  1367. tabs_tribe[i].addEventListener("mouseup",async function(){
  1368. if(tabs_tribe[i].classList.contains("active")==false){
  1369. try{
  1370. let data_coord=await readFileDropbox(list_filename_fakes[i])
  1371. let obj=JSON.parse(data_coord)
  1372. textarea.value=obj.coords;
  1373. paragraph_saved_by.innerText="saved by "+obj.playerName+" on "+obj.data
  1374. paragraph_nr_coord.innerText="nr coords "+obj.coords.split(" ").length
  1375. tabs_tribe[i].innerText=obj.nameTab
  1376. // console.log(obj)
  1377. UI.SuccessMessage("get coords",1000)
  1378. }catch(e){
  1379. UI.ErrorMessage("error coords",1000)
  1380. }
  1381.  
  1382. }
  1383.  
  1384. })
  1385. //initialize the first time when the script is run
  1386. if(tabs_tribe[i].classList.contains("active")==false){
  1387. try{
  1388. let obj=JSON.parse(list_files[i])
  1389. textarea.value=obj.coords;
  1390. paragraph_saved_by.innerText="saved by "+obj.playerName+" on "+obj.data
  1391. paragraph_nr_coord.innerText="nr coords "+obj.coords.split(" ").length
  1392. tabs_tribe[i].innerText=obj.nameTab
  1393. // console.log(obj)
  1394. UI.SuccessMessage("upload coords",1000)
  1395. }catch(e){
  1396. UI.ErrorMessage("save coords",1000)
  1397. }
  1398. }
  1399.  
  1400.  
  1401. }
  1402. }
  1403.  
  1404.  
  1405.  
  1406. async function getInfoVIllages(){
  1407.  
  1408. return new Promise(async(resolve,reject)=>{
  1409. let filename_innoDB=game_data.world+"infoVillages"
  1410. await insertlibraryLocalBase().catch(err=>{alert(err)})
  1411. let data = await localBase.getItem(filename_innoDB).catch(err=>{alert(err)})
  1412.  
  1413.  
  1414. console.log("get info VIllages")
  1415. let mapVillage=new Map();
  1416. let obj={};
  1417. let server_date=document.getElementById("serverDate").innerText.split("/")
  1418. let server_time=document.getElementById("serverTime").innerText
  1419. let current_date=new Date(server_date[1]+"/"+server_date[0]+"/"+server_date[2]+" "+server_time);
  1420. let url=window.location.href.split("/game.php")[0]
  1421. let mapPlayer=new Map();
  1422.  
  1423.  
  1424. if(data==undefined){
  1425. let dataVillage=httpGet(url+"/map/village.txt").split(/\r?\n/);
  1426. let dataPlayer=httpGet(url+"/map/player.txt").split(/\r?\n/);
  1427.  
  1428. for(let i=0;i<dataPlayer.length-1;i++){
  1429. // console.log(dataPlayer[i].split(",")[1])
  1430. let playerName=innoReplaceSpecialCaracters(dataPlayer[i].split(",")[1])
  1431. mapPlayer.set(dataPlayer[i].split(",")[0],{
  1432. allyId:dataPlayer[i].split(",")[2],
  1433. playerName:playerName
  1434. })
  1435. }
  1436.  
  1437. for(let i=0;i<dataVillage.length;i++){
  1438. if(mapPlayer.get(dataVillage[i].split(",")[4])!=undefined){
  1439. mapVillage.set(dataVillage[i].split(",")[2]+"|"+dataVillage[i].split(",")[3],{
  1440. villageId:dataVillage[i].split(",")[0],
  1441. playerId:dataVillage[i].split(",")[4],
  1442. points:dataVillage[i].split(",")[5],
  1443. allyId:mapPlayer.get(dataVillage[i].split(",")[4]).allyId,
  1444. playerName:mapPlayer.get(dataVillage[i].split(",")[4]).playerName
  1445. })
  1446. }
  1447. }
  1448. obj.datetime=current_date
  1449. obj.data=Array.from(mapVillage.entries())
  1450.  
  1451. let data=JSON.stringify(obj)
  1452. data=replaceSpecialCaracters(data)
  1453.  
  1454. await localBase.setItem(filename_innoDB,data)
  1455.  
  1456. }else{
  1457.  
  1458. let ino_db= JSON.parse(data)
  1459. let db_date=ino_db.datetime
  1460. mapVillage=new Map(ino_db.data)
  1461.  
  1462. // console.log("mapVillage",mapVillage)
  1463.  
  1464.  
  1465.  
  1466.  
  1467. // console.log(mapVillage)
  1468. if(new Date(current_date).getTime()-new Date(db_date)>3600*1000){
  1469. console.log("update database inno")
  1470.  
  1471. let dataVillage=httpGet(url+"/map/village.txt").split(/\r?\n/);
  1472. let dataPlayer=httpGet(url+"/map/player.txt").split(/\r?\n/);
  1473.  
  1474. for(let i=0;i<dataPlayer.length-1;i++){
  1475. let playerName=innoReplaceSpecialCaracters(dataPlayer[i].split(",")[1])
  1476. mapPlayer.set(dataPlayer[i].split(",")[0],{
  1477. allyId:dataPlayer[i].split(",")[2],
  1478. playerName:playerName
  1479. })
  1480. }
  1481.  
  1482. for(let i=0;i<dataVillage.length;i++){
  1483. if(mapPlayer.get(dataVillage[i].split(",")[4])!=undefined){
  1484. mapVillage.set(dataVillage[i].split(",")[2]+"|"+dataVillage[i].split(",")[3],{
  1485. villageId:dataVillage[i].split(",")[0],
  1486. playerId:dataVillage[i].split(",")[4],
  1487. points:dataVillage[i].split(",")[5],
  1488. allyId:mapPlayer.get(dataVillage[i].split(",")[4]).allyId,
  1489. playerName:mapPlayer.get(dataVillage[i].split(",")[4]).playerName
  1490. })
  1491. }
  1492. }
  1493. obj.datetime=current_date
  1494. obj.data=Array.from(mapVillage.entries())
  1495.  
  1496. let data=JSON.stringify(obj)
  1497. data=replaceSpecialCaracters(data)
  1498. await localBase.setItem(filename_innoDB,data)
  1499.  
  1500. console.log("upload new data")
  1501.  
  1502. }
  1503. else{
  1504. console.log("already exist")
  1505. }
  1506. }
  1507. resolve(mapVillage)
  1508.  
  1509.  
  1510. })
  1511.  
  1512.  
  1513. }
  1514.  
  1515. function insertlibraryLocalBase(){
  1516. return new Promise((resolve,reject)=>{
  1517.  
  1518. let start=new Date().getTime()
  1519. let script = document.createElement('script');
  1520. script.type="text/javascript"
  1521. script.src="https://dl.dropboxusercontent.com/s/22qgnhyxnyono68/libraryIndexedDB.js?dl=0"
  1522. script.onload = function () {
  1523. let stop=new Date().getTime()
  1524. console.log(`insert idb library in ${stop-start} ms`)
  1525. resolve("insert library")
  1526. };
  1527. document.getElementsByTagName("head")[0].appendChild(script);
  1528. })
  1529. }
  1530.  
  1531. function innoReplaceSpecialCaracters(text){//ino database has special characters
  1532. text=text.replaceAll("+"," ")
  1533. text=text.replaceAll("%21","!")
  1534. text=text.replaceAll("%23","#")
  1535. text=text.replaceAll("%24","$")
  1536. text=text.replaceAll("%25","%")
  1537.  
  1538. text=text.replaceAll("%28","(")
  1539. text=text.replaceAll("%29",")")
  1540. text=text.replaceAll("%2A","*")
  1541. text=text.replaceAll("%2B","+")
  1542. text=text.replaceAll("%2C",",")
  1543. text=text.replaceAll("%2F ","/")
  1544.  
  1545.  
  1546. text=text.replaceAll("%3A",":")
  1547. text=text.replaceAll("%3B","}")
  1548. text=text.replaceAll("%3D","=")
  1549. text=text.replaceAll("%3F","?")
  1550.  
  1551. text=text.replaceAll("%40","@")
  1552.  
  1553. text=text.replaceAll("%5B","[")
  1554. text=text.replaceAll("%5D","]")
  1555.  
  1556. text=text.replaceAll("%7B","_")
  1557. text=text.replaceAll("%7C","|")
  1558. text=text.replaceAll("%7D","|")
  1559.  
  1560. text=text.replaceAll("%7E","{")
  1561.  
  1562. text=text.replaceAll("%C3%84","Ä")
  1563. text=text.replaceAll("%C3%85","Å")
  1564. text=text.replaceAll("%C3%86","Æ")
  1565. text=text.replaceAll("%C3%A2","â")
  1566. text=text.replaceAll("%C3%A4","ä")
  1567. text=text.replaceAll("%C3%A5","å")
  1568. text=text.replaceAll("%C3%A6","æ")
  1569. text=text.replaceAll("%C3%B6","ö")
  1570. text=text.replaceAll("%C3%B8","ø")
  1571. text=text.replaceAll("%C3%BC","ü")
  1572.  
  1573. text=text.replaceAll("%C4%83","ă")
  1574.  
  1575. text=text.replaceAll("%C8%99","ș")
  1576. text=text.replaceAll("%C5%A3","ţ")
  1577. text=text.replaceAll("%C8%9B","ț")
  1578.  
  1579. return text
  1580. }
  1581.  
  1582.  
  1583. function getFakeLimit(){//get and save locally fake limit
  1584. let fake_limit=0;
  1585. if(localStorage.getItem(game_data.world+"fake_limit")!=null){
  1586. fake_limit=parseInt(localStorage.getItem(game_data.world+"fake_limit"))
  1587. console.log("already exist")
  1588. }
  1589. else{
  1590. let data=httpGet("/interface.php?func=get_config").split("\n");
  1591. for(let i=0;i<data.length;i++){
  1592. if(data[i].includes("fake_limit")){
  1593. fake_limit=data[i].split("<fake_limit>")[1]
  1594. fake_limit=fake_limit.split("</fake_limit>")[0]
  1595. console.log("get limit fake")
  1596. break;
  1597. }
  1598. }
  1599. localStorage.setItem(game_data.world+"fake_limit",fake_limit)
  1600. }
  1601. console.log("fake limit "+fake_limit)
  1602. return fake_limit
  1603. }
  1604.  
  1605.  
  1606.  
  1607.  
  1608. function autocomplete(inp, arr) {//autocomplete for adding tribes or admins
  1609. /*the autocomplete function takes two arguments,
  1610. the text field element and an array of possible autocompleted values:*/
  1611. var currentFocus;
  1612. /*execute a function when someone writes in the text field:*/
  1613. inp.addEventListener("input", function(e) {
  1614. var a, b, i, val = this.value;
  1615. /*close any already open lists of autocompleted values*/
  1616. closeAllLists();
  1617. if (!val) { return false;}
  1618. currentFocus = -1;
  1619. /*create a DIV element that will contain the items (values):*/
  1620. a = document.createElement("DIV");
  1621. a.setAttribute("id", this.id + "autocomplete-list");
  1622. a.setAttribute("class", "autocomplete-items");
  1623. /*append the DIV element as a child of the autocomplete container:*/
  1624. this.parentNode.appendChild(a);
  1625. /*for each item in the array...*/
  1626. var counter=0;
  1627. for (i = 0; i < arr.length; i++) {
  1628. /*check if the item starts with the same letters as the text field value:*/
  1629. if(arr[i]==undefined)
  1630. continue
  1631. if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
  1632.  
  1633. /*create a DIV element for each matching element:*/
  1634. b = document.createElement("DIV");
  1635. b.style.backgroundColor=backgroundInput
  1636. /*make the matching letters bold:*/
  1637. b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>";
  1638. b.innerHTML += arr[i].substr(val.length);
  1639. /*insert a input field that will hold the current array item's value:*/
  1640. b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
  1641. /*execute a function when someone clicks on the item value (DIV element):*/
  1642. b.addEventListener("click", function(e) {
  1643. /*insert the value for the autocomplete text field:*/
  1644. inp.value = this.getElementsByTagName("input")[0].value;
  1645. /*close the list of autocompleted values,
  1646. (or any other open lists of autocompleted values:*/
  1647. closeAllLists();
  1648. });
  1649. counter++;
  1650. if(counter<=5)
  1651. a.appendChild(b);
  1652. }
  1653. }
  1654. });
  1655. /*execute a function presses a key on the keyboard:*/
  1656. inp.addEventListener("keydown", function(e) {
  1657. var x = document.getElementById(this.id + "autocomplete-list");
  1658. if (x) x = x.getElementsByTagName("div");
  1659. if (e.keyCode == 40) {
  1660. /*If the arrow DOWN key is pressed,
  1661. increase the currentFocus variable:*/
  1662. currentFocus++;
  1663. /*and and make the current item more visible:*/
  1664. addActive(x);
  1665. } else if (e.keyCode == 38) { //up
  1666. /*If the arrow UP key is pressed,
  1667. decrease the currentFocus variable:*/
  1668. currentFocus--;
  1669. /*and and make the current item more visible:*/
  1670. addActive(x);
  1671. } else if (e.keyCode == 13) {
  1672. /*If the ENTER key is pressed, prevent the form from being submitted,*/
  1673. e.preventDefault();
  1674. if (currentFocus > -1) {
  1675. /*and simulate a click on the "active" item:*/
  1676. if (x) x[currentFocus].click();
  1677. }
  1678. }
  1679. });
  1680. function addActive(x) {
  1681. /*a function to classify an item as "active":*/
  1682. if (!x) return false;
  1683. /*start by removing the "active" class on all items:*/
  1684. removeActive(x);
  1685. if (currentFocus >= x.length) currentFocus = 0;
  1686. if (currentFocus < 0) currentFocus = (x.length - 1);
  1687. /*add class "autocomplete-active":*/
  1688. x[currentFocus].classList.add("autocomplete-active");
  1689. }
  1690. function removeActive(x) {
  1691. /*a function to remove the "active" class from all autocomplete items:*/
  1692. for (var i = 0; i < x.length; i++) {
  1693. x[i].classList.remove("autocomplete-active");
  1694. }
  1695. }
  1696. function closeAllLists(elmnt) {
  1697. /*close all autocomplete lists in the document,
  1698. except the one passed as an argument:*/
  1699. var x = document.getElementsByClassName("autocomplete-items");
  1700. for (var i = 0; i < x.length; i++) {
  1701. if (elmnt != x[i] && elmnt != inp) {
  1702. x[i].parentNode.removeChild(x[i]);
  1703. }
  1704. }
  1705. }
  1706. /*execute a function when someone clicks in the document:*/
  1707. document.addEventListener("click", function (e) {
  1708. closeAllLists(e.target);
  1709. });
  1710. }
  1711.  
  1712. function shuffleArray(array) {//randomize coords from vector
  1713. for (let i = array.length - 1; i > 0; i--) {
  1714. const j = Math.floor(Math.random() * (i + 1));
  1715. [array[i], array[j]] = [array[j], array[i]];
  1716. }
  1717. }
  1718.  
  1719. function getBonusNight() { //get bonus night
  1720. if (localStorage.getItem(game_data.world+"nightBonus") !== null) {
  1721. let obj=JSON.parse(localStorage.getItem(game_data.world+"nightBonus"))
  1722. console.log("speed world already exist")
  1723. return obj
  1724. }
  1725. else { //Get data from xml and save it in localStorage to avoid excessive XML requests to server
  1726. let currentHtml=document.body.innerHTML
  1727. let data=httpGet("/interface.php?func=get_config") //Load world data
  1728. document.body.innerHTML +=`<div id='load_html' hidden> ${data}</div>`
  1729. let obj={}
  1730. //active = 0-> bonus night off, active = 1-> bonus night static,active = 2-> bonus night dynamic
  1731. let active = document.getElementsByTagName("night")[0].getElementsByTagName("active")[0].innerHTML
  1732. let start_hour = document.getElementsByTagName("night")[0].getElementsByTagName("start_hour")[0].innerHTML
  1733. let end_hour = document.getElementsByTagName("night")[0].getElementsByTagName("end_hour")[0].innerHTML
  1734. obj.active=active
  1735. obj.start_hour=start_hour
  1736. obj.end_hour=end_hour
  1737. // document.body.innerHTML=currentHtml
  1738. document.getElementById("load_html").remove()
  1739.  
  1740.  
  1741. localStorage.setItem(game_data.world+"nightBonus",JSON.stringify(obj));
  1742. console.log("save speed world")
  1743. return obj
  1744. }
  1745. }
  1746.  
  1747.  
  1748. function getBonusNightForEach(list_href){// return bonus night interval for each player
  1749. return new Promise((solve,reject)=>{
  1750. var counter=0;
  1751. var map_idPlayers=new Map()
  1752. function ajaxRequest (urls) {
  1753. let villageId
  1754. let playerId
  1755. if(urls.length>0){
  1756. let obj=urls.pop()
  1757. villageId=obj.villageId
  1758. playerId=obj.playerId
  1759. }
  1760. else{
  1761. villageId="stop"
  1762. }
  1763. let start_ajax=new Date().getTime()
  1764. if (urls.length >= 0 && villageId!="stop") {
  1765. $.ajax({
  1766. url: game_data.link_base_pure + `map&ajax=map_info&source=${villageId}&target=${villageId}&`,
  1767. method: 'get',
  1768. success: (data) => {
  1769. let night_bonus_interval=data.night_bonus.current_interval.match(/[0-9]{2}:[0-9]{2}/g)
  1770. map_idPlayers.set(playerId,{
  1771. start_hour:night_bonus_interval[0],
  1772. end_hour:night_bonus_interval[1],
  1773.  
  1774. })
  1775.  
  1776. let stop_ajax=new Date().getTime();
  1777. let diff=stop_ajax-start_ajax
  1778. console.log("wait: "+diff)
  1779. window.setTimeout(function(){
  1780. ajaxRequest (list_href)
  1781. UI.SuccessMessage("get bonus: "+urls.length)
  1782. counter++;
  1783. },200-diff)
  1784. }
  1785. })
  1786.  
  1787. }
  1788. else
  1789. {
  1790. UI.SuccessMessage("done")
  1791. solve(map_idPlayers)
  1792. }
  1793. }
  1794. ajaxRequest(list_href);
  1795.  
  1796. })
  1797. }
  1798.  
  1799.  
  1800. function getSpeedConstant() { //Get speed constant (world speed * unit speed) for world
  1801. if (localStorage.getItem(game_data.world+"speedWorld") !== null) {
  1802. let obj=JSON.parse(localStorage.getItem(game_data.world+"speedWorld"))
  1803. console.log("speed world already exist")
  1804. return obj
  1805. }
  1806. else { //Get data from xml and save it in localStorage to avoid excessive XML requests to server
  1807. let currentHtml=document.body.innerHTML
  1808. let data=httpGet("/interface.php?func=get_config") //Load world data
  1809. document.body.innerHTML =`<div id='load_html' hidden>${data}</div>`
  1810. let obj={}
  1811. let worldSpeed = Number(document.getElementsByTagName("speed")[0].innerHTML)
  1812. let unitSpeed = Number(document.getElementsByTagName("unit_speed")[0].innerHTML);
  1813. obj.unitSpeed=unitSpeed
  1814. obj.worldSpeed=worldSpeed
  1815. // document.body.innerHTML=currentHtml
  1816. document.getElementById("load_html").remove()
  1817.  
  1818. localStorage.setItem(game_data.world+"speedWorld",JSON.stringify(obj));
  1819. console.log("save speed world")
  1820. return obj
  1821. }
  1822. }
  1823.  
  1824. function calcDistance(coord1,coord2)
  1825. {
  1826. let x1=parseInt(coord1.split("|")[0])
  1827. let y1=parseInt(coord1.split("|")[1])
  1828. let x2=parseInt(coord2.split("|")[0])
  1829. let y2=parseInt(coord2.split("|")[1])
  1830.  
  1831. return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
  1832.  
  1833.  
  1834. }
  1835.  
  1836. function intervalHour(time_start,time_end,time_target){//check if attack lands on bonus time
  1837. if(time_start==0)
  1838. time_start=23*3600*1000+40*60000;
  1839. else
  1840. time_start-=20*60000;
  1841.  
  1842. if(time_start<time_end){
  1843. return(time_target>time_start && time_target<time_end)?true:false
  1844. }
  1845. else{
  1846. return ((time_target>time_end && time_target<time_start))?false:true
  1847. }
  1848. }
  1849.  
  1850.  
  1851. function uploadFile(data,filename,dropboxToken){ // upload file into dropbox
  1852. return new Promise((resolve,reject)=>{
  1853. var file = new Blob([data], {type: "plain/text"});
  1854. var nr_start1=new Date().getTime();
  1855. file.name=filename;
  1856.  
  1857. //stop refreshing the page
  1858. $(document).bind("keydown", disableF5);
  1859. window.onbeforeunload = function (e) {
  1860. console.log("is uploading");
  1861. return "are you sure?";
  1862. };
  1863.  
  1864. var xhr = new XMLHttpRequest();
  1865. xhr.upload.onprogress = function(evt) {
  1866. console.log(evt)
  1867. var percentComplete = parseInt(100.0 * evt.loaded / evt.total);
  1868. console.log(percentComplete)
  1869. UI.SuccessMessage("progress upload: "+percentComplete+"%")
  1870. };
  1871.  
  1872. xhr.onload = function() {
  1873. if (xhr.status === 200) {
  1874. var fileInfo = JSON.parse(xhr.response);
  1875. // Upload succeeded. Do something here with the file info.
  1876. UI.SuccessMessage("upload succes")
  1877. var nr_stop1=new Date().getTime();
  1878. console.log("time upload: "+(nr_stop1-nr_start1))
  1879.  
  1880. //enable refresh page
  1881. window.onbeforeunload = function (e) {
  1882. console.log("done");
  1883. };
  1884. $(document).unbind("keydown", disableF5);
  1885.  
  1886. resolve("succes")
  1887.  
  1888. }
  1889. else {
  1890. var errorMessage = xhr.response || 'Unable to upload file';
  1891. // Upload failed. Do something here with the error.
  1892. UI.SuccessMessage("upload failed")
  1893. reject(errorMessage)
  1894. }
  1895. };
  1896.  
  1897. xhr.open('POST', 'https://content.dropboxapi.com/2/files/upload');
  1898. xhr.setRequestHeader('Authorization', 'Bearer ' + dropboxToken);
  1899. xhr.setRequestHeader('Content-Type', 'application/octet-stream');
  1900. xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
  1901. path: '/' + file.name,
  1902. mode: 'add',
  1903. autorename: true,
  1904. mode:'overwrite',
  1905. mute: false
  1906. }));
  1907.  
  1908. xhr.send(file)
  1909. })
  1910. }
  1911.  
  1912. function disableF5(e) { if ((e.which || e.keyCode) == 116 || (e.which || e.keyCode) == 82) e.preventDefault(); };
  1913.  
  1914.  
  1915. function readFileDropbox(filename){// read file from dropbox
  1916. return new Promise((resolve,reject)=>{
  1917. $.ajax({
  1918. url: "https://content.dropboxapi.com/2/files/download",
  1919. method: 'POST',
  1920. dataType: "text",
  1921. headers: { 'Authorization': 'Bearer ' + dropboxToken,
  1922. 'Dropbox-API-Arg': JSON.stringify({path: "/"+filename})},
  1923.  
  1924. success: (data) => {
  1925. resolve(data)
  1926. },error: (err)=>{
  1927. console.log(err)
  1928. reject(err)
  1929. }
  1930. })
  1931. })
  1932. }
  1933.  
  1934.  
  1935. function lzw_encode (s) {//data compression
  1936. if (!s) return s;
  1937. var dict = new Map(); // Use a Map!
  1938. var data = (s + "").split("");
  1939. var out = [];
  1940. var currChar;
  1941. var phrase = data[0];
  1942. var code = 256;
  1943. for (var i = 1; i < data.length; i++) {
  1944. currChar = data[i];
  1945. if (dict.has(phrase + currChar)) {
  1946. phrase += currChar;
  1947. } else {
  1948. out.push (phrase.length > 1 ? dict.get(phrase) : phrase.codePointAt(0));
  1949. dict.set(phrase + currChar, code);
  1950. code++;
  1951. if (code === 0xd800) { code = 0xe000; }
  1952. phrase = currChar;
  1953. }
  1954. }
  1955. out.push (phrase.length > 1 ? dict.get(phrase) : phrase.codePointAt(0));
  1956. for (var i = 0; i < out.length; i++) {
  1957. out[i] = String.fromCodePoint(out[i]);
  1958. }
  1959. //console.log ("LZW MAP SIZE", dict.size, out.slice (-50), out.length, out.join("").length);
  1960. return out.join("");
  1961. }
  1962.  
  1963. function lzw_decode (s) {//data decompression
  1964. var dict = new Map(); // Use a Map!
  1965. var data = Array.from(s + "");
  1966. //var data = (s + "").split("");
  1967. var currChar = data[0];
  1968. var oldPhrase = currChar;
  1969. var out = [currChar];
  1970. var code = 256;
  1971. var phrase;
  1972. for (var i = 1; i < data.length; i++) {
  1973. var currCode = data[i].codePointAt(0);
  1974. if (currCode < 256) {
  1975. phrase = data[i];
  1976. } else {
  1977. phrase = dict.has(currCode) ? dict.get(currCode) : (oldPhrase + currChar);
  1978. }
  1979. out.push(phrase);
  1980. var cp = phrase.codePointAt(0);
  1981. currChar = String.fromCodePoint(cp); //phrase.charAt(0);
  1982. dict.set(code, oldPhrase + currChar);
  1983. code++;
  1984. if (code === 0xd800) { code = 0xe000; }
  1985. oldPhrase = phrase;
  1986. }
  1987. return out.join("");
  1988. }
  1989.  
  1990. function replaceSpecialCaracters(data){//some special data cannot be compressed
  1991. let result=""
  1992. for(let i=0;i<data.length;i++){
  1993. if(data[i]=="ț")
  1994. result+='t'
  1995. else if(data[i]=="Ț")
  1996. result+="T"
  1997. else if(data[i]=="Ă")
  1998. result+="A"
  1999. else if(data[i]=="ă")
  2000. result+="a"
  2001. else if(data[i]=="Â")
  2002. result+="A"
  2003. else if(data[i]=="Ș")
  2004. result+="S"
  2005. else if(data[i]=="ș")
  2006. result+="s"
  2007. else if(data[i]=="Î")
  2008. result+="I"
  2009. else if(data[i]=="î")
  2010. result+="i"
  2011. else
  2012. result+=data[i]
  2013. }
  2014. return result
  2015.  
  2016.  
  2017.  
  2018.  
  2019. }
  2020.  
  2021. function checkPageRun(){//check if the script is run on the right page
  2022. let href=window.location.href
  2023. if(href.includes("screen=place")){
  2024. let list_href=JSON.parse(localStorage.getItem(game_data.world+"launchFakes"));
  2025. if(list_href.length>0){
  2026. let current_href=list_href.pop();
  2027. localStorage.setItem(game_data.world+"launchFakes",JSON.stringify(list_href));
  2028. UI.SuccessMessage("left "+list_href.length+" fakes",1000);
  2029.  
  2030. window.open(current_href,"_self");
  2031. throw new Error("fake sent");// i don't like this throw error here
  2032.  
  2033.  
  2034. }
  2035. }
  2036. else if(document.getElementById("combined_table")==null){
  2037. alert("the script must be run from overview_villages&mode=combined ")
  2038. window.location.href=game_data.link_base_pure+"overview_villages&mode=combined"
  2039. throw new Error("wrong page");
  2040.  
  2041. }
  2042.  
  2043. }
  2044.  
  2045.  
  2046. async function startFakes(){
  2047. let mapTroupes=new Map();
  2048. let mapInfoVillages=await getInfoVIllages();
  2049. let selectModLaunch=document.getElementById("select_option_fakes").value
  2050. let selectAttack=document.getElementById("select_type_attack").value
  2051. let landSpecific=$(".set_troops input[type=checkbox][value=land_specific]:visible").prop("checked")
  2052. let nrFakesPerVillage=parseInt(document.getElementById("nr_fakes_per_village").value)
  2053.  
  2054.  
  2055. let nrFakes=parseInt(document.getElementById("nr_fakes").value)
  2056. let nrSplits=parseInt(document.getElementById("nr_split").value)
  2057. let minPop=parseInt($(".min_pop:visible").val())
  2058. nrSplits=(Number.isNaN(nrSplits)==true || nrSplits==0)?5:nrSplits
  2059. nrFakes=(Number.isNaN(nrFakes)==true || nrFakes==0)?1:nrFakes
  2060. minPop=(Number.isNaN(minPop)==true || minPop==0)?200:minPop
  2061. nrFakesPerVillage=(Number.isNaN(nrFakesPerVillage)==true || nrFakesPerVillage==0)?4:nrFakesPerVillage
  2062. nrFakesPerVillage--
  2063.  
  2064. let start_window = new Date($(".set_troops .start_window:visible").val())
  2065. let stop_window = new Date($(".set_troops .stop_window:visible").val())
  2066. if(start_window == "Invalid Date"){
  2067. UI.ErrorMessage("set start window",1500)
  2068. throw new Error("set start window")
  2069. }
  2070. if(stop_window == "Invalid Date"){
  2071. UI.ErrorMessage("set stop window",1500)
  2072. throw new Error("set stop window")
  2073. }
  2074. if(stop_window.getTime() - start_window.getTime() < 0){
  2075. UI.ErrorMessage("right interval must be higher than left one",2000)
  2076. throw new Error("right interval must be higher than left one")
  2077. }
  2078.  
  2079.  
  2080. let listFakesTemplate=[];
  2081. let ally_tribe=JSON.parse((dropbox_ally=="")?"[]":dropbox_ally ).map(e=>{return e.allyId})
  2082.  
  2083. let bonusNight=getBonusNight();
  2084. console.log("mapInfoVillages",mapInfoVillages)
  2085.  
  2086.  
  2087.  
  2088. //after btn open tab is pressed get tropps again
  2089. if(document.getElementsByClassName("open_tab").length>0){
  2090. let start=new Date().getTime();
  2091. let text_page=httpGet(window.location.href)
  2092. let table=text_page.match(/<table id="combined_table"((.|\n)+)/)[0].split("<\/table>")[0]+"</table>"
  2093. document.getElementById("combined_table").innerHTML=table
  2094. let stop=new Date().getTime();
  2095. console.log("get combined page in: "+(stop-start)+" ms")
  2096. }
  2097.  
  2098.  
  2099. //////////////////////////////////////////////////////////////get template////////////////////////////////////////////////////////////////
  2100. let limitFake=getFakeLimit()/100;
  2101. console.log(limitFake)
  2102. for(let i=0;i<unitsLength;i++){
  2103. let troupeName=units[i]
  2104. let nrTroupe=document.getElementById(troupeName+"Troupe").value
  2105. mapTroupes.set(troupeName,nrTroupe)
  2106. }
  2107.  
  2108. let table_combined=document.getElementById("combined_table").getElementsByTagName("tr")
  2109. let select_type=document.getElementById("select_type_attack").value
  2110.  
  2111. if(select_type=="fakes"){
  2112. if(limitFake>0){
  2113. for(let i=1;i<table_combined.length;i++){
  2114. let vectorTroupes=Array.from(table_combined[i].getElementsByClassName("unit-item")).map(e=>{return parseInt(e.innerText)})
  2115. let currentCoord=table_combined[i].getElementsByClassName("quickedit-label")[0].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
  2116. let linkBase=table_combined[i].getElementsByClassName("quickedit-content")[0].getElementsByTagName("a")[0].href.replace("overview","place")
  2117. let villagePoints=mapInfoVillages.get(currentCoord).points
  2118. let villageId=mapInfoVillages.get(currentCoord).villageId
  2119. // console.log(linkBase)
  2120. let limitPop=parseInt(villagePoints*limitFake)+10;
  2121. // console.log("troupes available")
  2122. // console.log(vectorTroupes)
  2123. let availableTroupes={}
  2124. let totalPop=0;
  2125. Array.from(mapTroupes.keys()).forEach((key,index)=>{
  2126. let selectNameTroupe=key;
  2127. let selectValueTroupe=mapTroupes.get(key)
  2128. let currentTroupe=vectorTroupes[index]
  2129.  
  2130. if(selectValueTroupe!=0){
  2131. if(currentTroupe>nrFakes){
  2132. if(selectValueTroupe>0 && currentTroupe >= selectValueTroupe * nrFakes){
  2133. availableTroupes[selectNameTroupe]={
  2134. value:selectValueTroupe * nrFakes,
  2135. static:"true"
  2136. }
  2137. totalPop+=nrFakes*troupesPop[selectNameTroupe]*selectValueTroupe
  2138. }
  2139. else{
  2140. availableTroupes[selectNameTroupe]={
  2141. value:currentTroupe,
  2142. static:"false"
  2143. }
  2144. totalPop+=currentTroupe*troupesPop[selectNameTroupe]
  2145.  
  2146. }
  2147. }
  2148. }
  2149.  
  2150. })
  2151. let availableFakesTotal=totalPop/limitPop;
  2152. // console.log("current coord "+currentCoord)
  2153. // console.log(availableTroupes)
  2154. // console.log("limit pop "+limitPop)
  2155. // console.log("total pop "+totalPop)
  2156. // console.log("nr possible fakes "+availableFakesTotal)
  2157. let templateFakes={}
  2158. let totalPopTemplate=0;
  2159. Object.keys(availableTroupes).forEach(key=>{
  2160. if(availableFakesTotal>1.2){
  2161. if(availableTroupes[key].static=="false"){
  2162. let troupeTemplate=Math.ceil(availableTroupes[key].value/availableFakesTotal)
  2163. templateFakes[key]=troupeTemplate
  2164. totalPopTemplate+=troupeTemplate*troupesPop[key]
  2165. }else{
  2166. let troupeTemplate=availableTroupes[key].value/nrFakes
  2167. templateFakes[key]=troupeTemplate
  2168. totalPopTemplate+=troupeTemplate*troupesPop[key]
  2169.  
  2170. }
  2171. }
  2172. })
  2173. // console.log("templateFakes")
  2174. // console.log(templateFakes)
  2175. // console.log("total pop sent "+totalPopTemplate)
  2176. for(let k=0;k<30;k++){
  2177. Object.keys(templateFakes).forEach(key=>{
  2178. if(totalPopTemplate-limitPop>=1 && troupesPop[key]==1){
  2179. templateFakes[key]=templateFakes[key]-1;
  2180. totalPopTemplate--;
  2181. }
  2182. if(totalPopTemplate-limitPop>=2 && troupesPop[key]==2 && k%2==0 && availableTroupes[key].static=="false" ){
  2183. templateFakes[key]=templateFakes[key]-1;
  2184. totalPopTemplate-=2;
  2185. }
  2186. if(totalPopTemplate-limitPop>=4 && troupesPop[key]==4 && k%2==0){
  2187. templateFakes[key]=templateFakes[key]-1;
  2188. totalPopTemplate-=4;
  2189. }
  2190. if(totalPopTemplate-limitPop>=6 && troupesPop[key]==6 && k%4==0){
  2191. templateFakes[key]=templateFakes[key]-1;
  2192. totalPopTemplate-=6;
  2193. }
  2194. //rams
  2195. if(totalPopTemplate-limitPop>=5 && troupesPop[key]==5 && k%5==0 && templateFakes[key]>1 ){
  2196. // console.log("remove ram")
  2197. templateFakes[key]=templateFakes[key]-1;
  2198. totalPopTemplate-=5;
  2199. }
  2200. //cats
  2201. if(totalPopTemplate-limitPop>=8 && troupesPop[key]==8 && k%5==0 && templateFakes[key]>1){
  2202. // console.log("remove cat")
  2203. templateFakes[key]=templateFakes[key]-1;
  2204. totalPopTemplate-=8;
  2205. }
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  
  2211. if(templateFakes[key]==0){
  2212. delete templateFakes[key]
  2213. }
  2214.  
  2215. })
  2216. if(totalPopTemplate==limitPop)
  2217. break;
  2218. }
  2219. // console.log("templateFakes")
  2220. // console.log()
  2221. // console.log("total pop sent "+totalPopTemplate)
  2222. // Object.keys(templateFakes).forEach(key=>{console.log(key+" "+templateFakes[key])})
  2223. // console.log("-------------------------------------------------------------------------------")
  2224. let minFakes=Math.min(nrFakes,parseInt(availableFakesTotal))
  2225.  
  2226. if(availableFakesTotal>1.2 &&(templateFakes["ram"]>=1 || templateFakes["catapult"]>=1)){
  2227. listFakesTemplate.push({
  2228. templateFakes:templateFakes,
  2229. nrFakes:minFakes,
  2230. limitPop:limitPop,
  2231. totalPopTemplate:totalPopTemplate,
  2232. linkBase:linkBase,
  2233. coordOrigin:currentCoord,
  2234. speedTroop:ramSpeed,
  2235. nrCells:mapTroupes.size
  2236. })
  2237. }
  2238. }
  2239. }
  2240. else{
  2241. for(let i=1;i<table_combined.length;i++){
  2242.  
  2243. let vectorTroupes=Array.from(table_combined[i].getElementsByClassName("unit-item")).map(e=>{return parseInt(e.innerText)})
  2244. let currentCoord=table_combined[i].getElementsByClassName("quickedit-label")[0].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
  2245. let linkBase=table_combined[i].getElementsByClassName("quickedit-content")[0].getElementsByTagName("a")[0].href.replace("overview","place")
  2246. console.log("linkBase",linkBase)
  2247. console.log("vectorTroupes",vectorTroupes)
  2248. let availableTroupes={}
  2249. Array.from(mapTroupes.keys()).forEach((key,index)=>{
  2250. let selectNameTroupe=key;
  2251. let selectValueTroupe=mapTroupes.get(key)
  2252. let currentTroupe=vectorTroupes[index]
  2253.  
  2254. if(selectValueTroupe > 0 && selectValueTroupe != "min" && (selectNameTroupe=="spy" ||selectNameTroupe=="ram"|| selectNameTroupe=="catapult" )){
  2255. if(currentTroupe >= selectValueTroupe*nrFakes ){
  2256. availableTroupes[selectNameTroupe]=selectValueTroupe*nrFakes
  2257. }
  2258. }
  2259. })
  2260. console.log("availableTroupes",availableTroupes)
  2261. let templateFakes={}
  2262.  
  2263. if(availableTroupes["spy"]>=nrFakes && availableTroupes["ram"]>=nrFakes){
  2264. templateFakes["spy"]=parseInt(availableTroupes["spy"]/nrFakes)
  2265. templateFakes["ram"]=parseInt(availableTroupes["ram"]/nrFakes)
  2266. }
  2267. else if(availableTroupes["spy"] >= nrFakes && availableTroupes["catapult"] >= nrFakes){
  2268. templateFakes["spy"] = parseInt(availableTroupes["spy"]/nrFakes)
  2269. templateFakes["catapult"] = parseInt(availableTroupes["catapult"]/nrFakes)
  2270. }
  2271. else if( availableTroupes["ram"]>=nrFakes){
  2272. templateFakes["ram"] = parseInt(availableTroupes["ram"]/nrFakes)
  2273. }
  2274. else if( availableTroupes["catapult"]>=nrFakes){
  2275. templateFakes["catapult"] = parseInt(availableTroupes["catapult"]/nrFakes)
  2276. }
  2277.  
  2278. console.log("-------------------------------------------------------------------------------")
  2279. if(templateFakes["ram"]>=1 || templateFakes["catapult"]>=1){
  2280. listFakesTemplate.push({
  2281. templateFakes:templateFakes,
  2282. nrFakes:nrFakes,
  2283. limitPop:0,
  2284. totalPopTemplate:0,
  2285. linkBase:linkBase,
  2286. coordOrigin:currentCoord,
  2287. speedTroop:ramSpeed,
  2288. nrCells:mapTroupes.size
  2289.  
  2290. })
  2291. }
  2292. }
  2293.  
  2294. }
  2295. }
  2296. else{//nukes/fangs
  2297. let send_troops=Array.from($(".allinputTroops input:visible")).map(e=>parseInt(e.value))
  2298. let reserve_troops=Array.from($(".allinputTroopsRes input:visible")).map(e=>parseInt(e.value))
  2299. for(let i=0;i<unitsLength;i++){
  2300. send_troops[i]=(Number.isNaN(send_troops[i])==true || send_troops[i]<0)?0:send_troops[i]
  2301. reserve_troops[i]=(Number.isNaN(reserve_troops[i])==true || reserve_troops[i]<0)?0:reserve_troops[i]
  2302. }
  2303. console.log("send_troops",send_troops)
  2304. console.log("reserve_troops",reserve_troops)
  2305.  
  2306. for(let i=1;i<table_combined.length;i++){
  2307. let vectorTroupes=Array.from(table_combined[i].getElementsByClassName("unit-item")).map(e=>{return parseInt(e.innerText)})
  2308. let currentCoord=table_combined[i].getElementsByClassName("quickedit-label")[0].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
  2309. let linkBase=table_combined[i].getElementsByClassName("quickedit-content")[0].getElementsByTagName("a")[0].href.replace("overview","place")
  2310. let villagePoints=mapInfoVillages.get(currentCoord).points
  2311. let villageId=mapInfoVillages.get(currentCoord).villageId
  2312. let availableTroupes={}
  2313.  
  2314. let pop=0
  2315. for(let j=0;j<send_troops.length;j++){
  2316.  
  2317. let name_troop = units[j]
  2318. vectorTroupes[j] -= reserve_troops[j]
  2319. let value_troop = Math.min(vectorTroupes[j], send_troops[j])
  2320. // console.log(`name ${name_troop}: value: ${value_troop} vector:${vectorTroupes[i]}, send:${send_troops[j]}`)
  2321. value_troop = (value_troop<= 0) ? 0 : value_troop
  2322. availableTroupes[name_troop] = value_troop
  2323. pop+=troupesPop[name_troop] * value_troop
  2324. }
  2325.  
  2326. // console.log("vectorTroupes",vectorTroupes)
  2327.  
  2328. // console.log("availableTroupes",availableTroupes)
  2329.  
  2330. let speedTroop=ramSpeed
  2331. if(availableTroupes["snob"] > 0)
  2332. speedTroop=nobleSpeed
  2333. else if(availableTroupes["ram"] > 0 || availableTroupes["catapult"] > 0){
  2334. speedTroop=ramSpeed
  2335. }
  2336. else if(availableTroupes["sword"] > 0){
  2337. speedTroop=swordSpeed
  2338. }
  2339. else if(availableTroupes["spear"] > 0 || availableTroupes["axe"] > 0 || availableTroupes["archer"] > 0){
  2340. speedTroop=axeSpeed
  2341. }
  2342. else if(availableTroupes["light"] > 0 || availableTroupes["heavy"] > 0 || availableTroupes["marcher"] > 0){
  2343. speedTroop=axeSpeed
  2344. }
  2345. else{
  2346. speedTroop=scoutSpeed
  2347. }
  2348.  
  2349.  
  2350. // console.log(`${pop} >= ${minPop}`)
  2351. if(pop >= minPop){
  2352. // console.log(`availableTroupes:`,availableTroupes)
  2353. listFakesTemplate.push({
  2354. templateFakes:availableTroupes,
  2355. linkBase:linkBase,
  2356. coordOrigin:currentCoord,
  2357. speedTroop:speedTroop,
  2358. nrFakes:1,
  2359. nrCells:send_troops.length
  2360. })
  2361. }
  2362. }
  2363. }
  2364.  
  2365.  
  2366.  
  2367.  
  2368. shuffleArray(listFakesTemplate)
  2369. console.log("listFakesTemplate",listFakesTemplate)
  2370.  
  2371. /////////////////////////////////////////////////////////////////get list of coords/////////////////////////////////////////////////////////////////////
  2372. let list_coords=document.getElementsByClassName("panel active")[0].getElementsByTagName("textarea")[0].value.match(/[0-9]{3}\|[0-9]{3}/g)
  2373. if(list_coords==null){
  2374. console.log("no coords")
  2375. return
  2376. }
  2377. //eliminate duplicates only for fakes
  2378. if(selectAttack == "fakes"){
  2379. let set=new Set(list_coords)
  2380. list_coords=Array.from(set)
  2381. console.log("remove duplicates")
  2382. }
  2383. console.log("list_coords",list_coords)
  2384. //eliminate non existent coords and barbs coords
  2385. for(let i=0;i<list_coords.length;i++){
  2386. if(!mapInfoVillages.has(list_coords[i])){//don't exist
  2387. list_coords.splice(i,1);
  2388. i--;
  2389. }else if(mapInfoVillages.get(list_coords[i]).playerId=="0"){// it is a barb
  2390. list_coords.splice(i,1);
  2391. i--;
  2392. }
  2393. }
  2394. //add bonus night,if it is active, to each village
  2395. let map_idPlayers=new Map()
  2396. if(bonusNight.active==2){
  2397. for(let i=0;i<list_coords.length;i++){
  2398. map_idPlayers.set(mapInfoVillages.get(list_coords[i]).playerId,{
  2399. playerId:mapInfoVillages.get(list_coords[i]).playerId,
  2400. villageId:mapInfoVillages.get(list_coords[i]).villageId
  2401. })
  2402. }
  2403. map_idPlayers=await getBonusNightForEach(Array.from(map_idPlayers.values()))
  2404. console.log(map_idPlayers)
  2405. console.log("bonus level 2")
  2406. }
  2407. else if(bonusNight.active==1){
  2408. map_idPlayers=new Map()
  2409. for(let i=0;i<list_coords.length;i++){
  2410. map_idPlayers.set(mapInfoVillages.get(list_coords[i]).playerId,{
  2411. start_hour:bonusNight.start_hour+":00",
  2412. end_hour:bonusNight.end_hour+":00"
  2413. })
  2414. }
  2415. console.log(map_idPlayers)
  2416. console.log("bonus level 1")
  2417.  
  2418.  
  2419. }
  2420. //eliminate allies coords
  2421. if(ally_tribe.length>0){
  2422. for(let i=0;i<list_coords.length;i++){
  2423. let infoVillage=mapInfoVillages.get(list_coords[i])
  2424. if(infoVillage==undefined){
  2425. list_coords.splice(i,1)
  2426. i--;
  2427. }
  2428. else if(ally_tribe.includes(infoVillage.allyId)){
  2429. list_coords.splice(i,1)
  2430. i--;
  2431. }
  2432. }
  2433. }
  2434. shuffleArray(list_coords)
  2435. console.log(list_coords)
  2436. let list_href=[];
  2437. let k=0;
  2438.  
  2439. let list_info_launch=[]
  2440. let map_nr_destination=new Map()
  2441. for(let i=0;i<listFakesTemplate.length;i++){
  2442. let repeatforNukes=false
  2443.  
  2444. let obj=listFakesTemplate[i]
  2445. obj.nr_from=0
  2446. for(let j=0;j<obj.nrFakes;j++){
  2447. let found_target=false
  2448.  
  2449. let href=obj.linkBase+"&";
  2450. Object.keys(obj.templateFakes).forEach(key=>{
  2451. href+=key+"="+obj.templateFakes[key]+"&"
  2452. })
  2453.  
  2454. //if bonus night exist
  2455. if(bonusNight.active==1 || bonusNight.active==2){
  2456. for(let l=k;l<list_coords.length;l++){
  2457. let time_travel = calcDistance(obj.coordOrigin,list_coords[l]) * (ramSpeed)//time travel for ram speed
  2458. let serverTime=document.getElementById("serverTime").innerText
  2459. let serverDate=document.getElementById("serverDate").innerText.split("/")
  2460. serverDate=serverDate[1]+"/"+serverDate[0]+"/"+serverDate[2]
  2461.  
  2462. let date_current=new Date(serverDate+" "+serverTime).getTime()
  2463. date_current=new Date(date_current+time_travel)
  2464. console.log('coord '+list_coords[l])
  2465. console.log("landing time:"+date_current)
  2466.  
  2467. let start_hour=map_idPlayers.get(mapInfoVillages.get(list_coords[l]).playerId).start_hour
  2468. let end_hour=map_idPlayers.get(mapInfoVillages.get(list_coords[l]).playerId).end_hour
  2469. console.log("bonus night interval: "+start_hour+":"+end_hour)
  2470.  
  2471. let time_start=parseInt(start_hour.split(":")[0])*3600*1000+parseInt(start_hour.split(":")[1])*60000
  2472. let time_end=parseInt(end_hour.split(":")[0])*3600*1000+parseInt(end_hour.split(":")[1])*60000
  2473. let time_target=date_current.getHours()*3600*1000+date_current.getMinutes()*60000+date_current.getSeconds()*1000
  2474.  
  2475.  
  2476. //this part is for fakes
  2477. if(landSpecific==true){//only if checkbox for window si selected
  2478. let coord_origin=obj.coordOrigin
  2479. for(let l=k;l<list_coords.length;l++){
  2480. let coord_target=list_coords[l];
  2481. if(intervalHour(time_start,time_end,time_target)==false && checkWindow(start_window,stop_window,coord_origin,coord_target,obj.speedTroop)==true){//check if attack lands inside the window
  2482. href+="x="+coord_target.split("|")[0]+"&y="+coord_target.split("|")[1]+"&"
  2483. found_target=true
  2484.  
  2485. if(select_type=="nukes" || select_type=="fangs"){
  2486. list_coords.splice(k,1)
  2487. }else{
  2488. if(map_nr_destination.has(coord_target)){//check if coord dest exist and then check if there are enough fakes
  2489. if(map_nr_destination.get(coord_target)>=nrFakesPerVillage){
  2490. list_coords.splice(k,1)
  2491. }
  2492. else
  2493. k++
  2494. }
  2495. else
  2496. k++
  2497. }
  2498.  
  2499. let landing_time=calculateLandingTime(coord_origin,coord_target,obj.speedTroop)
  2500. obj.coordDestination=coord_target
  2501. obj.nr_from = obj.nr_from + 1
  2502. obj.landing_time=landing_time
  2503. break;
  2504. }
  2505. k++
  2506. }
  2507. }
  2508. else{
  2509. let coord_origin=obj.coordOrigin
  2510. let coord_target=list_coords[l];
  2511. if(intervalHour(time_start,time_end,time_target)==false){
  2512. console.log("it is not on bonus night")
  2513. href+="x="+list_coords[l].split("|")[0]+"&y="+list_coords[l].split("|")[1]+"&"
  2514. found_target=true
  2515.  
  2516. if(select_type=="nukes" || select_type=="fangs"){
  2517. list_coords.splice(k,1)
  2518. }else{
  2519. if(map_nr_destination.has(coord_target)){//check if coord dest exist and then check if there are enough fakes
  2520. // console.log(`number baaaa: ${map_nr_destination.get(coord_origin)}`)
  2521.  
  2522. if(map_nr_destination.get(coord_target)>=nrFakesPerVillage){
  2523. list_coords.splice(k,1)
  2524. }
  2525. else
  2526. k++
  2527.  
  2528. }
  2529. else
  2530. k++
  2531. }
  2532. let landing_time=calculateLandingTime(coord_origin,coord_target,obj.speedTroop)
  2533. obj.coordDestination=coord_target
  2534. obj.nr_from = obj.nr_from + 1
  2535. obj.landing_time=landing_time
  2536. break;
  2537. }
  2538. k++;
  2539. }
  2540.  
  2541. //this part is for nukes
  2542. if(select_type=="nukes" && found_target==false){
  2543.  
  2544. }
  2545.  
  2546. }
  2547. }
  2548. else{ //sending fakes/nukes/fangs when bonus night is off
  2549.  
  2550. if(landSpecific==true){//only if checkbox for window si selected
  2551. let coord_origin=obj.coordOrigin
  2552. for(let l=k;l<list_coords.length;l++){
  2553. let coord_target=list_coords[l];
  2554. if(checkWindow(start_window,stop_window,coord_origin,coord_target,obj.speedTroop)==true){//check if attack lands inside the window
  2555. href+="x="+coord_target.split("|")[0]+"&y="+coord_target.split("|")[1]+"&"
  2556. found_target=true
  2557. if(select_type=="nukes" || select_type=="fangs"){
  2558. list_coords.splice(k,1)
  2559. }else{
  2560. if(map_nr_destination.has(coord_target)){//check if coord dest exist and then check if there are enough fakes
  2561. // console.log(`number baaaa: ${map_nr_destination.get(coord_origin)}`)
  2562.  
  2563. if(map_nr_destination.get(coord_target)>=nrFakesPerVillage){
  2564. list_coords.splice(k,1)
  2565. console.log(list_coords)
  2566.  
  2567. }
  2568. else
  2569. k++
  2570.  
  2571. }
  2572. else
  2573. k++
  2574. }
  2575. let landing_time=calculateLandingTime(coord_origin,coord_target,obj.speedTroop)
  2576. obj.coordDestination=coord_target
  2577. obj.nr_from = obj.nr_from + 1
  2578. obj.landing_time=landing_time
  2579. break;
  2580. }
  2581. k++
  2582. }
  2583. }
  2584. else{//just land whenever is possible
  2585. if(list_coords.length==0)
  2586. break;
  2587.  
  2588.  
  2589. let coord_target=list_coords[k];
  2590. let coord_origin=obj.coordOrigin
  2591. href+="x="+coord_target.split("|")[0]+"&y="+coord_target.split("|")[1]+"&"
  2592. found_target=true
  2593. if(select_type=="nukes" || select_type=="fangs"){
  2594. list_coords.splice(k,1)
  2595. }else{
  2596. k++;
  2597. }
  2598.  
  2599. let landing_time=calculateLandingTime(coord_origin,coord_target,obj.speedTroop)
  2600. obj.coordDestination=coord_target
  2601. obj.nr_from = obj.nr_from + 1
  2602. obj.landing_time=landing_time
  2603.  
  2604.  
  2605.  
  2606. }
  2607. }
  2608. // console.log(list_coords)
  2609. if(found_target==true){
  2610. if(map_nr_destination.has(obj.coordDestination)){//count +1 if exist
  2611. let nr_update=map_nr_destination.get(obj.coordDestination)+1
  2612. map_nr_destination.set(obj.coordDestination,nr_update)
  2613. }else{
  2614. map_nr_destination.set(obj.coordDestination,1)
  2615.  
  2616. }
  2617. obj.coordOriginId=mapInfoVillages.get(obj.coordOrigin).villageId
  2618. obj.coordDestinationId=mapInfoVillages.get(obj.coordDestination).villageId
  2619. list_info_launch.push(obj)
  2620. // console.log(obj)
  2621. list_href.push(href)
  2622. }
  2623. if(k==list_coords.length){
  2624. k=0;
  2625. }
  2626.  
  2627. // console.log(`${i} found_target: ${found_target}`)
  2628. if(select_type=="nukes" && found_target==false && repeatforNukes==false){//if there is a nuke to send and it hasn't found a target yet repeat alg again one more time
  2629. // console.log(`repeat loop for ${i}`)
  2630. j--
  2631. repeatforNukes=true
  2632. }
  2633.  
  2634.  
  2635. }
  2636. }
  2637. //add number of attacks per village
  2638. console.log("map_nr_destination",map_nr_destination)
  2639. for(let i=0;i<list_info_launch.length;i++){
  2640. let nr_to=map_nr_destination.get(list_info_launch[i].coordDestination)
  2641. list_info_launch[i].nr_to=nr_to
  2642. }
  2643. console.log("list_info_launch",list_info_launch)
  2644.  
  2645.  
  2646. list_info_launch.sort((o1,o2)=>{
  2647. return (new Date(o1.landing_time).getTime() > new Date(o2.landing_time).getTime())?1:
  2648. (new Date(o1.landing_time).getTime() < new Date(o2.landing_time).getTime())?-1:0
  2649.  
  2650. })
  2651. $(".hide_btn_show").show()
  2652. if(document.getElementsByClassName("active")[0].classList.contains("own") && ( select_type=="nukes" || select_type=="fangs")){
  2653. $(".hide_btn_delete").show()
  2654. }else{
  2655. $(".hide_btn_delete").hide()
  2656. }
  2657.  
  2658. $("#btn_show").off("click")
  2659. $("#btn_show").on("click",()=>{
  2660. showLaunches(list_info_launch)
  2661. })
  2662.  
  2663. //only for nukes/fangs , delete coord
  2664. $("#btn_delete").off("click")
  2665. $("#btn_delete").on("click",()=>{
  2666. if(confirm("are you sure you want to delete coords?")){
  2667. console.log("delete coord")
  2668.  
  2669. if(document.getElementsByClassName("active")[0].classList.contains("own") && ( select_type=="nukes" || select_type=="fangs")){
  2670. if($(".active textarea").val().match(/[0-9]{3}\|[0-9]{3}/g)!=null){
  2671. let coords=Array.from($(".active textarea").val().match(/[0-9]{3}\|[0-9]{3}/g))
  2672. for(let i=0;i<list_info_launch.length;i++){
  2673. let index = coords.indexOf(list_info_launch[i].coordDestination);
  2674. console.log("index",index)
  2675. if (index !== -1) {
  2676. coords.splice(index, 1);
  2677. }
  2678. }
  2679. console.log("coords",coords)
  2680. $(".active textarea").val(coords.join(" "))
  2681. saveOwnData()
  2682.  
  2683.  
  2684. }
  2685. }
  2686.  
  2687. }
  2688. })
  2689.  
  2690. console.log("nrFakesPerVillage",nrFakesPerVillage)
  2691.  
  2692.  
  2693.  
  2694. shuffleArray(list_href)
  2695. console.log(list_href)
  2696.  
  2697. /////////////////////////////////////////////////////create button for tabs//////////////////////////////////////////
  2698.  
  2699. $(".open_tab").remove();
  2700. if(selectModLaunch=="open tabs"){
  2701.  
  2702. let nr_buttons=Math.ceil(list_href.length/nrSplits);
  2703. let delayTab=parseInt(document.getElementById("delay_tabs").value)
  2704. delayTab=(Number.isNaN(delayTab)==true || delayTab<200)?200:delayTab
  2705.  
  2706.  
  2707. for(let i=0;i<nr_buttons;i++){
  2708. // console.log("createButton")
  2709. let startFrom=i*nrSplits;
  2710. let stopTo=(i*nrSplits)+nrSplits
  2711. if((i*nrSplits)+nrSplits>list_href.length)
  2712. stopTo=list_href.length
  2713.  
  2714. let btn=document.createElement("button")
  2715. btn.classList="btn evt-confirm-btn btn-confirm-yes open_tab"
  2716. btn.innerText="[ "+startFrom+" - "+stopTo+" ]";
  2717. btn.style.margin="5px"
  2718. btn.onclick=function(){
  2719. let current_hrefs= list_href.slice(startFrom,stopTo)
  2720. // console.log(current_hrefs)
  2721. // console.log(btn)
  2722. btn.classList.remove("evt-confirm-btn")
  2723. btn.classList.remove("btn-confirm-yes")
  2724. btn.classList.add("btn-confirm-no")
  2725.  
  2726. for(let j=0;j<current_hrefs.length;j++){
  2727. window.setTimeout(()=>{
  2728. window.open(current_hrefs[j], '_blank')
  2729. console.log(new Date().getTime())
  2730. },delayTab*j)
  2731.  
  2732. }
  2733.  
  2734. $(".open_tab").prop('disabled', true)
  2735. window.setTimeout(()=>{
  2736. $(".open_tab").prop('disabled', false)
  2737. },delayTab*(stopTo-startFrom))
  2738.  
  2739.  
  2740. }
  2741. document.getElementById("div_open_tabs").appendChild(btn)
  2742.  
  2743. }
  2744.  
  2745. }
  2746. else if(selectModLaunch=="go to rally"){
  2747.  
  2748. console.log("go to rally");
  2749. let current_href=list_href.pop();
  2750. localStorage.setItem(game_data.world+"launchFakes",JSON.stringify(list_href))
  2751. window.open(current_href);
  2752. }
  2753. else{
  2754. UI.ErrorMessage("select option fake!")
  2755. }
  2756.  
  2757.  
  2758. }
  2759.  
  2760.  
  2761. function checkWindow(start_window,stop_window,coord_origin, coord_target,speedTroop){
  2762. let field = calcDistance(coord_origin,coord_target)
  2763. let time_travel = field * speedTroop
  2764. let serverTime = document.getElementById("serverTime").innerText
  2765. let serverDate = document.getElementById("serverDate").innerText.split("/")
  2766. serverDate=serverDate[1]+"/"+serverDate[0]+"/"+serverDate[2]
  2767. let date_current = new Date(serverDate+" "+serverTime).getTime()
  2768.  
  2769. let date_land = new Date(date_current+time_travel).getTime()
  2770.  
  2771. if(date_land >= start_window.getTime() && date_land <= stop_window.getTime())
  2772. return true
  2773. else
  2774. return false
  2775.  
  2776.  
  2777. }
  2778.  
  2779.  
  2780. function calculateLandingTime(coord_origin, coord_target,speedTroop){
  2781. let field = calcDistance(coord_origin,coord_target)
  2782. let time_travel = field * speedTroop
  2783. let serverTime = document.getElementById("serverTime").innerText
  2784. let serverDate = document.getElementById("serverDate").innerText.split("/")
  2785. serverDate=serverDate[1]+"/"+serverDate[0]+"/"+serverDate[2]
  2786. let date_current = new Date(serverDate+" "+serverTime).getTime()
  2787.  
  2788. let date_land = new Date(date_current+time_travel).getTime()
  2789. return parseDate(date_land)
  2790.  
  2791. }
  2792.  
  2793. function parseDate(time){
  2794. let date=new Date(time)
  2795.  
  2796. let year=date.getFullYear();
  2797. let month=("00"+(date.getMonth()+1)).slice(-2)
  2798. let day=("00"+date.getDate()).slice(-2)
  2799. let hours=("00"+date.getHours()).slice(-2)
  2800. let minutes=("00"+date.getMinutes()).slice(-2)
  2801. let seconds=("00"+date.getSeconds()).slice(-2)
  2802. let result=`${month}/${day}/${year} ${hours}:${minutes}:${seconds}`
  2803. return result
  2804. }
  2805.  
  2806.  
  2807. function showLaunches(list_info_launch){
  2808. // console.log("aici",list_info_launch)
  2809.  
  2810. let html_table=`
  2811. <table id="table_show" class="" style="width:100%;height:700px; overflow:auto;background-color:${getColorDarker(backgroundAlternateTableOdd,headerColorDarken)};">
  2812. <tr style=" position: sticky;top: 0;z-index: 10;">
  2813. <td style="text-align:center; width:auto; background-color:${getColorDarker(backgroundAlternateTableOdd,headerColorDarken)};border: 1px solid ${borderColor}">
  2814. <center style="margin:10px"><font color="${textColor}">nr</font></center>
  2815. </td>
  2816. <td style="text-align:center; width:auto; background-color:${getColorDarker(backgroundAlternateTableOdd,headerColorDarken)};border: 1px solid ${borderColor}" colspan="2">
  2817. <a href="#" id="order_by_from"><center style="margin:10px"><font color="${textColor}">from</font></center></a>
  2818. </td>
  2819. <td style="text-align:center; width:auto; background-color:${getColorDarker(backgroundAlternateTableOdd,headerColorDarken)};border: 1px solid ${borderColor}" colspan="2">
  2820. <a href="#" id="order_by_to"><center style="margin:10px"><font color="${textColor}">to</font></center></a>
  2821. </td>
  2822.  
  2823. `;
  2824. for(let i=0;i<units.length;i++){
  2825. if(units[i]!="militia" && units[i]!="snob"){
  2826. html_table+=`<td class="fm_unit hide_${units[i]}" style="text-align:center;width:auto; background-color:${getColorDarker(backgroundAlternateTableOdd,headerColorDarken)};margin:2px;border: 1px solid ${borderColor}"><img src="https://dsen.innogamescdn.com/asset/1d2499b/graphic/unit/unit_${units[i]}.png"></td>`
  2827. }
  2828. }
  2829. html_table+=`
  2830. <td style="text-align:center; width:auto; background-color:${getColorDarker(backgroundAlternateTableOdd,headerColorDarken)};border: 1px solid ${borderColor}">
  2831. <a href="#" id="order_by_landing"><center style="margin:10px"><font color="${textColor}">landing time</font></center></a>
  2832. </td>
  2833. </tr>
  2834. `
  2835. for(let i=0;i<list_info_launch.length;i++){
  2836. let header=(i%2==0)?backgroundAlternateTableEven:backgroundAlternateTableOdd
  2837.  
  2838. html_table+=`
  2839. <tr>
  2840. <td style="text-align:center; width:auto; background-color:${header};border: 1px solid ${borderColor}">
  2841. <center style="margin:5px"><font color="${textColor}">${i}</font></center>
  2842. </td>
  2843. <td style="text-align:center; width:auto; background-color:${header};border: 1px solid ${borderColor}" >
  2844. <a href="${game_data.link_base_pure}info_village&id=${list_info_launch[i].coordOriginId}"><center><font color="${textColor}">${list_info_launch[i].coordOrigin}</font></center></a>
  2845. </td>
  2846. <td style="text-align:center; width:auto; background-color:${header};border: 1px solid ${borderColor}" >
  2847. <center style="margin:5px"><font color="${textColor}">${list_info_launch[i].nr_from}</font></center>
  2848. </td>
  2849. <td style="text-align:center; width:auto; background-color:${header};border: 1px solid ${borderColor}" >
  2850. <a href="${game_data.link_base_pure}info_village&id=${list_info_launch[i].coordDestinationId}"><center><font color="${textColor}">${list_info_launch[i].coordDestination}</font></center></a>
  2851. </td>
  2852. <td style="text-align:center; width:auto; background-color:${header};border: 1px solid ${borderColor}" >
  2853. <center style="margin:5px"><font color="${textColor}">${list_info_launch[i].nr_to}</font></center>
  2854. </td>`
  2855. for(let j=0;j<list_info_launch[i].nrCells;j++){
  2856. let value=list_info_launch[i].templateFakes[units[j]]
  2857. value=(value==undefined)?0:value
  2858. let title=(value==0)?"#4f2f2f":"#00bf00"
  2859.  
  2860.  
  2861. html_table+=`
  2862. <td style="text-align:center; width:auto; background-color:${header};border: 1px solid ${borderColor}" >
  2863. <center style="margin:5px;font-weight: bold"><font color="${title}">${value}</font></center>
  2864. </td>`
  2865. }
  2866.  
  2867. html_table+=`
  2868. <td style="text-align:center; width:auto; background-color:${header};border: 1px solid ${borderColor}">
  2869. <center style="margin:5px"><font color="${textColor}">${list_info_launch[i].landing_time}</font></center>
  2870. </td>
  2871. </tr>`
  2872. }
  2873.  
  2874.  
  2875.  
  2876. html_table+=`</tbody></table>`
  2877. Dialog.show("content",html_table)
  2878. if($("#select_type_attack").val()=="fakes"){
  2879. $(".hide_knight").hide()
  2880. }
  2881.  
  2882. $("#order_by_from").on("click",()=>{
  2883. list_info_launch.sort((o1,o2)=>{
  2884. return (o1.nr_from > o2.nr_from)?-1:(o1.nr_from < o2.nr_from)?1:0
  2885. })
  2886. console.log("order by destination")
  2887. $(".popup_box_close").click()
  2888. showLaunches(list_info_launch)
  2889.  
  2890. })
  2891. $("#order_by_to").on("click",()=>{
  2892. list_info_launch.sort((o1,o2)=>{
  2893. return (o1.nr_to > o2.nr_to)?-1:(o1.nr_to < o2.nr_to)?1:0
  2894. })
  2895. console.log("order by origin")
  2896. console.log(list_info_launch)
  2897. $(".popup_box_close").click()
  2898. showLaunches(list_info_launch)
  2899.  
  2900. })
  2901. $("#order_by_landing").on("click",()=>{
  2902. list_info_launch.sort((o1,o2)=>{
  2903. return (new Date(o1.landing_time).getTime() > new Date(o2.landing_time).getTime())?1:
  2904. (new Date(o1.landing_time).getTime() < new Date(o2.landing_time).getTime())?-1:0
  2905. })
  2906. console.log("order by landing time")
  2907. $(".popup_box_close").click()
  2908. showLaunches(list_info_launch)
  2909.  
  2910. })
  2911. }
  2912.  
  2913.  
  2914.  
  2915. // javascript:$.getScript('https://dl.dropboxusercontent.com/s/jtoktspt7073sgo/fakesW124.js?dl=0');void(0)
  2916.  
  2917.  
  2918.  
  2919.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement