-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGarminConnect-SelectAllParticipantsForChallenges.user.js
More file actions
94 lines (83 loc) · 4.09 KB
/
GarminConnect-SelectAllParticipantsForChallenges.user.js
File metadata and controls
94 lines (83 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// ==UserScript==
// @name Garmin Connect: Select All Participants for Challenges
// @namespace typpi.online
// @version 1.8
// @description Adds a button to select all participants in Garmin Connect challenges and logs participant details
// @author Nick2bad4u
// @match https://connect.garmin.com/modern/challenge/create-challenge
// @grant none
// @license Unlicense
// @homepageURL https://github.com/Nick2bad4u/UserStyles
// @supportURL https://github.com/Nick2bad4u/UserStyles/issues
// @icon https://www.google.com/s2/favicons?sz=64&domain=garmin.com
// @downloadURL https://update.greasyfork.org/scripts/532475/Garmin%20Connect%3A%20Select%20All%20Participants%20for%20Challenges.user.js
// @updateURL https://update.greasyfork.org/scripts/532475/Garmin%20Connect%3A%20Select%20All%20Participants%20for%20Challenges.meta.js
// ==/UserScript==
(function () {
'use strict';
// Create the button
const button = document.createElement('button');
button.textContent = 'Select All Participants';
button.className = 'select-participants-button'; // custom class to avoid duplicate insertions
// Adjust styling suitable for inline placement (instead of fixed position)
button.style.marginLeft = '10px';
button.style.padding = '5px 10px';
button.style.backgroundColor = '#007bff';
button.style.color = '#fff';
button.style.border = 'none';
button.style.borderRadius = '5px';
button.style.cursor = 'pointer';
// Button click handler: simulate a click event on each checkbox
button.addEventListener('click', () => {
// Find all checkbox inputs within the participant labels
const checkboxes = document.querySelectorAll('label.ConnectionParticipant_connection__9WFV6 input[type="checkbox"]');
checkboxes.forEach((checkbox) => {
// Only simulate click if not already checked (to avoid toggling off)
if (!checkbox.checked) {
checkbox.click();
}
// Log participant details by retrieving the name element in the same label structure
const participantNameElement = checkbox.closest('label').querySelector('div.ConnectionParticipant_name__A620Z');
const participantName = participantNameElement ? participantNameElement.textContent.trim() : 'Unknown';
console.log(`Simulated click on participant: ${participantName}`);
});
console.log(`Total simulated clicks: ${checkboxes.length}`);
// Create a popup notification
const notification = document.createElement('div');
notification.textContent = `Successfully selected ${checkboxes.length} participants!`;
notification.style.position = 'absolute';
notification.style.top = `${button.offsetTop + button.offsetHeight + 10}px`;
notification.style.left = `${button.offsetLeft}px`;
notification.style.backgroundColor = '#007bff';
notification.style.color = '#fff';
notification.style.padding = '10px 20px';
notification.style.borderRadius = '5px';
notification.style.boxShadow = '0 4px 6px rgba(0, 0, 0, 0.1)';
notification.style.zIndex = '1000';
// Append the notification near the button
button.parentElement.appendChild(notification);
// Remove the notification after 3 seconds
setTimeout(() => {
notification.remove();
}, 3000);
});
// Function that looks for the section title element and inserts the button when found
function insertButton() {
const sectionTitle = document.querySelector('div.CreateChallengePageIndex_sectionTitle__kLfj1');
if (sectionTitle && sectionTitle.textContent.includes('Who do you want to challenge?') && !sectionTitle.querySelector('.select-participants-button')) {
// Append the button to the section title element
sectionTitle.appendChild(button);
console.log('Select button inserted into the section title element.');
// Once inserted, stop further observation
observer.disconnect();
}
}
// Create a MutationObserver to monitor the DOM for the section title element
const observer = new MutationObserver(() => {
insertButton();
});
// Start observing the document body
observer.observe(document.body, { childList: true, subtree: true });
// Also try to insert immediately in case the element is already present
insertButton();
})();