Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.82 KB | None | 0 0
  1. // ==UserScript==
  2.  
  3. // @name PGMSuite
  4.  
  5. // @homepage https://github.com/Slimmmo/PGMSuite/
  6.  
  7. // @namespace PGMSuite
  8.  
  9. // @version 1.0.7
  10.  
  11. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js
  12.  
  13. // @include /^https?:\/\/.*po(go|ke)map\.com\/*/
  14.  
  15. // @exclude http://www.lapogomap.com/*
  16.  
  17. // @grant none
  18.  
  19. // ==/UserScript==
  20.  
  21.  
  22.  
  23. function generateFilterList() {
  24.  
  25. if (!didGenerateFilterList) {
  26.  
  27. didGenerateFilterList = true;
  28.  
  29. var html = '';
  30.  
  31. for (var i = 0; i < pokeArray.length; ++i) {
  32.  
  33. var pokemon = pokeArray[i];
  34.  
  35. var disabled = '';
  36.  
  37. var checked = '';
  38.  
  39. var cssClass = '';
  40.  
  41. var question = '';
  42.  
  43.  
  44.  
  45. if (!pokemon.h) {
  46.  
  47. cssClass = 'filter_checkbox';
  48.  
  49. if (isPokemonChecked(pokemon.i)) {
  50.  
  51. checked = ' checked="true" ';
  52.  
  53. }
  54.  
  55. } else {
  56.  
  57. cssClass = 'filter_checkbox input_disabled';
  58.  
  59. disabled = ' disabled ';
  60.  
  61. question = ' <a href="faq.html#pidgey"><img src="images/question.png" style="width: 15px; height: 15px;" /></a> ';
  62.  
  63. }
  64.  
  65. var assetServer = parseInt(pokemon.i) % 8 + 1;
  66.  
  67. var assetURL = '//assets-' + assetServer.toString() + '.' + currentTopDomainName + '/images/poke/' + pokemon.i + '.png?ver27';
  68.  
  69. var ivSet = localStorage.getItem('iv_' + pokemon.i) !== '';
  70.  
  71. var ivString = ivSet ? ' value="' + localStorage.getItem('iv_' + pokemon.i) + '"' : '';
  72.  
  73. html += '<div class="' + cssClass + '"><input id="checkbox_' + pokemon.i + '" type="checkbox" ' + checked + disabled + ' name="pokemon" value="' + pokemon.i + '"><label for="checkbox_' + pokemon.i + '"><img src="' + assetURL + '" style="max-height: 25px"> ' + pokemon.n + '</label>' + question;
  74.  
  75. html += '<input type="number" id="iv_' + pokemon.i + '"' + ivString + disabled + ' style="margin-left: 3px; max-width: 45px; display: inline-block" onchange="updateIV(' + pokemon.i + ')"></div>';
  76.  
  77. }
  78.  
  79. $('#filter_list_top').html(html);
  80.  
  81. $('.filter_checkbox input').bind("change", function(data) {
  82.  
  83. if (this.checked) {
  84.  
  85. checkPokemon(this.value);
  86.  
  87. inserted = 0;
  88.  
  89. reloadPokemons();
  90.  
  91. } else {
  92.  
  93. uncheckPokemon(this.value);
  94.  
  95. }
  96.  
  97. });
  98.  
  99. }
  100.  
  101. }
  102.  
  103.  
  104.  
  105. function indexOfPokemons(pokemon, pokemons) {
  106.  
  107. if (!showPokemon(pokemon)) {
  108.  
  109. return 0;
  110.  
  111. } else {
  112.  
  113. for (var i = 0; i < pokemons.length; ++i) {
  114.  
  115. var currentPokemon = pokemons[i];
  116.  
  117. if (pokemon.isEqual(currentPokemon)) {
  118.  
  119. return i;
  120.  
  121. }
  122.  
  123. }
  124.  
  125. }
  126.  
  127. if ($('#icb').is(':checked') && isInBounds(pokemon.center)) {
  128.  
  129. postDiscord(pokemon);
  130.  
  131. }
  132.  
  133. return -1;
  134.  
  135. }
  136.  
  137.  
  138.  
  139. function isInBounds(center) {
  140.  
  141. return map.getBounds().contains(new L.LatLng(center.lat, center.lng));
  142.  
  143. }
  144.  
  145.  
  146.  
  147. function modifyHTML() {
  148.  
  149. var icb = document.createElement('input');
  150.  
  151. icb.type = 'checkbox';
  152.  
  153. icb.id = 'icb';
  154.  
  155. var clab = document.createElement('label');
  156.  
  157. clab.htmlFor = 'icb';
  158.  
  159. clab.appendChild(document.createTextNode('Enable Discord'));
  160.  
  161. clab.style.cssText = 'padding-right: 7px';
  162.  
  163. $('#topbar').append(icb);
  164.  
  165. $('#topbar').append(clab);
  166.  
  167.  
  168.  
  169. var iiv = document.createElement('input');
  170.  
  171. iiv.type = 'number';
  172.  
  173. iiv.id = 'iiv';
  174.  
  175. iiv.max = 100;
  176.  
  177. iiv.value = localStorage.getItem('iv_value') || 82;
  178.  
  179. iiv.onchange = saveIVValue;
  180.  
  181. iiv.style.cssText = 'max-width: 45px';
  182.  
  183. var nlab = document.createElement('label');
  184.  
  185. nlab.htmlFor = 'iiv';
  186.  
  187. nlab.appendChild(document.createTextNode('IV %'));
  188.  
  189. nlab.style.cssText = 'padding-right: 7px';
  190.  
  191. $('#topbar').append(iiv);
  192.  
  193. $('#topbar').append(nlab);
  194.  
  195.  
  196.  
  197. var fcb = document.createElement('input');
  198.  
  199. fcb.type = 'checkbox';
  200.  
  201. fcb.id = 'fcb';
  202.  
  203. fcb.onchange = saveIVEverything;
  204.  
  205. if (localStorage.getItem('iv_everything') == 'true') fcb.checked = true;
  206.  
  207. var flab = document.createElement('label');
  208.  
  209. flab.htmlFor = 'fcb';
  210.  
  211. flab.appendChild(document.createTextNode('IV filter everything'));
  212.  
  213. flab.style.cssText = 'padding-right: 7px';
  214.  
  215. $('#topbar').append(fcb);
  216.  
  217. $('#topbar').append(flab);
  218.  
  219.  
  220.  
  221. var iwh = document.createElement('input');
  222.  
  223. iwh.type = 'text';
  224.  
  225. iwh.id = 'iwh';
  226.  
  227. iwh.onchange = saveWebhook;
  228.  
  229. iwh.value = localStorage.getItem('whURL') || '';
  230.  
  231. iwh.style.cssText = 'max-width: 50px';
  232.  
  233. var wlab = document.createElement('label');
  234.  
  235. wlab.htmlFor = 'iwh';
  236.  
  237. wlab.appendChild(document.createTextNode('Webhook URL'));
  238.  
  239. $('#topbar').append(iwh);
  240.  
  241. $('#topbar').append(wlab);
  242.  
  243.  
  244.  
  245. /*$('#map').css('top','');
  246.  
  247. $('#map').css('bottom','');
  248.  
  249. $('#filter_settings').css('top','50px');
  250.  
  251. $('#locate').css('top','50px');*/
  252.  
  253. }
  254.  
  255.  
  256.  
  257. function postDiscord(p) {
  258.  
  259. var date = new Date(p.despawn * 1000);
  260.  
  261. var dateString = date.getHours() + ':' + ("0" + date.getMinutes()).substr(-2) + ':' + ("0" + date.getSeconds()).substr(-2);
  262.  
  263. var text = getPokemonName(p) + ' ' + '(' + Math.floor((p.attack + p.defence + p.stamina) / 0.45) + '%) ' + (p.cp == -1 ? '' : '' + p.cp + 'CP') + ' with ' + getMoveName(p.move1) + ', ' + getMoveName(p.move2) + ' until ' + dateString + ' at http://maps.google.com/maps?q=' + p.center.lat + ',' + p.center.lng + '&zoom=14';
  264.  
  265. // $.ajax({
  266.  
  267. // data: 'content=' + text,
  268.  
  269. // dataType: 'json',
  270.  
  271. // processData: false,
  272.  
  273. // type: 'POST',
  274.  
  275. // url: $('#iwh').val()
  276.  
  277. // });
  278.  
  279. $.ajax({
  280. data: JSON.stringify({"username":getPokemonName(p),"embeds": [{ "title":getPokemonName(p) + ' (' + Math.floor((p.attack + p.defence + p.stamina) / 0.45) + '%) ' + (p.cp == -1 ? '' : '' + p.cp + 'CP') + " - Until " + dateString,"url":"http://maps.google.com/maps?q=" + p.center.lat + "," + p.center.lng + "&zoom=14","description":"**IVs:** " + Math.floor((p.attack + p.defence + p.stamina) / 0.45) + "% (" + p.attack + "/" + p.defence + "/" + p.stamina + ") " + (p.cp == -1 ? '' : '' + p.cp + "CP\n") + "**Moves:** " + getMoveName(p.move1) + " / " + getMoveName(p.move2),"image": { "url": "https://maps.googleapis.com/maps/api/staticmap?markers=" + p.center.lat + ',' + p.center.lng + "&zoom=14&size=275x125&key=AIzaSyDfFFgmT0u_2-8XZvs9uZOVnLvKIGqwUm0" } }]}),
  281. //data: text,
  282. dataType: 'json',
  283. processData: false,
  284. type: 'POST',
  285. url: $('#iwh').val()
  286. });
  287.  
  288. }
  289.  
  290.  
  291.  
  292. function refreshPokemons() {
  293.  
  294. if (!shouldUpdate) {
  295.  
  296. return; //don't update when map is moving
  297.  
  298. }
  299.  
  300. var toBeRemovedIndexes = [];
  301.  
  302. var currentPokemon, marker, i;
  303.  
  304. var currentUnixTime = Math.floor(Date.now() / 1000) - timeOffset;
  305.  
  306. for (i = 0; i < pokemons.length; ++i) {
  307.  
  308. currentPokemon = pokemons[i];
  309.  
  310. if (currentPokemon.despawn < currentUnixTime - 10 || (!isPokemonChecked(currentPokemon.id) && !shouldTurnFilterOff()) || !showPokemon(currentPokemon)) {
  311.  
  312. toBeRemovedIndexes.push(i);
  313.  
  314. }
  315.  
  316. }
  317.  
  318. for (i = toBeRemovedIndexes.length - 1; i >= 0; --i) {
  319.  
  320. pokemons.splice(toBeRemovedIndexes[i], 1);
  321.  
  322. marker = markers[toBeRemovedIndexes[i]];
  323.  
  324. marker.removeFrom(map);
  325.  
  326. markers.splice(toBeRemovedIndexes[i], 1);
  327.  
  328. }
  329.  
  330. //remove low IV from map, add high IV to map
  331.  
  332. for (i = 0; i < pokemons.length; ++i) {
  333.  
  334. currentPokemon = pokemons[i];
  335.  
  336. var ivPercentage = (currentPokemon.attack + currentPokemon.defence + currentPokemon.stamina) / 45 * 100;
  337.  
  338. marker = markers[i];
  339.  
  340. var min_iv_compare = min_iv;
  341.  
  342. //to let unknown iv show
  343.  
  344. if (min_iv === 0) {
  345.  
  346. min_iv_compare = -100;
  347.  
  348. }
  349.  
  350. if (ivPercentage >= min_iv_compare || shouldTurnFilterOff()) {
  351.  
  352. if (!marker._map) {
  353.  
  354. marker.addTo(map);
  355.  
  356. }
  357.  
  358. } else {
  359.  
  360. if (marker._map) {
  361.  
  362. marker.removeFrom(map);
  363.  
  364. }
  365.  
  366. }
  367.  
  368. }
  369.  
  370. if (shouldShowTimers()) {
  371.  
  372. for (i = 0; i < markers.length; ++i) {
  373.  
  374. //only update for the ones in bounds
  375.  
  376. var mapBounds = map.getBounds();
  377.  
  378. var tmpMarker = markers[i];
  379.  
  380. if (mapBounds.contains(tmpMarker.getLatLng())) {
  381.  
  382. $(tmpMarker._icon).find('.pokemon_icon_timer').html(timeToString(pokemons[i].remainingTime()));
  383.  
  384. }
  385.  
  386. }
  387.  
  388. }
  389.  
  390. }
  391.  
  392.  
  393.  
  394. function saveIVEverything() {
  395.  
  396. localStorage.setItem('iv_everything', $('#fcb').is(':checked'));
  397.  
  398. }
  399.  
  400.  
  401.  
  402. function saveIVValue() {
  403.  
  404. localStorage.setItem('iv_value', $('#iiv').val());
  405.  
  406. }
  407.  
  408.  
  409.  
  410. function saveWebhook() {
  411.  
  412. localStorage.setItem('whURL', $('#iwh').val());
  413.  
  414. }
  415.  
  416.  
  417.  
  418. function showPokemon(p) {
  419.  
  420. var iv = (p.attack + p.defence + p.stamina) / 0.45;
  421.  
  422. var lsVal = localStorage.getItem('iv_' + p.id);
  423.  
  424. if (lsVal !== null && (lsVal === '' || lsVal === '0')) {
  425.  
  426. lsVal = null;
  427.  
  428. localStorage.removeItem('iv_' + p.id);
  429.  
  430. }
  431.  
  432. if (localStorage.getItem('filterOff') == '1') {
  433.  
  434. return true;
  435.  
  436. } else if (lsVal !== null) {
  437.  
  438. return iv >= lsVal;
  439.  
  440. } else if ($('#fcb').is(':checked') || !isPokemonChecked(p.id)) {
  441.  
  442. return iv >= $('#iiv').val();
  443.  
  444. } else {
  445.  
  446. return true;
  447.  
  448. }
  449.  
  450. }
  451.  
  452.  
  453.  
  454. function updateIV(pid) {
  455.  
  456. var val = $('#iv_' + pid).val();
  457.  
  458. if (val !== '' && val !== 0) {
  459.  
  460. localStorage.setItem('iv_' + pid, val);
  461.  
  462. } else {
  463.  
  464. localStorage.removeItem('iv_' + pid);
  465.  
  466. }
  467.  
  468. }
  469.  
  470.  
  471.  
  472. $('#select_all_btn').unbind('click');
  473.  
  474. $('#select_all_btn').bind('click', function() {
  475.  
  476. var shouldCheckAll = true;
  477.  
  478. shouldCheckAll = confirm("Show all Pokémon will make your page laggy. Proceed?");
  479.  
  480. if (shouldCheckAll) {
  481.  
  482. $(".filter_checkbox input[type=checkbox]").each(function() {
  483.  
  484. var tmpPokemon = pokeDict[$(this).val()];
  485.  
  486. if (tmpPokemon.show_filter) {
  487.  
  488. $(this).prop('checked', true);
  489.  
  490. }
  491.  
  492. });
  493.  
  494. for (var key in pokeDict) {
  495.  
  496. if (pokeDict[key].show_filter) {
  497.  
  498. checkPokemon(key);
  499.  
  500. }
  501.  
  502. }
  503.  
  504. inserted = 0;
  505.  
  506. reloadPokemons();
  507.  
  508. }
  509.  
  510. });
  511.  
  512. $('#deselect_all_btn').unbind('click');
  513.  
  514. $('#deselect_all_btn').bind('click', function() {
  515.  
  516. $(".filter_checkbox input[type=checkbox]").each(function() {
  517.  
  518. $(this).prop('checked', false);
  519.  
  520. });
  521.  
  522. for (var key in pokeDict) {
  523.  
  524. uncheckPokemon(key);
  525.  
  526. }
  527.  
  528. inserted = 0;
  529.  
  530. reloadPokemons();
  531.  
  532. });
  533.  
  534.  
  535.  
  536. if (localStorage.getItem("infiniteScrollEnabled") === null) {
  537.  
  538. for (var i = 1; i <= 251; i++) {
  539.  
  540. localStorage['icon' + i] = 'https://raw.githubusercontent.com/pokeicons/icons/master/' + i + '.png';
  541.  
  542. }
  543.  
  544. }
  545.  
  546.  
  547.  
  548. // Inject this code into the site's scope
  549.  
  550.  
  551.  
  552. modifyHTML();
  553.  
  554. addJS_Node(generateFilterList);
  555.  
  556. addJS_Node(indexOfPokemons);
  557.  
  558. addJS_Node(isInBounds);
  559.  
  560. addJS_Node(postDiscord);
  561.  
  562. addJS_Node(refreshPokemons);
  563.  
  564. addJS_Node(saveIVEverything);
  565.  
  566. addJS_Node(saveIVValue);
  567.  
  568. addJS_Node(saveWebhook);
  569.  
  570. addJS_Node(showPokemon);
  571.  
  572. addJS_Node(updateIV);
  573.  
  574.  
  575.  
  576. function addJS_Node(text, s_URL, funcToRun, runOnLoad) {
  577.  
  578. var D = document;
  579.  
  580. var scriptNode = D.createElement('script');
  581.  
  582. if (runOnLoad) {
  583.  
  584. scriptNode.addEventListener("load", runOnLoad, false);
  585.  
  586. }
  587.  
  588. scriptNode.type = "text/javascript";
  589.  
  590. if (text) scriptNode.textContent = text;
  591.  
  592. if (s_URL) scriptNode.src = s_URL;
  593.  
  594. if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
  595.  
  596.  
  597.  
  598. var targ = D.getElementsByTagName('head')[0] || D.body || D.documentElement;
  599.  
  600. targ.appendChild (scriptNode);
  601.  
  602. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement