Pokevision Enhancer

Save/Load filter list, scan an area for pokemon, plus more!

目前为 2016-07-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pokevision Enhancer
  3. // @namespace https://greasyfork.org/en/users/814-bunta
  4. // @description Save/Load filter list, scan an area for pokemon, plus more!
  5. // @include *pokevision.com/*
  6. // @version 1.2
  7. // @Author Bunta
  8. // @license http://creativecommons.org/licenses/by-nc-sa/3.0/us/
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12.  
  13. var scanDelay = 1000; // time between scans for each lat/long position. Should be no lower than 1000 (1s)
  14. var autoDelay = 60000; // time between scans repeating when Auto checkbox is enabled
  15. var scanOnLoad = false; // if true will perform scan as soon as page is loaded or refreshed
  16. var minLat = -36.84, maxLat = -36.86, minLon = 174.62, maxLon = 174.64; // bounds for the scan area. minLat is northmost value, minLon is westmost value. Scans adjust lat/long by 0.01
  17.  
  18. /* run below code (after setting above position variables) in console to view the bounds of your search area
  19. App.home.createMarker(1,{latitude: minLat,longitude:minLon,pokemonId:151,}); // Mew should be top left
  20. App.home.createMarker(1,{latitude: minLat,longitude:maxLon,pokemonId:25,}); // Pikachu should be top right
  21. App.home.createMarker(1,{latitude: maxLat,longitude:minLon,pokemonId:26,}); // Raichu should be bottom left
  22. App.home.createMarker(1,{latitude: maxLat,longitude:maxLon,pokemonId:150,}); // MewTwo should be bottom right
  23. */
  24.  
  25. var pokemonAlertList = { //Choose which pokemon you want to be alerted about!
  26. "Bulbasaur": false,
  27. "Ivysaur":false,
  28. "Venusaur":false,
  29. "Charmander":false,
  30. "Charmeleon":true,
  31. "Charizard":true,
  32. "Squirtle":false,
  33. "Wartortle":false,
  34. "Blastoise":true,
  35. "Caterpie":false,
  36. "Metapod":false,
  37. "Butterfree":false,
  38. "Weedle":false,
  39. "Kakuna":false,
  40. "Beedrill":false,
  41. "Pidgey":false,
  42. "Pidgeotto":false,
  43. "Pidgeot":false,
  44. "Rattata":false,
  45. "Raticate":false,
  46. "Spearow":false,
  47. "Fearow":false,
  48. "Ekans":false,
  49. "Arbok":false,
  50. "Pikachu":true,
  51. "Raichu":true,
  52. "Sandshrew":false,
  53. "Sandslash":false,
  54. "Nidoran♀":false,
  55. "Nidorina":false,
  56. "Nidoqueen":true,
  57. "Nidoran♂":false,
  58. "Nidorino":false,
  59. "Nidoking":false,
  60. "Clefairy":false,
  61. "Clefable":false,
  62. "Vulpix":false,
  63. "Ninetales":true,
  64. "Jigglypuff":false,
  65. "Wigglytuff":false,
  66. "Zubat":false,
  67. "Golbat":false,
  68. "Oddish":false,
  69. "Gloom":false,
  70. "Vileplume":true,
  71. "Paras":false,
  72. "Parasect":false,
  73. "Venonat":false,
  74. "Venomoth":false,
  75. "Diglett":false,
  76. "Dugtrio":true,
  77. "Meowth":false,
  78. "Persian":false,
  79. "Psyduck":false,
  80. "Golduck":false,
  81. "Mankey":false,
  82. "Primeape":true,
  83. "Growlithe":false,
  84. "Arcanine":false,
  85. "Poliwag":false,
  86. "Poliwhirl":false,
  87. "Poliwrath":false,
  88. "Abra":false,
  89. "Kadabra":false,
  90. "Alakazam":true,
  91. "Machop":false,
  92. "Machoke":true,
  93. "Machamp":true,
  94. "Bellsprout":false,
  95. "Weepinbell":false,
  96. "Victreebel":false,
  97. "Tentacool":false,
  98. "Tentacruel":false,
  99. "Geodude":false,
  100. "Graveler":false,
  101. "Golem":true,
  102. "Ponyta":false,
  103. "Rapidash":true,
  104. "Slowpoke":false,
  105. "Slowbro":false,
  106. "Magnemite":false,
  107. "Magneton":true,
  108. "Farfetch'd":true,
  109. "Doduo":false,
  110. "Dodrio":false,
  111. "Seel":false,
  112. "Dewgong":true,
  113. "Grimer":false,
  114. "Muk":true,
  115. "Shellder":false,
  116. "Cloyster":true,
  117. "Gastly":false,
  118. "Haunter":false,
  119. "Gengar":true,
  120. "Onix":false,
  121. "Drowzee":false,
  122. "Hypno":true,
  123. "Krabby":false,
  124. "Kingler":false,
  125. "Voltorb":false,
  126. "Electrode":false,
  127. "Exeggcute":false,
  128. "Exeggutor":true,
  129. "Cubone":false,
  130. "Marowak":true,
  131. "Hitmonlee":false,
  132. "Hitmonchan":false,
  133. "Lickitung":false,
  134. "Koffing":false,
  135. "Weezing":false,
  136. "Rhyhorn":false,
  137. "Rhydon":true,
  138. "Chansey":false,
  139. "Tangela":false,
  140. "Kangaskhan":true,
  141. "Horsea":false,
  142. "Seadra":false,
  143. "Goldeen":false,
  144. "Seaking":false,
  145. "Staryu":false,
  146. "Starmie":false,
  147. "Mr. Mime":true,
  148. "Scyther":false,
  149. "Jynx":false,
  150. "Electabuzz":false,
  151. "Magmar":false,
  152. "Pinsir":false,
  153. "Tauros":true,
  154. "Magikarp":false,
  155. "Gyarados":true,
  156. "Lapras":true,
  157. "Ditto":true,
  158. "Eevee":false,
  159. "Vaporeon":false,
  160. "Jolteon":true,
  161. "Flareon":true,
  162. "Porygon":false,
  163. "Omanyte":false,
  164. "Omastar":true,
  165. "Kabuto":false,
  166. "Kabutops":true,
  167. "Aerodactyl":false,
  168. "Snorlax":false,
  169. "Articuno":true,
  170. "Zapdos":true,
  171. "Moltres":true,
  172. "Dratini":false,
  173. "Dragonair":false,
  174. "Dragonite":true,
  175. "Mewtwo":true,
  176. "Mew":true,
  177. }
  178.  
  179. // Test if local storage is available
  180. function storageAvailable(type) {
  181. try {
  182. var storage = window[type],
  183. x = '__storage_test__';
  184. storage.setItem(x, x);
  185. storage.removeItem(x);
  186. return true;
  187. }
  188. catch(e) {
  189. return false;
  190. }
  191. }
  192. var storageAllowed = storageAvailable('localStorage');
  193.  
  194. // Start with some style fixes to improve map visibility
  195. function addGlobalStyle(css) {
  196. var head, style;
  197. head = document.getElementsByTagName('head')[0];
  198. if (!head) { return; }
  199. style = document.createElement('style');
  200. style.type = 'text/css';
  201. style.innerHTML = css;
  202. head.appendChild(style);
  203. }
  204. addGlobalStyle("header { padding: 5px 0 ! important }")
  205. addGlobalStyle("body.home { padding: 40px 0px 0px 0 ! important }")
  206. $("footer").remove()
  207.  
  208. // Function to update the pokemon list to the selected pokemon above
  209. function refreshFilter() {
  210. $("button.bs-deselect-all").click()
  211. for (key in pokemonAlertList) {
  212. if (pokemonAlertList[key]) {
  213. $("ul.dropdown-menu.inner li span").filter(function(index) { return $(this).text() === key; }).click();
  214. }
  215. }
  216. }
  217.  
  218. // Function to save the pokemon list to local storage
  219. function saveFilter() {
  220. var selectedPokemon = [];
  221. $('.dropdown-menu.inner li.selected').each(function(_, el){
  222. selectedPokemon.push($(el).data('original-index'));
  223. });
  224. localStorage.setItem('selectedPokemon', JSON.stringify(selectedPokemon));
  225. }
  226.  
  227. // Function to load the pokemon list from local storage
  228. function loadFilter() {
  229. var selectedPokemon
  230. try {
  231. selectedPokemon = JSON.parse(localStorage.selectedPokemon);
  232. } catch(e) {
  233. refreshFilter();
  234. return;
  235. }
  236. if (selectedPokemon == null || selectedPokemon == "") { refreshFilter(); return; }
  237. $("button.bs-deselect-all").click()
  238. selectedPokemon.forEach(function(pokemonId) {
  239. $("ul.dropdown-menu.inner li[data-original-index=" + pokemonId + "] a").click();
  240. });
  241. }
  242.  
  243. var scanning = false;
  244.  
  245. // function to perform scanning in grid area bound by lat/long variables set above
  246. function scanLoop(lat,lon) {
  247. if (lon > maxLon) {
  248. lat -= 0.01;
  249. lon = minLon;
  250. }
  251. if (lat < maxLat) {
  252. console.log("Scanning Complete:", (new Date()).toLocaleTimeString());
  253. if ($("#autoRescan").prop("checked"))
  254. {
  255. console.log("Next scan will start:", (new Date((new Date()).getTime() + autoDelay)).toLocaleTimeString());
  256. setTimeout(function() {
  257. console.log("Initiating Scan:", (new Date()).toLocaleTimeString());
  258. scanLoop(minLat,minLon);
  259. }, autoDelay);
  260. } else {
  261. scanning = false;
  262. }
  263. return;
  264. }
  265. //console.log("scanning:",lat,lon);
  266. App.home.findNearbyPokemon(lat, lon);
  267. setTimeout(function() { scanLoop(lat,lon+0.01); }, scanDelay);
  268. }
  269.  
  270. // Add buttons to header bar
  271. if (storageAllowed) {
  272. $("a.header-map-locate").before('<input type="checkbox" name="autoRescan" id="autoRescan" value="Auto">Auto <button id="rescanPokes">Scan</Rescan><button id="saveFilter">Save Filter</button><button id="loadFilter">Load Filter</button>');
  273. } else {
  274. $("a.header-map-locate").before('<input type="checkbox" name="autoRescan" id="autoRescan" value="Auto">Auto <button id="rescanPokes">Scan</Rescan><button id="refreshFilter">Filter</button>');
  275. }
  276.  
  277. // Add click functions to buttons
  278. $("#rescanPokes").click(function() {
  279. console.log("rescanPokes");
  280. if (!scanning) {
  281. scanning = true;
  282. console.log("Initiating Scan:", (new Date()).toLocaleTimeString());
  283. scanLoop(minLat,minLon);
  284. }
  285. });
  286. $("#refreshFilter").click(function() {
  287. console.log("refreshFilter");
  288. refreshFilter();
  289. });
  290. $("#saveFilter").click(function() {
  291. console.log("saveFilter");
  292. saveFilter();
  293. });
  294.  
  295. $("#loadFilter").click(function() {
  296. console.log("loadFilter");
  297. loadFilter();
  298. });
  299.  
  300.  
  301. // Update filter and scan on page load (if enabled)
  302. $(window).load(function(){
  303. if (storageAllowed) {
  304. loadFilter();
  305. } else {
  306. refreshFilter();
  307. }
  308. if (!scanning && scanOnLoad) {
  309. scanning = true;
  310. console.log("Initiating Scan:", (new Date()).toLocaleTimeString());
  311. scanLoop(minLat,minLon);
  312. }
  313. });