Last active
June 11, 2018 18:43
-
-
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
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 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