SophieDebleeckere

coordgrabber

May 2nd, 2020
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript:
  2.  
  3. $("#ds_body").append('<div id="DS_border" style="display: block; z-index: 10000; position: absolute; width: 0px; height: 0px; white-space: nowrap; left: 554px; top: 126px; opacity: 0.5; background-color:yellow;"/>');
  4. var DS_Map = TWMap;
  5. var x = '',
  6. y = '',
  7. xi = '',
  8. xy = '',
  9. busy = false,
  10. sndbusy = false,
  11. thdbusy = true, // set to true for tribalwars 8.29.1 -> shift doesnt need to be pressed to select/deselect coord with click
  12. arr = [],
  13. el = $("#DS_border");
  14. function spawnSectorReplacer(data, sector) {
  15. DS_Map.mapHandler.DSspawnSector(data, sector);
  16. var beginX = sector.x - data.x;
  17. var endX = beginX + DS_Map.mapSubSectorSize;
  18. var beginY = sector.y - data.y;
  19. var endY = beginY + DS_Map.mapSubSectorSize;
  20. for (var x in data.tiles) {
  21. var x = parseInt(x, 10);
  22. if (x < beginX || x >= endX) {
  23. continue;
  24. }
  25. for (var y in data.tiles[x]) {
  26. var y = parseInt(y, 10);
  27.  
  28. if (y < beginY || y >= endY) {
  29. continue;
  30. }
  31. var xCoord = data.x + x;
  32. var yCoord = data.y + y;
  33. var v = DS_Map.villages[(xCoord) * 1000 + yCoord];
  34. if (v) {
  35. var pl = (v.owner > 0 && TWMap.players[v.owner]) ? TWMap.players[v.owner] : 0;
  36. var overlay = document.createElement('div');
  37. overlay.style.position = 'absolute';
  38. overlay.style.zIndex = '50';
  39. overlay.style.width = (DS_Map.map.scale[0] - 1).toString() + 'px';
  40. overlay.style.height = (DS_Map.map.scale[1] - 1).toString() + 'px';
  41. overlay.style.opacity = 0.3;
  42. overlay.style.background = $("#DS_coordlist").text().match(xCoord + "\\|" + yCoord) ? "blue" : "none";
  43. overlay.className = "DS_overlay";
  44. overlay.id = ['DSoverlay', xCoord + "|" + yCoord, v.owner, pl.ally, pl != 0 ? pl.name : ''].join("_");
  45. sector.appendElement(overlay, x - beginX, y - beginY);
  46. }
  47. }
  48. }
  49. }
  50. DS_Map.mapHandler.DSspawnSector = DS_Map.mapHandler.spawnSector;
  51. TWMap.mapHandler.spawnSector = spawnSectorReplacer;
  52. DS_Map.map._DShandleClick = DS_Map.map._handleClick;   
  53. TWMap.map._handleClick = function (e) {
  54. if (thdbusy) {
  55. var pos = this.coordByEvent(e),
  56. coord = pos.join("|"),
  57. coords = $("#DS_coordlist").val().match(/\d{1,3}\|\d{1,3}/g) || [],
  58. v = TWMap.villages[(pos[0]) * 1000 + pos[1]];
  59.  
  60. if (v) {
  61. var ii = coords.indexOf(coord);
  62. if (ii >= 0) {
  63. coords.splice(ii, 1);
  64. $('[id*="' + coord + '"]').css("background", "none")
  65. } else {
  66. coords.push(coord);
  67. $('[id*="' + coord + '"]').css("background", "blue")
  68. }
  69. Refresh(coords);
  70. return false;
  71. }
  72. } else {
  73. DS_Map.map._DShandleClick(e);
  74. return false;
  75. }
  76. };
  77. TWMap.reload();
  78.  
  79. function Refresh(coords) {
  80. $("#DS_coordlist").text($.map((coords || $("#DS_coordlist").text().match(/\d{1,3}\|\d{1,3}/g)), function (e) {
  81. return $("#DS_bbcodes").is(":checked") ? 'Dorp niet beschikbaar' : e;
  82. }).join('\n'));
  83.  
  84. var new_count = ($('#DS_coordlist').val() != '') ? $('#DS_coordlist').val().match(/\d{1,3}\|\d{1,3}/g).length : '0';
  85. $('.select_count').text(new_count);
  86. }
  87.  
  88. function exit() {
  89. if (busy) {
  90. TWMap = func;
  91. $('[id*="DSoverlay_"]').each(function () {
  92. var offset = $(this).offset(),
  93. arr = this.id.split("_"),
  94. owner = arr[2],
  95. n = $(".DS_opts:checked").attr("data");
  96. if (
  97. (owner == 0 && n == 3) ||
  98. (owner == game_data.player.id && n == 4) ||
  99. (n == 5 && owner != game_data.player.id && owner != 0) ||
  100. (n == 6 && arr[3] != 0 && arr[3] != game_data.player.ally) ||
  101. (n == 7 && owner != 0 && document.getElementById("DS_byname").value.match(RegExp(arr[4], "i"))) || n == 1 || n == 2) {
  102. if ((offset.left + this.offsetWidth) > xi && offset.left < (xi + $("#DS_border").width()) && offset.top > yi && offset.top < (yi + $("#DS_border").height())) {
  103. var coord = this.id.split("_")[1],
  104. coords = $("#DS_coordlist")[0].textContent.match(/\d{1,3}\|\d{1,3}/g) || [];
  105. var ii = coords.indexOf(coord);
  106. if (n == 2 && ii != -1) {
  107. coords.splice(ii, 1);
  108. $(this).css("background", 'none');
  109. } else if (n != 2 && ii == -1) {
  110. $(this).css("background", 'blue');
  111. coords.push(coord);
  112. }
  113. Refresh(coords);
  114. }
  115. }
  116. });
  117. $("#DS_border").width(0).height(0);
  118. !$('#show_popup').is(':checked') && $('#show_popup').click();
  119. $(".autoHideBox").css("opacity", 0);
  120. $('#map_mover').show();
  121. x = '';
  122. y = '';
  123. busy = false;
  124. }
  125. }
  126. func = TWMap;
  127. $("#ds_body").keydown(function (e) {
  128. if (e.which == 16) {
  129. busy = true;
  130. thdbusy = true;
  131. $('#map_mover').hide();
  132. }
  133. }).keyup(function (e) {
  134. sndbusy = false;
  135. e.which == 16 && (thdbusy = true); // set to true for tribalwars 8.29.1 -> shift doesnt need to be pressed to select/deselect coord with click
  136. exit();
  137. return false;
  138. }).mousedown(function (e) {
  139. if (busy) {
  140. sndbusy = true;
  141. $("#DS_border").offset({
  142. top: e.pageY,
  143. left: e.pageX
  144. });
  145. x = e.pageX;
  146. y = e.pageY;
  147. $('#map_mover').hide();
  148. $('#show_popup').is(':checked') && $('#show_popup').click();
  149. $(".autoHideBox").css("opacity", 0);
  150. return false;
  151. }
  152. }).mouseup(function () {
  153. sndbusy = false;
  154. exit();
  155. return false;
  156. });
  157. document.onmousemove = function (a) {
  158. if ("" != x && "" != y && busy && sndbusy) {
  159. tx = -x + a.pageX;
  160. ty = -y + a.pageY;
  161. el.width(0 > tx ? -tx : tx).height(0 > ty ? -ty : ty).offset({
  162. top: 0 > ty ? a.pageY : y,
  163. left: 0 > tx ? a.pageX : x
  164. });
  165. xi = 0 > tx ? a.pageX : x;
  166. yi = 0 > ty ? a.pageY : y;
  167. var b = xi + el.width(),
  168. c = yi + el.height(),
  169. d = document.getElementsByClassName("DS_overlay"),
  170. n = $(".DS_opts:checked").attr("data");
  171. if (!$("#DS_mousemove").is(":checked")) { for (i = 0; i < d.length; i++) {
  172. var e = $(d).offset(),
  173. f = document.getElementById("DS_coordlist").textContent.indexOf(d.id.split("_")[1]),
  174. arr = d.id.split("_"),
  175. owner = arr[2];
  176. if (
  177. (owner == 0 && n == 3) ||
  178. (owner == game_data.player.id && n == 4) ||
  179. (n == 5 && owner != game_data.player.id && owner != 0) ||
  180. (n == 6 && arr[3] != 0 && arr[3] != game_data.player.ally) ||
  181. (n == 7 && owner != 0 && document.getElementById("DS_byname").value.match(RegExp(arr[4], "i"))) || n == 1 || n == 2) {
  182. (e.left + d.offsetWidth) > xi && e.left < b && e.top > yi && e.top < c ? n == 2 ?
  183. d.style.background = "none" : -1 == f && (d.style.background = "blue") : -1 == f ? d.style.background = "none" : -1 != f && (d.style.background = "blue");
  184. }
  185. }
  186. };
  187. return false;
  188. };
  189. };
  190.  
  191. function get_browserinfo(){
  192. var ua=navigator.userAgent,tem,M=ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
  193. if(/trident/i.test(M[1])){
  194. tem=/\brv[ :]+(\d+)/g.exec(ua) || [];
  195. return 'IE '+(tem[1]||'');
  196. }
  197. if(M[1]==='Chrome'){
  198. tem=ua.match(/\bOPR\/(\d+)/)
  199. if(tem!=null) {return 'Opera '+tem[1];}
  200. }
  201. M=M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
  202. if((tem=ua.match(/version\/(\d+)/i))!=null) {M.splice(1,1,tem[1]);}
  203. return [M[0], M[1]];
  204. }
  205.  
  206. var bi = get_browserinfo();
  207. var str = '<br/><table class="vis" style="border-spacing:0px;border-collapse:collapse;" width="100%"><tbody>';
  208. str += '<tr><th colspan="100%">Coord grabber </th></tr>';
  209. str += '<tr><td><b><span class="select_count">0</select></b> dorpen geselecteerd<br><textarea style="height: 160px; width: 180px;" id="DS_coordlist" onfocus="this.select();"/></td><td>';
  210. str += '<input type="checkbox" id="DS_bbcodes" data="0"> Coordinaten in BB codes</input><br/>';
  211. if (bi[0] == 'Opera' && parseInt(bi[1]) <= 12) {
  212. str += '<input type="checkbox" id="DS_mousemove" checked="checked" data="0"> Aanvinken voor tragere computers / oude versie van opera</input><br/>';
  213. } else {
  214. str += '<input type="checkbox" id="DS_mousemove" data="0"> Aanvinken voor tragere computers / oude versie van opera</input><br/>';
  215. }
  216. str += '<input name="selectors" type="radio" class="DS_opts" data="1"> Selecteer alle dorpen</input><br/>';
  217. str += '<input name="selectors" type="radio" class="DS_opts" data="2"> Coordinaten verwijderen</input><br/>';
  218. str += '<input name="selectors" type="radio" class="DS_opts" data="3"> Selecteer alleen barbarendorpen</input><br/>';
  219. str += '<input name="selectors" type="radio" class="DS_opts" data="4"> Selecteer dorpen van jezelf</input><br/>';
  220. str += '<input name="selectors" type="radio" class="DS_opts" data="5"> Selecteer dorpen van andere spelers</input><br/>';
  221. str += '<input name="selectors" type="radio" class="DS_opts" data="6"> Selecteer dorpen van niet-stamgenoten</input><br/>';
  222. str += '<input name="selectors" type="radio" class="DS_opts" data="7"><input type="text" id="DS_byname" value=""></input> Selecteer alleen dorpen van deze speler</input><br/>';
  223. str += '<input style="display:none" type="checkbox" id="DS_oneclick" data="8"><br/>';
  224. str += '</td></tr></tbody></table>';
  225. $("#map_config").before(str);
  226. $("#DS_bbcodes").change(function () {
  227. Refresh();
  228. });
  229. $(".DS_opts:first").click();
  230. void(0);
Add Comment
Please, Sign In to add comment