-
-
Save danielsguima/7721b246ff38401cf8551d046c18acf7 to your computer and use it in GitHub Desktop.
Export gym JSON from GymHuntr as Meowth's format
This file contains hidden or 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
// ==UserScript== | |
// @name Export visible gym from GymHuntr as Meowth's gym matching JSON format | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Export gyms to json/csv | |
// @author danielsguima | |
// @match https://gymhuntr.com/ | |
// @grant none | |
// @downloadURL https://gist.github.com/danielsguima/7721b246ff38401cf8551d046c18acf7/raw/ | |
// @updateURL | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var server = {}; | |
var gyms = {}; | |
var $gym; | |
var nbGyms; | |
var iterator = 0; | |
var serverId; | |
// Add button to export | |
$("<a/>", {"id": "export", "class": "button-circle"}) | |
.html( | |
$("<span/>", {"class": "inner"}).html( | |
$("<i/>", {"class": "fa fa-floppy-o"}) | |
) | |
) | |
.insertAfter("#location"); | |
$("#export").on("click", function() { | |
nbGyms = $(".gym").length; | |
console.clear(); | |
serverId = prompt("Insert your Discord server ID:"); | |
if(serverId) { | |
if(serverId.length == 18) { | |
alert("You can check the progress with the browser console. Press F12 and choose \"Console\"."); | |
getGyms(serverId); | |
} else { | |
alert("The ID's length must be 18."); | |
} | |
} else { | |
alert("The server ID is required!"); | |
} | |
}); | |
var getGyms = function() { | |
var gymInterval = setInterval(function() { | |
console.log(iterator + "/" + nbGyms); | |
$gym = $(".gym:eq("+iterator+")"); | |
// Click on gym to see modal | |
$gym.click(); | |
// Wait for modal | |
setTimeout(function() { | |
// Get gym's name | |
var name = $(".modal-header span.label.label-success:first").text(); | |
// Get gym's coordinate | |
var coordinates = $(".modal-footer a:first").attr("href").split("/").pop(); | |
gyms[name] = { | |
"coordinates": coordinates | |
}; | |
// Close modal | |
$(".modal-footer>button[data-dismiss='modal']:visible").click(); | |
iterator = iterator+1; | |
if(iterator >= nbGyms){ | |
server[serverId] = gyms; | |
download(); | |
clearInterval(gymInterval); | |
} | |
}, 250); | |
}, 500); | |
}; | |
var download = function() { | |
alert("Gym JSON generated with " + nbGyms + " gyms! Click OK to download!"); | |
var data = "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(server)); | |
$("<a/>", { | |
"id": "download", | |
"href": "data:" + data, | |
"download": "gym_data.json" | |
})[0].click(); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
Any question, issue or suggestion, please let me know!