GitHub Auto Signup

Automate github signup

目前為 2024-02-21 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         GitHub Auto Signup
// @version      0.1
// @description  Automate github signup
// @author       Young Jimmy
// @match        https://github.com/signup*
// @grant        none
// @license      MIT
// @namespace https://greasyfork.org/users/1218336
// ==/UserScript==

(function() {
    'use strict';

    // Delay function
    function delay(time) {
        return new Promise(function(resolve) {
            setTimeout(resolve, time);
        });
    }

    // Wait for label with specific content to exist
    function labelReady(content) {
        return new Promise((resolve, reject) => {
            new MutationObserver((mutationRecords, observer) => {
                Array.from(document.querySelectorAll('label')).forEach((element) => {
                    if (element.textContent.trim() === content) {
                        console.log(`Label with content "${content}" found.`);
                        resolve(element);
                        observer.disconnect();
                    }
                });
            })
            .observe(document.documentElement, {childList: true, subtree: true});
        });
    }

    function generatePassword(length) {
        const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+~`|}{[]:;?><,./-=";
        let retVal = "";
        for (let i = 0, n = charset.length; i < length; ++i) {
            retVal += charset.charAt(Math.floor(Math.random() * n));
        }
        return retVal;
    }

    function generateUsername(length) {
        let result = '';
        const characters = '0123456789';
        const charactersLength = characters.length;
        for (let i = 0; i < length; i++) {
            result += characters.charAt(Math.floor(Math.random() * charactersLength));
        }
        return result;
    }

    async function signup(email) {
        const password = generatePassword(12);
        const username = generateUsername(Math.floor(Math.random() * 5) + 8);

        console.log("Waiting for label...");
        await labelReady("Enter your email*");

        console.log("Starting signup process...");
        await elementReady(".js-continue-container").then(element => element.click());
        await delay(1000);

        await elementReady("#email").then(element => element.value = email);
        await elementReady(".mx-1").then(element => element.click());
        await elementReady("#email-container .js-continue-button").then(element => element.click());
        await delay(1000);

        await elementReady("#password").then(element => {element.click(); element.value = password;});
        await elementReady(".mx-1").then(element => element.click());
        await elementReady("#password-container .js-continue-button").then(element => element.click());
        await delay(1000);

        await elementReady("#login").then(element => {element.click(); element.value = username;});
        await elementReady(".mx-1").then(element => element.click());
        await elementReady("#username-container .js-continue-button").then(element => element.click());
        await elementReady("#opt-in-container .js-continue-button").then(element => element.click());
        await elementReady("button[name=button]").then(element => element.click());

        console.log("Signup process completed.");
    }

    // Wait for element to exist
    function elementReady(selector) {
        return new Promise((resolve, reject) => {
            let el = document.querySelector(selector);
            if (el) { resolve(el); }
            new MutationObserver((mutationRecords, observer) => {
                // Query for elements matching the specified selector
                Array.from(document.querySelectorAll(selector)).forEach((element) => {
                    resolve(element);
                    //Once we have resolved we don't need the observer anymore.
                    observer.disconnect();
                });
            })
            .observe(document.documentElement, {childList: true, subtree: true});
        });
    }

    console.log("Script loaded, waiting for page load...");
    window.addEventListener('load', function() {
        console.log("Page loaded, starting script...");
        let email = "[email protected]";
        signup(email);
    }, false);

})();