Advertisement
TiagoSamuel

Untitled

Oct 2nd, 2020
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.49 KB | None | 0 0
  1. javascript:
  2. if (window.location.href.indexOf('map') < 0) {
  3. window.location.assign(game_data.link_base_pure + "map");
  4. }
  5. var villageIDs = [];
  6. var creator = [];
  7. var data = [];
  8. var langShinko={ "en_DK": {
  9. "player": "Player:",
  10. "coord": "Coordinates:"
  11. },
  12. "en_GB": {
  13. "player": "Player:",
  14. "coord": "Coordinates:"
  15. },
  16. "it_IT": {
  17. "player": "Giocatore:",
  18. "coord": "Coordinate:"
  19. },
  20. "pt_BR": {
  21. "player": "Jogador:",
  22. "coord": "Coordenadas:"
  23. },
  24. "el_GR":{
  25. "player": "Παίκτης:",
  26. "coord": "Συντεταγμένες:"
  27. },
  28. "sv_SE":{
  29. "player": "Spelare:",
  30. "coord": "Koordinater:"
  31. }
  32. }
  33.  
  34. //check all icons on minimap
  35. for (key in TWMap.villageIcons) {
  36. //check for a note property to find the village notes
  37. for (property in TWMap.villageIcons[key]) {
  38. if (property == "note") {
  39. console.log(key);
  40. if (TWMap.villageIcons[key].note.img.includes("village_notes") == true) {
  41. id = key;
  42. //creatorType = TWMap.villageIcons[key].note.img.match(/village_notes_(\d)/)[1];
  43. villageIDs.push(id);
  44. /*if (creatorType == 1) {
  45. //own village note
  46. creator.push("own");
  47. } else {
  48. //someone elses note
  49. creator.push("someone else");
  50. }*/
  51.  
  52. }
  53. }
  54. }
  55. }
  56.  
  57.  
  58.  
  59. //loading bar
  60. $("#contentContainer").eq(0).prepend(`
  61. <div id="progressbar" style="width: 100%;
  62. background-color: #36393f;"><div id="progress" style="width: 0%;
  63. height: 35px;
  64. background-color: #4CAF50;
  65. text-align: center;
  66. line-height: 32px;
  67. color: black;"></div>
  68. </div>`);
  69.  
  70.  
  71. //function to get multiple urls
  72. $.getAll = function (
  73. urls, // array of URLs
  74. onLoad, // called when any URL is loaded, params (index, data)
  75. onDone, // called when all URLs successfully loaded, no params
  76. onError // called when a URL load fails or if onLoad throws an exception, params (error)
  77. ) {
  78. var numDone = 0;
  79. var lastRequestTime = 0;
  80. var minWaitTime = 200; // ms between requests
  81. loadNext();
  82. function loadNext() {
  83. if (numDone == urls.length) {
  84. onDone();
  85. return;
  86. }
  87.  
  88. let now = Date.now();
  89. let timeElapsed = now - lastRequestTime;
  90. if (timeElapsed < minWaitTime) {
  91. let timeRemaining = minWaitTime - timeElapsed;
  92. setTimeout(loadNext, timeRemaining);
  93. return;
  94. }
  95. console.log('Getting ', urls[numDone]);
  96. $("#progress").css("width", `${(numDone + 1) / urls.length * 100}%`);
  97. lastRequestTime = now;
  98. $.get(urls[numDone])
  99. .done((data) => {
  100. try {
  101. onLoad(numDone, data);
  102. ++numDone;
  103. loadNext();
  104. } catch (e) {
  105. onError(e);
  106. }
  107. })
  108. .fail((xhr) => {
  109. onError(xhr);
  110. })
  111. }
  112. };
  113.  
  114.  
  115. infoURLs = [];
  116. for (var i = 0; i < villageIDs.length; i++) {
  117. infoURLs.push(`/game.php?&screen=info_village&id=${villageIDs[i]}`);
  118. }
  119. villagesHTML = "";
  120. var tempRow;
  121. $.getAll(infoURLs,
  122. (i, blabla) => {
  123. thisVillaNotes = $(blabla).find(".village-notes-container")[0].innerHTML;
  124. thisVillaName = $(blabla).find(".icon.header.village")[1].parentElement.innerText;
  125. thisVillaCoordinate = $(blabla).find("td:contains('"+langShinko[game_data.locale]["coord"]+"')").next()[2].innerText;
  126. if ($(blabla).find("td:contains('"+langShinko[game_data.locale]["player"]+"')").length != 0) {
  127. thisVillaPlayer = $(blabla).find("td:contains('"+langShinko[game_data.locale]["player"]+"')").next()[2].innerText;
  128. thisVillaPlayerID = $(blabla).find("td:contains('"+langShinko[game_data.locale]["player"]+"')").next()[2].children[0].href.match(/id=(\d*)/)[1];
  129. thisVillaPlayerID=`<a href="/game.php?&screen=info_player&id=${thisVillaPlayerID}">${thisVillaPlayer}</a>`
  130. }
  131. else {
  132. thisVillaPlayerID = "Barbarians :D";
  133. }
  134.  
  135. if (i % 2 == 0) {
  136. tempRow = "class='row_b'";
  137. }
  138. else {
  139. tempRow = "class='row_a'";
  140. }
  141. urlParams = new URLSearchParams(infoURLs[i]);
  142. myParam = urlParams.get('id');
  143. villagesHTML += `<tr ${tempRow}><td><a href ="${infoURLs[i]}">${thisVillaName}</a></td><td>${thisVillaPlayerID}</td><td><a href ="${infoURLs[i]}">${thisVillaCoordinate}</a></td><td id="${myParam}">${thisVillaNotes}</td></tr>`
  144. },
  145. () => {
  146. //on done
  147. htmlCode = `
  148. <div id="villageNotes" class="vis" border=0>
  149. <table id="tableNotes" width="100%" border=1>
  150. <tbody id="appendHere">
  151. <tr>
  152. <th colspan=6 width=“550” style="text-align:center" >Village notes</th>
  153. </tr>
  154. <tr>
  155. <th width="15%" style="text-align:center">Vil name</th>
  156. <th width="15%" style="text-align:center">Vilowner</th>
  157. <th width="5%" style="text-align:center">Coord</th>
  158. <th width="65%">
  159. <font size="1">Script created by Sophie "Shinko to Kuma"</font>
  160. </th>
  161. </tr>
  162. ${villagesHTML}
  163. </tbody>
  164. </table>
  165. </div>`;
  166.  
  167. $("#contentContainer").eq(0).prepend(htmlCode);
  168. for(var k=0;k<$(".float_right.tooltip.village-note-delete").length;k++)
  169. {
  170.  
  171. $(".float_right.tooltip.village-note-delete")[k].onclick = function(){
  172. idToDelete=this.parentElement.parentElement.parentElement.parentElement.id;
  173. deleteNote(idToDelete);
  174. this.parentElement.parentElement.parentElement.parentElement.innerHTML="";
  175. };
  176. }
  177. },
  178. (error) => {
  179. console.error(error);
  180. });
  181.  
  182. function deleteNote(villageID) {
  183. var e = { "village_id": villageID, "note": "" };
  184. TribalWars.post("api", {
  185. ajaxaction: "village_note_edit",
  186. }, e, function () {
  187. UI.SuccessMessage("Succesfully deleted message");
  188. },
  189. !1
  190. );
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement