Created
May 19, 2024 02:15
-
-
Save Alegrowin/bdd1387fea9128036d8ce678a390ee0b to your computer and use it in GitHub Desktop.
Extract Pokemon Go Names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sleep(delay) { | |
return new Promise(resolve => setTimeout(resolve, delay)); | |
} | |
async function takeABreak() { | |
await sleep(2000); // Wait for 2 seconds | |
} | |
async function displayLeagueTierSearchStrings(maxPerTier, maxTier, league) { | |
const leagueMap = new Map(); | |
// Select the dropdown element | |
var dropdown = $('.format-select'); | |
// Loop through each option in the dropdown | |
dropdown.find('option').each(function(index, option) { | |
const text = $(option).text(); // Get the text content of the option | |
const details = { | |
value: $(option).val(), | |
cup: $(option).attr('cup'), | |
"meta-group": $(option).attr('meta-group'), | |
}; | |
leagueMap.set(text, details); // Use text as the map key | |
}); | |
let foundOption = null; | |
for (let i = 0; i < dropdown.find('option').length; i++) { | |
var option = dropdown.find('option')[i]; | |
if ($(option).attr('value') === leagueMap.get(league).value && $(option).attr('cup') === leagueMap.get(league).cup && $(option).attr('meta-group') === leagueMap.get(league)['meta-group']) { | |
foundOption = dropdown.find('option')[i]; | |
break; | |
} | |
} | |
if (foundOption) { | |
// var dropdown = document.querySelector('.format-select'); | |
console.log(foundOption.index) | |
dropdown.selectedIndex = foundOption.index; | |
dropdown.prop('selectedIndex', foundOption.index); | |
dropdown.trigger('change'); | |
dropdown.trigger('click'); | |
await takeABreak() | |
} else { | |
console.error("Desired option not found"); | |
} | |
var normals = ""; | |
var galars = ""; | |
var shadows = ""; | |
console.log(`--------------------------------------`); | |
console.log("Best pokemons for " + league); | |
console.log(`--------------------------------------`); | |
for (var Tier = 0; Tier < maxTier; Tier++) { | |
var tierNormals = ""; | |
var tierGalars = ""; | |
var tierShadows = ""; | |
for (var X = 1+(Tier*maxPerTier); X <= maxPerTier+(Tier*maxPerTier); X++) { | |
// Construct the selector with the current value of X | |
var selector = "#main > div.section.league-select-container.white > div.rankings-container.clear > div:nth-child(" + X + ") > div.name-container > span.name"; | |
// Use querySelector to find the element | |
var element = document.querySelector(selector); | |
// Check if the element exists | |
if (element) { | |
// If it exists, get the outerText and add it to the names array | |
if (element.outerText.includes('Galarian')) { | |
tierGalars += "+" + element.outerText + ","; | |
} | |
else if (element.outerText.includes('Shadow')) { | |
tierShadows += "+" + element.outerText + ","; | |
} | |
else { | |
tierNormals += "+" + element.outerText + ","; | |
} | |
} else { | |
// If the element does not exist, log a message or handle as needed | |
console.log("No element found for X = " + X); | |
} | |
} | |
console.log(`Tier: ${Tier + 1} (${1+(Tier*maxPerTier)}:${Tier*maxPerTier + maxPerTier})`); | |
var query = tierNormals.replace(/XL/g, "").replace(/[()]/g, "").replace(/ Galarian/g, ""); | |
query = query.slice(0, query.length - 1); | |
console.log("Normals: "); | |
console.log(`${query}&!shadow`); | |
var query = tierGalars.replace(/XL/g, "").replace(/ \(Galarian\)/g, ""); | |
query = query.slice(0, query.length - 1); | |
console.log("Galars: "); | |
console.log(`${query}&galar&!shadow`); | |
var query = tierShadows.replace(/XL/g, "").replace(/ \(Shadow\)/g, ""); | |
query = query.slice(0, query.length - 1); | |
console.log("Shadows: "); | |
console.log(`${query}&shadow`); | |
shadows += tierShadows; | |
galars += tierGalars; | |
normals += tierNormals; | |
console.log(`--------------------------------------`); | |
} | |
console.log(`--------------------------------------`); | |
console.log(`TOP${maxTier*maxPerTier} for ${league}`); | |
var query = normals.replace(/XL/g, "").replace(/[()]/g, "").replace(/ Galarian/g, ""); | |
query = query.slice(0, query.length - 1); | |
console.log("Normals: "); | |
console.log(`${query}&!shadow`); | |
var query = galars.replace(/XL/g, "").replace(/ \(Galarian\)/g, ""); | |
query = query.slice(0, query.length - 1); | |
console.log("Galars: "); | |
console.log(`${query}&galar&!shadow`); | |
var query = shadows.replace(/XL/g, "").replace(/ \(Shadow\)/g, ""); | |
query = query.slice(0, query.length - 1); | |
console.log("Shadows: "); | |
console.log(`${query}&shadow`); | |
return [normals + galars, shadows] | |
} | |
var top45AllLeagueNormals = ""; | |
var top45AllLeagueShadows = ""; | |
var r = await displayLeagueTierSearchStrings(15,3,"Great League") | |
top45AllLeagueNormals += r[0]; | |
top45AllLeagueShadows += r[1]; | |
var r = await displayLeagueTierSearchStrings(15,3,"Ultra League") | |
top45AllLeagueNormals += r[0]; | |
top45AllLeagueShadows += r[1]; | |
var r = await displayLeagueTierSearchStrings(15,3,"Master League") | |
top45AllLeagueNormals += r[0]; | |
top45AllLeagueShadows += r[1]; | |
var r = await displayLeagueTierSearchStrings(15,3,"Little Catch Cup") | |
top45AllLeagueNormals += r[0]; | |
top45AllLeagueShadows += r[1]; | |
console.log(`--------------------------------------`); | |
console.log(`TOP45 for all leagues`); | |
var query = top45AllLeagueNormals.replace(/XL/g, "").replace(/[()]/g, "").replace(/ Galarian/g, ""); | |
query = query.slice(0, query.length - 1); | |
console.log("Normals: "); | |
console.log(`${query}&!shadow`); | |
var query = top45AllLeagueShadows.replace(/XL/g, "").replace(/ \(Shadow\)/g, ""); | |
query = query.slice(0, query.length - 1); | |
console.log("Shadows: "); | |
console.log(`${query}&shadow`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This generates the following: