Skip to content

Instantly share code, notes, and snippets.

@nakami
Created December 3, 2021 22:37
Show Gist options
  • Save nakami/f4b23710f9775309a0506d9533dfcc4b to your computer and use it in GitHub Desktop.
Save nakami/f4b23710f9775309a0506d9533dfcc4b to your computer and use it in GitHub Desktop.
Adds a button "Join All Challenges" to click all "Join Challenge" buttons
// ==UserScript==
// @name Strava "Join All Challenges" button
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Adds a button "Join All Challenges" to click all "Join Challenge" buttons
// @author nakami
// @match https://www.strava.com/challenges*
// @icon https://d3nn82uaxijpm6.cloudfront.net/favicon-32x32.png?v=dLlWydWlG8
// @grant none
// @run-at document-idle
// ==/UserScript==
/*
Support me by donating to my PayPal address:
https://www.paypal.com/donate/?hosted_button_id=VNDER8T6AZ732
Thank you!
*/
(function() {
'use strict';
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
sleep(2000).then(() => {
function joinAllChallenges() {
console.log('joinAllChallenges');
let buts = document.getElementsByTagName("Button");
let buts2 = [...buts];
buts2 = buts2.filter(x => x.textContent == "Join Challenge");
console.log("found number of buttons:" + buts2.length);
for (var i = 0, len = buts2.length; i < len; i++) {
buts2[i].click();
}
};
let joinAllBtn = document.createElement('button');
joinAllBtn.setAttribute('class', 'btn--primary');
joinAllBtn.textContent = 'Join All Challenges';
joinAllBtn.onclick = joinAllChallenges;
let filterContainer = document.querySelector("div#filter-container");
filterContainer.parentNode.insertBefore(joinAllBtn, filterContainer.nextSibling);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment