// ==UserScript== // @name PGMSuite // @homepage https://github.com/Slimmmo/PGMSuite/ // @namespace PGMSuite // @version 1.0.8 // @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js // @include /^https?:\/\/.*po(go|ke)map\.com\/*/ // @exclude http://www.lapogomap.com/* // @exclude .*/gym.html // @grant none // ==/UserScript== function generateFilterList() { if (!didGenerateFilterList) { didGenerateFilterList = true; var html = ''; for (var i = 0; i < pokeArray.length; ++i) { var pokemon = pokeArray[i]; var disabled = ''; var checked = ''; var cssClass = ''; var question = ''; if (!pokemon.h) { cssClass = 'filter_checkbox'; if (isPokemonChecked(pokemon.i)) { checked = ' checked="true" '; } } else { cssClass = 'filter_checkbox input_disabled'; disabled = ' disabled '; question = ' '; } var assetServer = parseInt(pokemon.i) % 8 + 1; var assetURL = '//assets-' + assetServer.toString() + '.' + currentTopDomainName + '/images/poke/' + pokemon.i + '.png?ver27'; var ivSet = localStorage.getItem('iv_' + pokemon.i) !== ''; var ivString = ivSet ? ' value="' + localStorage.getItem('iv_' + pokemon.i) + '"' : ''; html += '
' + question; html += '
'; } $('#filter_list_top').html(html); $('.filter_checkbox input').bind("change", function(data) { if (this.checked) { checkPokemon(this.value); inserted = 0; reloadPokemons(); } else { uncheckPokemon(this.value); } }); } } function indexOfPokemons(pokemon, pokemons) { if (!showPokemon(pokemon)) { return 0; } else { for (var i = 0; i < pokemons.length; ++i) { var currentPokemon = pokemons[i]; if (pokemon.isEqual(currentPokemon)) { return i; } } } if ($('#icb').is(':checked') && isInBounds(pokemon.center)) { postDiscord(pokemon); } return -1; } function isInBounds(center) { return map.getBounds().contains(new L.LatLng(center.lat, center.lng)); } function modifyHTML() { var icb = document.createElement('input'); icb.type = 'checkbox'; icb.id = 'icb'; var clab = document.createElement('label'); clab.htmlFor = 'icb'; clab.appendChild(document.createTextNode('Enable Discord')); clab.style.cssText = 'padding-right: 7px'; $('#topbar').append(icb); $('#topbar').append(clab); var iiv = document.createElement('input'); iiv.type = 'number'; iiv.id = 'iiv'; iiv.max = 100; iiv.value = localStorage.getItem('iv_value') || 82; iiv.onchange = saveIVValue; iiv.style.cssText = 'max-width: 45px'; var nlab = document.createElement('label'); nlab.htmlFor = 'iiv'; nlab.appendChild(document.createTextNode('IV %')); nlab.style.cssText = 'padding-right: 7px'; $('#topbar').append(iiv); $('#topbar').append(nlab); var fcb = document.createElement('input'); fcb.type = 'checkbox'; fcb.id = 'fcb'; fcb.onchange = saveIVEverything; if (localStorage.getItem('iv_everything') == 'true') fcb.checked = true; var flab = document.createElement('label'); flab.htmlFor = 'fcb'; flab.appendChild(document.createTextNode('IV filter everything')); flab.style.cssText = 'padding-right: 7px'; $('#topbar').append(fcb); $('#topbar').append(flab); var iwh = document.createElement('input'); iwh.type = 'text'; iwh.id = 'iwh'; iwh.onchange = saveWebhook; iwh.value = localStorage.getItem('whURL') || ''; iwh.style.cssText = 'max-width: 50px; margin-right: 15px'; var wlab = document.createElement('label'); wlab.htmlFor = 'iwh'; wlab.appendChild(document.createTextNode('Webhook URL')); $('#topbar').append(wlab); $('#topbar').append(iwh); var gak = document.createElement('input'); gak.type = 'text'; gak.id = 'gak'; gak.onchange = saveGoogleApiKey; gak.value = localStorage.getItem('gApiKey') || ''; gak.style.cssText = 'max-width: 50px'; var glab = document.createElement('label'); glab.htmlFor = 'gak'; glab.appendChild(document.createTextNode('Google Maps API Key')); $('#topbar').append(glab); $('#topbar').append(gak); /*$('#map').css('top',''); $('#map').css('bottom',''); $('#filter_settings').css('top','50px'); $('#locate').css('top','50px');*/ } function postDiscord(p) { if (gmapsLoaded) { var address = ''; geocoder.geocode({'location': {lat: p.center.lat, lng: p.center.lng}}, function(results, status) { if (status === 'OK') { if (results[0]) { address = results[0].formatted_address; postFromAddr(address); } else { postFromAddr(''); } } else { postFromAddr(''); } }); } else { postFromAddr(''); } function postFromAddr(addr){ var date = new Date(p.despawn * 1000); var dateString = date.getHours() + ':' + ("0" + date.getMinutes()).substr(-2) + ':' + ("0" + date.getSeconds()).substr(-2); var stats = p.cp == -1 ? '' : ('(' + p.cp + ' CP, L' + p.level + ')') + Math.floor((p.attack + p.defence + p.stamina) / 0.45) + '% with ' + getMoveName(p.move1) + ', ' + getMoveName(p.move2); var text = getPokemonName(p) + ' ' + stats + ' until ' + dateString + ' at ' + addr + ' http://maps.google.com/maps?q=' + p.center.lat + ',' + p.center.lng + '&zoom=14'; $.ajax({ data: 'content=' + text, dataType: 'json', processData: false, type: 'POST', url: $('#iwh').val() }); } } function refreshPokemons() { if (!shouldUpdate) { return; //don't update when map is moving } var toBeRemovedIndexes = []; var currentPokemon, marker, i; var currentUnixTime = Math.floor(Date.now() / 1000) - timeOffset; for (i = 0; i < pokemons.length; ++i) { currentPokemon = pokemons[i]; if (currentPokemon.despawn < currentUnixTime - 10 || (!isPokemonChecked(currentPokemon.id) && !shouldTurnFilterOff()) || !showPokemon(currentPokemon)) { toBeRemovedIndexes.push(i); } } for (i = toBeRemovedIndexes.length - 1; i >= 0; --i) { pokemons.splice(toBeRemovedIndexes[i], 1); marker = markers[toBeRemovedIndexes[i]]; marker.removeFrom(map); markers.splice(toBeRemovedIndexes[i], 1); } //remove low IV from map, add high IV to map for (i = 0; i < pokemons.length; ++i) { currentPokemon = pokemons[i]; var ivPercentage = (currentPokemon.attack + currentPokemon.defence + currentPokemon.stamina) / 45 * 100; marker = markers[i]; var min_iv_compare = min_iv; //to let unknown iv show if (min_iv === 0) { min_iv_compare = -100; } if (ivPercentage >= min_iv_compare || shouldTurnFilterOff()) { if (!marker._map) { marker.addTo(map); } } else { if (marker._map) { marker.removeFrom(map); } } } if (shouldShowTimers()) { for (i = 0; i < markers.length; ++i) { //only update for the ones in bounds var mapBounds = map.getBounds(); var tmpMarker = markers[i]; if (mapBounds.contains(tmpMarker.getLatLng())) { $(tmpMarker._icon).find('.pokemon_icon_timer').html(timeToString(pokemons[i].remainingTime())); } } } } function saveIVEverything() { localStorage.setItem('iv_everything', $('#fcb').is(':checked')); } function saveIVValue() { localStorage.setItem('iv_value', $('#iiv').val()); } function saveWebhook() { localStorage.setItem('whURL', $('#iwh').val()); } function saveGoogleApiKey() { localStorage.setItem('gApiKey', $('#gak').val()); } function showPokemon(p) { var iv = (p.attack + p.defence + p.stamina) / 0.45; var lsVal = localStorage.getItem('iv_' + p.id); if (lsVal !== null && (lsVal === '' || lsVal === '0')) { lsVal = null; localStorage.removeItem('iv_' + p.id); } if (localStorage.getItem('filterOff') == '1') { return true; } else if (lsVal !== null) { return iv >= lsVal; } else if ($('#fcb').is(':checked') || !isPokemonChecked(p.id)) { return iv >= $('#iiv').val(); } else { return true; } } function updateIV(pid) { var val = $('#iv_' + pid).val(); if (val !== '' && val !== 0) { localStorage.setItem('iv_' + pid, val); } else { localStorage.removeItem('iv_' + pid); } } $('#select_all_btn').unbind('click'); $('#select_all_btn').bind('click', function() { var shouldCheckAll = true; shouldCheckAll = confirm("Show all Pokémon will make your page laggy. Proceed?"); if (shouldCheckAll) { $(".filter_checkbox input[type=checkbox]").each(function() { var tmpPokemon = pokeDict[$(this).val()]; if (tmpPokemon.show_filter) { $(this).prop('checked', true); } }); for (var key in pokeDict) { if (pokeDict[key].show_filter) { checkPokemon(key); } } inserted = 0; reloadPokemons(); } }); $('#deselect_all_btn').unbind('click'); $('#deselect_all_btn').bind('click', function() { $(".filter_checkbox input[type=checkbox]").each(function() { $(this).prop('checked', false); }); for (var key in pokeDict) { uncheckPokemon(key); } inserted = 0; reloadPokemons(); }); if (localStorage.getItem("infiniteScrollEnabled") === null) { for (var i = 1; i <= 251; i++) { localStorage['icon' + i] = 'https://raw.githubusercontent.com/pokeicons/icons/master/' + i + '.png'; } } function loadGMaps(apiKey) { var script2 = document.createElement('script'); script2.type = 'text/javascript'; script2.innerHTML = 'function initializeGmaps() {'; script2.innerHTML += 'geocoder = new google.maps.Geocoder();'; script2.innerHTML += '}'; document.body.appendChild(script2); var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://maps.googleapis.com/maps/api/js?key=' + apiKey + '&callback=initializeGmaps'; script.setAttribute("async", ""); script.setAttribute("defer", ""); document.body.appendChild(script); gmapsLoaded = true; } // Inject this code into the site's scope modifyHTML(); gmapsLoaded = false; if ($('#gak').val()) { loadGMaps($('#gak').val()); } addJS_Node(generateFilterList); addJS_Node(indexOfPokemons); addJS_Node(isInBounds); addJS_Node(postDiscord); addJS_Node(refreshPokemons); addJS_Node(saveIVEverything); addJS_Node(saveIVValue); addJS_Node(saveWebhook); addJS_Node(showPokemon); addJS_Node(updateIV); function addJS_Node(text, s_URL, funcToRun, runOnLoad) { var D = document; var scriptNode = D.createElement('script'); if (runOnLoad) { scriptNode.addEventListener("load", runOnLoad, false); } scriptNode.type = "text/javascript"; if (text) scriptNode.textContent = text; if (s_URL) scriptNode.src = s_URL; if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()'; var targ = D.getElementsByTagName('head')[0] || D.body || D.documentElement; targ.appendChild (scriptNode); }