Created
January 17, 2021 11:02
-
-
Save scottpdawson/e4a9e7febf073302c46f012b46cc5676 to your computer and use it in GitHub Desktop.
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
// | |
// 1. Go to https://www.strava.com/athlete/training | |
// | |
// 2. Open the Chrome developer console | |
// | |
// 3. Paste into the console the code from | |
// https://github.com/eligrey/FileSaver.js/blob/master/src/FileSaver.js | |
// | |
// 4. Paste the two functions below into the console | |
// | |
// 5. Type run getActivities(true) or getActivities(false) | |
// | |
// With true as the parameter it will wait for the activity to download before | |
// starting the next download. | |
// | |
// With false it will send the requests off for all at the same time. This is | |
// much faster but may fail - more testing needed. | |
// | |
// To get more activities select another page of activities and run getActivities() | |
// again. | |
function getActivity(i) { | |
return new Promise(function(resolve, reject) { | |
var attr = activityCollection.models[i].attributes | |
var filename = attr.start_time + '-' + attr.name + ".tcx" | |
var xhttp = new XMLHttpRequest(); | |
xhttp.open("GET", attr.activity_url + "/export_tcx", true); | |
xhttp.responseType = 'blob' | |
xhttp.onload = function() { | |
if (xhttp.responseURL === attr.activity_url) { // 302 redirect back to the activity page | |
console.log (i | |
+ ": Looks like Strava can't download this activity. Does it have a distance?\n" | |
+ "Try manually downloading this url " | |
+ attr.activity_url + "/export_tcx"); | |
} else { | |
saveAs(xhttp.response, filename); | |
console.log(i + ':' + filename); | |
} | |
resolve(); | |
} | |
xhttp.onerror = function() { | |
console.log("Error: " + i + ':' + filename); | |
reject(); | |
} | |
xhttp.send(); | |
}); | |
} | |
async function getActivities(wait) { | |
for (var i = 0; i < activityCollection.models.length; i++) { | |
wait ? await getActivity(i) : getActivity(i); | |
} | |
console.log("all done") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had an issue with
saveAs
not being defined – everything worked when I pasted the contents of https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js into the console as well (found via https://stackoverflow.com/a/54527783)