GitHub Auto Signup

Automate github signup

当前为 2024-02-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GitHub Auto Signup
  3. // @version 0.2
  4. // @description Automate github signup
  5. // @author Young Jimmy
  6. // @match https://github.com/signup*
  7. // @match https://github.com/account_verifications?recommend_plan=true
  8. // @grant GM_xmlhttpRequest
  9. // @license MIT
  10. // @namespace https://greasyfork.org/users/1218336
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Delay function
  17. function delay(time) {
  18. return new Promise(function(resolve) {
  19. setTimeout(resolve, time);
  20. });
  21. }
  22.  
  23. // Wait for label with specific content to exist
  24. function labelReady(content) {
  25. return new Promise((resolve, reject) => {
  26. new MutationObserver((mutationRecords, observer) => {
  27. Array.from(document.querySelectorAll('label')).forEach((element) => {
  28. if (element.textContent.trim() === content) {
  29. console.log(`Label with content "${content}" found.`);
  30. resolve(element);
  31. observer.disconnect();
  32. }
  33. });
  34. })
  35. .observe(document.documentElement, {childList: true, subtree: true});
  36. });
  37. }
  38.  
  39. function generatePassword(length) {
  40. const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+~`|}{[]:;?><,./-=";
  41. let retVal = "";
  42. for (let i = 0, n = charset.length; i < length; ++i) {
  43. retVal += charset.charAt(Math.floor(Math.random() * n));
  44. }
  45. return retVal;
  46. }
  47.  
  48. function generateUsername(length) {
  49. let result = '';
  50. const characters = '0123456789';
  51. const charactersLength = characters.length;
  52. for (let i = 0; i < length; i++) {
  53. result += characters.charAt(Math.floor(Math.random() * charactersLength));
  54. }
  55. return result;
  56. }
  57.  
  58. // Wait for element to exist
  59. function elementReady(selector) {
  60. return new Promise((resolve, reject) => {
  61. let el = document.querySelector(selector);
  62. if (el) { resolve(el); }
  63. new MutationObserver((mutationRecords, observer) => {
  64. // Query for elements matching the specified selector
  65. Array.from(document.querySelectorAll(selector)).forEach((element) => {
  66. resolve(element);
  67. //Once we have resolved we don't need the observer anymore.
  68. observer.disconnect();
  69. });
  70. })
  71. .observe(document.documentElement, {childList: true, subtree: true});
  72. });
  73. }
  74.  
  75. async function signup(email) {
  76. const password = generatePassword(12);
  77. const username = generateUsername(Math.floor(Math.random() * 5) + 8);
  78.  
  79. console.log("Waiting for label...");
  80. await labelReady("Enter your email*");
  81.  
  82. console.log("Starting signup process...");
  83. await elementReady(".js-continue-container").then(element => element.click());
  84. await delay(1000);
  85.  
  86. await elementReady("#email").then(element => element.value = email);
  87. await elementReady(".mx-1").then(element => element.click());
  88. await elementReady("#email-container .js-continue-button").then(element => element.click());
  89. await delay(1000);
  90.  
  91. await elementReady("#password").then(element => {element.click(); element.value = password;});
  92. await elementReady(".mx-1").then(element => element.click());
  93. await elementReady("#password-container .js-continue-button").then(element => element.click());
  94. await delay(1000);
  95.  
  96. await elementReady("#login").then(element => {element.click(); element.value = username;});
  97. await elementReady(".mx-1").then(element => element.click());
  98. await elementReady("#username-container .js-continue-button").then(element => element.click());
  99. await elementReady("#opt-in-container .js-continue-button").then(element => element.click());
  100. await elementReady("button[name=button]").then(element => element.click());
  101.  
  102. console.log("Signup process completed.");
  103. // Store the email in localStorage after signup
  104. localStorage.setItem('email', email);
  105. }
  106.  
  107. async function getEmail() {
  108. return new Promise((resolve, reject) => {
  109. GM_xmlhttpRequest({
  110. method: "GET",
  111. url: "http://127.0.0.1:5000/get_email",
  112. onload: function(response) {
  113. console.log('http://127.0.0.1:5000/get_email',response.responseText)
  114. const data = JSON.parse(response.responseText);
  115. if (data.account) {
  116. resolve(data.account);
  117. } else {
  118. reject('Failed to get email');
  119. }
  120. }
  121. });
  122. });
  123. }
  124.  
  125. async function getVerificationCode(email) {
  126. return new Promise((resolve, reject) => {
  127. GM_xmlhttpRequest({
  128. method: "GET",
  129. url: `http://127.0.0.1:5000/get_verification_code?account=${email}`,
  130. onload: function(response) {
  131. console.log(response.responseText)
  132. const data = JSON.parse(response.responseText);
  133. if (data.verification_code) {
  134. resolve(data.verification_code);
  135. } else {
  136. reject('Failed to get verification code');
  137. }
  138. }
  139. });
  140. });
  141. }
  142.  
  143. async function fillVerificationCode(code) {
  144. const codeInputs = Array.from(document.querySelectorAll('.form-control.input-monospace'));
  145. const codeArray = code.split('');
  146. codeInputs.forEach((input, index) => {
  147. if (codeArray[index]) {
  148. input.value = codeArray[index];
  149. input.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
  150. }
  151. });
  152. }
  153.  
  154.  
  155.  
  156. async function checkVerificationCode(email) {
  157. while (true) {
  158. try {
  159. const code = await getVerificationCode(email);
  160. if (code) {
  161. fillVerificationCode(code);
  162. break;
  163. }
  164. } catch (error) {
  165. console.error(error);
  166. }
  167. await delay(3000);
  168. }
  169. }
  170.  
  171. console.log("Script loaded, waiting for page load...");
  172. window.addEventListener('load', async function() {
  173. console.log("Page loaded, starting script...");
  174. if (window.location.href === 'https://github.com/signup?source=login') {
  175. console.log('start get eamil')
  176. let email = await getEmail();
  177. signup(email);
  178. } else if (window.location.href === 'https://github.com/account_verifications?recommend_plan=true') {
  179. // Retrieve the email from localStorage on the verification page
  180. let email = localStorage.getItem('email');
  181. if (email) {
  182. checkVerificationCode(email);
  183. }
  184. }
  185. }, false);
  186.  
  187. })();