Advertisement
TiagoSamuel

Untitled

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