|
1 | 1 | // ==UserScript== |
2 | | -// @name Automatically Select First Google Account to Sign In |
| 2 | +// @name Auto Click Google Sign-In Button |
3 | 3 | // @namespace typpi.online |
4 | | -// @version 1.1 |
5 | | -// @description Selects the first Google account in the Google account selector page |
| 4 | +// @version 1.2 |
| 5 | +// @description Automatically clicks the Google sign-in button on the page |
6 | 6 | // @author Nick2bad4u |
7 | | -// @match https://accounts.google.com/* |
| 7 | +// @match https://www.strava.com/login |
8 | 8 | // @grant none |
9 | 9 | // @license Unlicense |
10 | 10 | // @homepageURL https://github.com/Nick2bad4u/UserStyles |
11 | 11 | // @supportURL https://github.com/Nick2bad4u/UserStyles/issues |
12 | | -// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com |
| 12 | +// @icon https://www.google.com/s2/favicons?sz=64&domain=strava.com |
| 13 | +// @downloadURL https://update.greasyfork.org/scripts/531639/Auto%20Click%20Google%20Sign-In%20Button.user.js |
| 14 | +// @updateURL https://update.greasyfork.org/scripts/531639/Auto%20Click%20Google%20Sign-In%20Button.meta.js |
13 | 15 | // ==/UserScript== |
14 | 16 |
|
15 | | -(function() { |
16 | | - 'use strict'; |
| 17 | +(function () { |
| 18 | + 'use strict'; |
17 | 19 |
|
18 | | - // Function to select the first account |
19 | | - const selectFirstAccount = () => { |
20 | | - const firstAccount = document.querySelector('li.aZvCDf'); |
21 | | - if (firstAccount) { |
22 | | - const firstLink = firstAccount.querySelector('div[role="link"]'); |
23 | | - if (firstLink) { |
24 | | - firstLink.click(); |
25 | | - } else { |
26 | | - console.log('First account link not found.'); |
27 | | - } |
28 | | - } else { |
29 | | - console.log('First account not found on the page.'); |
30 | | - } |
31 | | - }; |
| 20 | + // Function to find and click the Google sign-in button |
| 21 | + const clickGoogleSignIn = () => { |
| 22 | + const buttons = Array.from(document.querySelectorAll('button, a')); // Get all buttons and links |
| 23 | + const googleButton = buttons.find((btn) => btn.innerText.includes('Sign In With Google')); |
| 24 | + if (googleButton) { |
| 25 | + googleButton.click(); |
| 26 | + } else { |
| 27 | + console.log('Google Sign-In button not found.'); |
| 28 | + } |
| 29 | + }; |
32 | 30 |
|
33 | | - // Set up a MutationObserver to wait for dynamic content |
34 | | - const observer = new MutationObserver(() => { |
35 | | - if (document.querySelector('li.aZvCDf')) { |
36 | | - selectFirstAccount(); |
37 | | - observer.disconnect(); // Stop observing once the element is found |
38 | | - } |
39 | | - }); |
| 31 | + // Use MutationObserver to wait for the button if the page loads dynamically |
| 32 | + const observer = new MutationObserver(() => { |
| 33 | + const buttons = Array.from(document.querySelectorAll('button, a')); |
| 34 | + const googleButton = buttons.find((btn) => btn.innerText.includes('Sign In With Google')); |
| 35 | + if (googleButton) { |
| 36 | + clickGoogleSignIn(); |
| 37 | + observer.disconnect(); // Stop observing once the button is found and clicked |
| 38 | + } |
| 39 | + }); |
40 | 40 |
|
41 | | - // Observe changes in the document body |
42 | | - observer.observe(document.body, { childList: true, subtree: true }); |
| 41 | + // Observe changes in the document body |
| 42 | + observer.observe(document.body, { childList: true, subtree: true }); |
43 | 43 | })(); |
0 commit comments