|
| 1 | +// ==UserScript== |
| 2 | +// @name Garmin Connect: Select All Participants for Challenges |
| 3 | +// @namespace typpi.online |
| 4 | +// @version 1.5 |
| 5 | +// @description Adds a button to select all participants in Garmin Connect challenges and logs participant details |
| 6 | +// @author Nick2bad4u |
| 7 | +// @match https://connect.garmin.com/modern/challenge/create-challenge |
| 8 | +// @grant none |
| 9 | +// @license Unlicense |
| 10 | +// @homepageURL https://github.com/Nick2bad4u/UserStyles |
| 11 | +// @supportURL https://github.com/Nick2bad4u/UserStyles/issues |
| 12 | +// @icon https://www.google.com/s2/favicons?sz=64&domain=garmin.com |
| 13 | +// @downloadURL https://update.greasyfork.org/scripts/531640/Garmin%20Connect%20Select%20All%20Participants%20for%20Challenges.user.js |
| 14 | +// @updateURL https://update.greasyfork.org/scripts/531640/Garmin%20Connect%20Select%20All%20Participants%20for%20Challenges.meta.js |
| 15 | +// ==/UserScript== |
| 16 | + |
| 17 | +(function () { |
| 18 | + 'use strict'; |
| 19 | + |
| 20 | + // Create the button |
| 21 | + const button = document.createElement('button'); |
| 22 | + button.textContent = 'Select All Participants'; |
| 23 | + button.className = 'select-participants-button'; // custom class to avoid duplicate insertions |
| 24 | + |
| 25 | + // Adjust styling suitable for inline placement (instead of fixed position) |
| 26 | + button.style.marginLeft = '10px'; |
| 27 | + button.style.padding = '5px 10px'; |
| 28 | + button.style.backgroundColor = '#007bff'; |
| 29 | + button.style.color = '#fff'; |
| 30 | + button.style.border = 'none'; |
| 31 | + button.style.borderRadius = '5px'; |
| 32 | + button.style.cursor = 'pointer'; |
| 33 | + |
| 34 | + // Button click handler: simulate a click event on each checkbox |
| 35 | + button.addEventListener('click', () => { |
| 36 | + // Find all checkbox inputs within the participant labels |
| 37 | + const checkboxes = document.querySelectorAll('label.ConnectionParticipant_connection__9WFV6 input[type="checkbox"]'); |
| 38 | + checkboxes.forEach((checkbox) => { |
| 39 | + // Only simulate click if not already checked (to avoid toggling off) |
| 40 | + if (!checkbox.checked) { |
| 41 | + checkbox.click(); |
| 42 | + } |
| 43 | + // Log participant details by retrieving the name element in the same label structure |
| 44 | + const participantNameElement = checkbox.closest('label').querySelector('div.ConnectionParticipant_name__A620Z'); |
| 45 | + const participantName = participantNameElement ? participantNameElement.textContent.trim() : 'Unknown'; |
| 46 | + console.log(`Simulated click on participant: ${participantName}`); |
| 47 | + }); |
| 48 | + |
| 49 | + console.log(`Total simulated clicks: ${checkboxes.length}`); |
| 50 | + alert(`Simulated clicks on ${checkboxes.length} participant checkboxes!`); |
| 51 | + }); |
| 52 | + |
| 53 | + // Function that looks for the section title element and inserts the button when found |
| 54 | + function insertButton() { |
| 55 | + const sectionTitle = document.querySelector('div.CreateChallengePageIndex_sectionTitle__kLfj1'); |
| 56 | + if (sectionTitle && sectionTitle.textContent.includes('Who do you want to challenge?') && !sectionTitle.querySelector('.select-participants-button')) { |
| 57 | + // Append the button to the section title element |
| 58 | + sectionTitle.appendChild(button); |
| 59 | + console.log('Select button inserted into the section title element.'); |
| 60 | + // Once inserted, stop further observation |
| 61 | + observer.disconnect(); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + // Create a MutationObserver to monitor the DOM for the section title element |
| 66 | + const observer = new MutationObserver(() => { |
| 67 | + insertButton(); |
| 68 | + }); |
| 69 | + |
| 70 | + // Start observing the document body |
| 71 | + observer.observe(document.body, { childList: true, subtree: true }); |
| 72 | + |
| 73 | + // Also try to insert immediately in case the element is already present |
| 74 | + insertButton(); |
| 75 | +})(); |
0 commit comments