Skip to content

Instantly share code, notes, and snippets.

@Err0r404
Last active June 11, 2018 18:43
Show Gist options
  • Save Err0r404/1a4ce5a02fc4c6a51d7c38f29bf328c8 to your computer and use it in GitHub Desktop.
Save Err0r404/1a4ce5a02fc4c6a51d7c38f29bf328c8 to your computer and use it in GitHub Desktop.
Export visible gyms from gymhuntr.com to a json object that can be converrted to csv
// ==UserScript==
// @name Export visible gyms to a json object that can be converrted to csv
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Export gyms to json/csv
// @author Err0r404
// @match https://gymhuntr.com/
// @grant none
// @downloadURL https://gist.githubusercontent.com/Err0r404/1a4ce5a02fc4c6a51d7c38f29bf328c8/raw/
// @updateURL
// ==/UserScript==
(function() {
'use strict';
var gyms = [];
var $gym, gym, trainers, trainer;
var nbGyms;
var iterator = 0;
// 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();
getGyms();
});
var getGyms = function() {
var gymInterval = setInterval(function() {
console.log(iterator+"/"+nbGyms);
$gym = $(".gym:eq("+iterator+")");
gym = {};
// Click on gym to see modal
$gym.click();
// Wait for modal
setTimeout(function() {
// Get gym's name
gym.name = $(".modal-header span.label.label-success:first").text();
// Get gym's team
// gym.team = $(".modal-header span.label:not(.label-success):not(.label-default)").text().split(" ").pop();
// Get gym's coordinate
gym.coordinate = $(".modal-footer a:first").attr("href").split("/").pop();
gym.url = "https://www.google.fr/maps/search/"+gym.coordinate;
// Add gym to the list
gyms.push(gym);
// Close modal
$(".modal-footer>button[data-dismiss='modal']:visible").click();
iterator = iterator+1;
if(iterator >= nbGyms){
exportToNewTab();
clearInterval(gymInterval);
}
}, 250);
}, 500);
};
var exportToNewTab = function() {
// console.log(gyms);
console.log("Copy + Paste the following to https://konklone.io/json/ and download your CSV");
console.log(JSON.stringify(gyms));
alert("Done : "+iterator+" gyms exported to console");
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment