admin管理员组

文章数量:1401460

I have this script for tampermonkey that should enter a random email on Spotify sign up page and click on submit. For now it does enter the email but it disappears after 2 secs instead of staying in the placeholder, it gives an "This email is invalid. Make sure it's written like [email protected]" as it's empty and it doesn't click on submit.

// ==UserScript==
// @name         Spotify Auto Registration
// @namespace    /
// @version      1.3
// @description  Automate Spotify account creation
// @author       You
// @match        https://*.spotify/*/signup*
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function () {
    'use strict';

    // Helper function to generate a valid random email with only letters
    function generateRandomEmail() {
        const letters = 'abcdefghijklmnopqrstuvwxyz';
        let randomString = '';
        for (let i = 0; i < 8; i++) { // Generate an 8-character string
            randomString += letters[Math.floor(Math.random() * letters.length)];
        }
        const domains = ['gmail', 'yahoo', 'outlook'];
        const randomDomain = domains[Math.floor(Math.random() * domains.length)];
        return `${randomString}@${randomDomain}`;
    }

    // Helper function for wait time
    function wait(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }

    // Function to fill out the form
    async function fillSpotifyForm() {
        const email = GM_getValue('lastEmail', generateRandomEmail()); // Get or generate email
        const password = 'Spotify123!'; // Replace with your desired password

        console.log(`Creating account with email: ${email}`);

        try {
            // Fill email field
            const emailInputField = document.querySelector('#username');
            if (emailInputField) {
                emailInputField.focus();
                emailInputField.value = email;
                await wait(500); // Allow the field to process input
            }

            // Click the next button
            const submitButton = document.querySelector('button[data-testid="submit"]');
            if (submitButton && !submitButton.disabled) {
                submitButton.click();
                await wait(1000); // Wait for the next step to load
            }

            
        } catch (error) {
            console.error('Error filling the form:', error);
        }
    }

    // Wait for the page to load and execute the script
    window.addEventListener('load', () => {
        setTimeout(() => {
            fillSpotifyForm();
        }, 2000); // Adjust delay as needed
    });
})();

本文标签: javascriptTampermonkey script email disappearingStack Overflow