Skip to content

Instantly share code, notes, and snippets.

@scottpdawson
Created January 17, 2021 11:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottpdawson/e4a9e7febf073302c46f012b46cc5676 to your computer and use it in GitHub Desktop.
Save scottpdawson/e4a9e7febf073302c46f012b46cc5676 to your computer and use it in GitHub Desktop.
//
// 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")
}
@frankrolf
Copy link

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)

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