AttackRange Helper

Shows your attack range for the new Grepolis Casual World's

  1. // ==UserScript==
  2. // @name AttackRange Helper
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2.1
  5. // @description Shows your attack range for the new Grepolis Casual World's
  6. // @author Marvins13
  7. // @include https://de99.grepolis.com/game/*
  8. // @include https://en112.grepolis.com/game/*
  9. // @include https://zz12.grepolis.com/game/*
  10. // @include https://fr114.grepolis.com/game/*
  11. // @include https://gr53.grepolis.com/game/*
  12. // @include https://nl65.grepolis.com/game/*
  13. // @include https://es76.grepolis.com/game*
  14. // @include https://it63.grepolis.com/game/*
  15. // @include https://ro53.grepolis.com/game/*
  16. // @include https://cz49.grepolis.com/game/*
  17. // @include https://pl75.grepolis.com/game/*
  18. // @include https://pt56.grepolis.com/game/*
  19. // @include https://hu50.grepolis.com/game/*
  20. // @include https://sk45.grepolis.com/game/*
  21. // @include https://dk42.grepolis.com/game/*
  22. // @include https://ru68.grepolis.com/game/*
  23. // @include https://br79.grepolis.com/game/*
  24. // @include https://tr39.grepolis.com/game/*
  25. // @include https://us76.grepolis.com/game/*
  26. // @include https://ar34.grepolis.com/game/*
  27. // @grant GM_addStyle
  28. // ==/UserScript==
  29.  
  30. var uw = unsafeWindow || window,
  31. $ = uw.jQuery;
  32. var pPoints = uw.Game.player_points;
  33.  
  34. var rankingButton;
  35. var infoButton = null;
  36. load_menu_button();
  37. load_info_button(infoButton);
  38. load_settings_window()
  39. towns_refresh();
  40. load_att_range_members();
  41. var count = 0;
  42.  
  43. //Get the Worlddata of all players
  44. var playerList = $.ajax({type: "GET", url: "/data/players.txt", async: false}).responseText;
  45. var subPlayer = playerList.split(/\r\n|\n/);
  46.  
  47. //Get the Worlddata of all towns
  48. var townsList = $.ajax({type: "GET", url: "/data/towns.txt", async: false}).responseText;
  49. var subTowns = townsList.split(/\r\n|\n/);
  50.  
  51. //add some CSS styles
  52. GM_addStyle ( `
  53. .r_city_shield_blessing {
  54. background: url(https://i.ibb.co/W05MsxT/dr-city-shield-blessing-a1471e5.png) no-repeat 0 0 !important;
  55. width: 120px !important;
  56. height: 72px !important;
  57. pointer-events: none !important;
  58. }
  59.  
  60. .o_city_shield_blessing {
  61. background: url(https://i.ibb.co/X8cn1fK/r-city-shield-blessing-a1471e5.png) no-repeat 0 0 !important;
  62. width: 120px !important;
  63. height: 72px !important;
  64. pointer-events: none !important;
  65. }
  66.  
  67. .b_city_shield_blessing {
  68. background: url(https://i.ibb.co/9crM5x6/b-city-shield-blessing-a1471e5.png) no-repeat 0 0 !important;
  69. width: 120px !important;
  70. height: 72px !important;
  71. pointer-events: none !important;
  72. }
  73.  
  74. .g_city_shield_blessing {
  75. background: url(https://i.ibb.co/6YmdJVk/g-city-shield-blessing-a1471e5.png) no-repeat 0 0 !important;
  76. width: 120px !important;
  77. height: 72px !important;
  78. pointer-events: none !important;
  79. }
  80. ` );
  81.  
  82. //Search for settings
  83. function load_settings_window(){
  84. var settingsWindows = document.getElementsByClassName('settings-menu');
  85.  
  86. if (settingsWindows.length === 0) {
  87. count = 0;
  88. setTimeout(() => load_settings_window(), 500);
  89. } else {
  90. var settingsWindow = settingsWindows[0];
  91. count++;
  92. arh_settings(count);
  93. setTimeout(() => load_settings_window(), 1000);
  94. }
  95. }
  96.  
  97. function arh_settings(counter){
  98. if(counter == 1){
  99. console.log("create");
  100. $(".settings-menu ul:last").append('<li id="arh_li"></div> <a id="arh_helper" href="#"> ARH Helper</a></li>');
  101. $("#arh_helper").click(function () {
  102. settings_window();
  103. })
  104. }
  105. }
  106.  
  107. //Search for member list
  108. function load_att_range_members(){
  109. var memberList = document.getElementsByClassName('members_list');
  110. if (memberList.length === 0) {
  111. setTimeout(() => load_att_range_members(), 500);
  112.  
  113. } else {
  114. setTimeout(() => {
  115. att_range_members();
  116. load_att_range_members();
  117. }, 1000);
  118. }
  119. }
  120.  
  121. //Coloring the member list
  122. function att_range_members(){
  123. var players = document.getElementsByClassName('small-descr');
  124. try{
  125. for(var player of players) {
  126. var pointsOfPlayer = player.innerHTML.substring(0,player.innerHTML.indexOf("P"));
  127. if (pointsOfPlayer > 0) {
  128. if (pointsOfPlayer < (pPoints * 0.83333333333) || pointsOfPlayer > (pPoints * 1.2)) {
  129. player.style.color = 'red';
  130. } else {
  131. player.style.color = 'green';
  132. }
  133. }
  134. }
  135. }catch(err){}
  136. }
  137.  
  138. function settings_window(){
  139.  
  140. }
  141.  
  142. //Refreshes the towns
  143. function towns_refresh(){
  144. setInterval(() => town_coloring(), 1500);
  145. }
  146.  
  147. //Coloring the visible twons on the map
  148. function town_coloring(){
  149. var towns = document.getElementsByClassName('flag town');
  150. for(var town of towns){
  151. try{
  152. if((town.nextSibling.nextSibling.classList.contains("city_shield_blessing"))||(town.nextSibling.nextSibling.classList.contains("r_city_shield_blessing"))||(town.nextSibling.nextSibling.classList.contains("b_city_shield_blessing"))){
  153.  
  154. var nextelement = town.nextSibling;
  155. var content = nextelement.getAttribute("href");
  156. var base64 = window.atob(content.substring(1));
  157.  
  158. var ix = base64.substring(base64.indexOf(",\"ix")+6, base64.indexOf(",\"iy"));
  159. var iy = base64.substring(base64.indexOf(",\"iy")+6, base64.indexOf(",\"tp"));
  160. var pos = base64.substring(base64.indexOf("island")+8, base64.indexOf("}"));
  161. var search = ix+","+iy+","+pos;
  162. var player_of_town = subTowns.find(function(element) {
  163. return element.includes(search);
  164. });
  165. var playerArr = player_of_town.split(/,/);
  166. var pl_id = playerArr[1];
  167.  
  168. var player = subPlayer.find(function(element) {
  169. return element.includes(pl_id);
  170. });
  171. var playerArray = player.split(/,/);
  172. if ((playerArray[3] < (pPoints * 0.83333333333) || playerArray[3] > (pPoints * 1.2))) {
  173. town.nextSibling.nextSibling.classList.remove("city_shield_blessing");
  174. town.nextSibling.nextSibling.classList.add("r_city_shield_blessing");
  175. } else {
  176. town.nextSibling.nextSibling.classList.remove("city_shield_blessing");
  177. town.nextSibling.nextSibling.classList.add("b_city_shield_blessing");
  178. }
  179.  
  180. }else{
  181. var n_nextelement = town.nextSibling;
  182. var n_content = n_nextelement.getAttribute("href");
  183. var n_base64 = window.atob(n_content.substring(1));
  184.  
  185. var n_ix = n_base64.substring(n_base64.indexOf(",\"ix")+6, n_base64.indexOf(",\"iy"));
  186. var n_iy = n_base64.substring(n_base64.indexOf(",\"iy")+6, n_base64.indexOf(",\"tp"));
  187. var n_pos = n_base64.substring(n_base64.indexOf("island")+8, n_base64.indexOf("}"));
  188. var n_search = n_ix+","+n_iy+","+n_pos;
  189. var n_player_of_town = subTowns.find(function(element) {
  190. return element.includes(n_search);
  191. });
  192. var n_playerArr = n_player_of_town.split(/,/);
  193. var n_pl_id = n_playerArr[1];
  194.  
  195. var n_player = subPlayer.find(function(element) {
  196. return element.includes(n_pl_id);
  197. });
  198. var n_playerArray = n_player.split(/,/);
  199. var style = town.nextSibling.getAttribute("style");
  200. var classEle = town.nextSibling.getAttribute("class");
  201. var town_id = town.getAttribute("id");
  202. var classIn = classEle.substring(5, 12);
  203. var l = style.substring(style.indexOf("left")+6,style.indexOf("top")-4);
  204. var t = style.substring(style.indexOf("top")+5, style.length-3);
  205. var fixedStyle = "left: " + (l-25) + "px; top: " + (t-20) + "px;";
  206. if ((n_playerArray[3] < (pPoints * 0.83333333333) || n_playerArray[3] > (pPoints * 1.2)) && !(town.children[0].getAttribute("class").includes("ghost"))) {
  207. var div = document.createElement("div");
  208. div.setAttribute("class","o_city_shield_blessing " + classIn);
  209. div.setAttribute("style",fixedStyle + " position: absolute;");
  210. div.setAttribute("id","blessing_"+town_id);
  211. if(document.getElementById("blessing_"+town_id) == null){
  212. town.parentElement.appendChild(div);
  213. }
  214. } else {
  215. var div2 = document.createElement("div");
  216. div2.setAttribute("class","g_city_shield_blessing " + classIn);
  217. div2.setAttribute("style",fixedStyle + " position: absolute;");
  218. div2.setAttribute("id","blessing_"+town_id);
  219. if(document.getElementById("blessing_"+town_id) == null){
  220. town.parentElement.appendChild(div2);
  221. }
  222. }
  223. }
  224. }catch(err){}
  225. }
  226. }
  227.  
  228. //Searches for the ranking window
  229. function load_menu_button() {
  230. var rankingButtons = document.getElementsByClassName('ranking main_menu_item');
  231. if (rankingButtons.length === 0) {
  232. setTimeout(() => load_menu_button(), 500);
  233. } else {
  234. rankingButton = rankingButtons[0];
  235. rankingButton.addEventListener('click', () => {
  236. setInterval(() => att_range_ranking(), 1000);
  237. });
  238. }
  239. }
  240.  
  241. //Search for "info windows"
  242. function load_info_button(){
  243. try{
  244. if(((document.getElementsByClassName('list_item_left')[0]).innerHTML).includes('<a href="#ey'))
  245. {
  246. att_range_info();
  247. }
  248. }catch(err){}
  249. setTimeout(() => load_info_button(), 1000);
  250.  
  251. }
  252.  
  253. //Coloring the ranking
  254. function att_range_ranking() {
  255. var points = document.getElementsByClassName('r_points');
  256. var names = document.getElementsByClassName('r_name');
  257.  
  258. //Coloring for the world ranking
  259. try{
  260. if (document.getElementById('ranking-index').className=="submenu_link active"){
  261. for(var point of points) {
  262. if (point.innerHTML > 0) {
  263. if (point.innerHTML < (pPoints * 0.83333333333) || point.innerHTML > (pPoints * 1.2)) {
  264. point.style.color = 'red';
  265. } else {
  266. point.style.color = 'green';
  267. }
  268. }
  269. }
  270. }
  271. }catch(err){}
  272.  
  273. //Coloring for the sea ranking
  274. try{
  275. if (document.getElementById('ranking-sea_player').className=="submenu_link active"){
  276. for(var i = 0; i < names.length; i++){
  277. var name = names[i];
  278. var content = name.innerHTML;
  279. var base64 = window.atob(content.substring(content.indexOf("href")+7, content.indexOf("class")-2));
  280. var id = base64.substring(base64.indexOf("id\"")+4,base64.indexOf("}"));
  281. var player = subPlayer.find(function(element) {
  282. return element.includes(id);
  283. });
  284. try{
  285. var playerArr = player.split(/,/);
  286. if (playerArr[3] < (pPoints * 0.83333333333) || playerArr[3] > (pPoints * 1.2)) {
  287. points[i].style.color = 'red';
  288. } else {
  289. points[i].style.color = 'green';
  290. }
  291. }catch(err){}
  292.  
  293. }
  294. }
  295. }catch(err){}
  296. }
  297.  
  298.  
  299. //Coloring the points in the "info window" of players
  300. function att_range_info(){
  301. var opened_info_windows = document.getElementsByClassName('list_item_left');
  302. for(var j = 0; j < opened_info_windows.length; j++){
  303. var line = opened_info_windows[j].innerHTML;
  304. console.log(opened_info_windows[j].innerHTML);
  305. var a = line.indexOf('#');
  306. var b = line.indexOf('" ');
  307. var base64 = window.atob(line.substring(a+1,b));
  308. var id = base64.substring(base64.indexOf("id\"")+4,base64.indexOf("}"));
  309. var player = subPlayer.find(function(element) {
  310. return element.includes(id);
  311. });
  312. try{
  313. var playerArr = player.split(/,/);
  314. if (playerArr[3] < (pPoints * 0.83333333333) || playerArr[3] > (pPoints * 1.2)) {
  315. opened_info_windows[j].style.color = 'red';
  316. } else {
  317. opened_info_windows[j].style.color = 'green';
  318. }
  319. }catch(err){}
  320. }
  321. }
  322.  
  323.  
  324.  
  325.  
  326.