Skip to content

Instantly share code, notes, and snippets.

@danielsguima
Forked from Err0r404/gymhuntr-export.js
Last active August 8, 2018 19:41
Show Gist options
  • Save danielsguima/7721b246ff38401cf8551d046c18acf7 to your computer and use it in GitHub Desktop.
Save danielsguima/7721b246ff38401cf8551d046c18acf7 to your computer and use it in GitHub Desktop.
Export gym JSON from GymHuntr as Meowth's format
// ==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();
};
})();
@danielsguima
Copy link
Author

danielsguima commented Jun 11, 2018

Usage

  1. Install Tampermonkey or Greasemonkey in your browser.
  2. Create a new script with the extension and paste this gist code.
  3. Access GymHuntr, find your location and click on the map to show the gyms.
  4. Click the Save button (floppy disk icon).
  5. Insert your Discord server ID.
  6. Wait for the JSON to be generated.
  7. Save the generated file and paste it on your Meowth's data directory.

Any question, issue or suggestion, please let me know!

@hrenaud
Copy link

hrenaud commented Jun 11, 2018

Works great thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment