GitHub Auto-Fill Form

try to take over the world!

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

  1. // ==UserScript==
  2. // @name GitHub Auto-Fill Form
  3. // @version 2024-02-19
  4. // @description try to take over the world!
  5. // @author SMNET
  6. // @license MIT
  7. // @grant GM_xmlhttpRequest
  8. // @match https://github.com/github-copilot/signup/billing?*
  9. // @namespace https://greasyfork.org/users/1218336
  10. // ==/UserScript==
  11.  
  12. function fillForm1(data) {
  13. let firstName = data.address.Full_Name.split(" ")[0];
  14. let lastName = data.address.Full_Name.split(" ")[1] || firstName;
  15. document.querySelector('input[name="user_contact_info[first_name]"]').value = firstName;
  16. document.querySelector('input[name="user_contact_info[last_name]"]').value = lastName;
  17. let countrySelect1 = document.querySelector('select[name="user_contact_info[country]"]');
  18. for(let i=0; i<countrySelect1.options.length; i++){
  19. if(countrySelect1.options[i].innerText === 'United States of America'){
  20. countrySelect1.value = countrySelect1.options[i].value;
  21. break;
  22. }
  23. }
  24. }
  25. function fillForm2(data) {
  26. let firstName = data.address.Full_Name.split(" ")[0];
  27. let lastName = data.address.Full_Name.split(" ")[1] || firstName;
  28. document.querySelector('input[name="account_screening_profile[first_name]"]').value = firstName;
  29. document.querySelector('input[name="account_screening_profile[last_name]"]').value = lastName;
  30. document.querySelector('input[name="account_screening_profile[address1]"]').value = data.address.Address;
  31. document.querySelector('input[name="account_screening_profile[city]"]').value = data.address.City;
  32. document.querySelector('input[name="account_screening_profile[region]"]').value = data.address.State;
  33. document.querySelector('input[name="account_screening_profile[postal_code]"]').value = data.address.Zip_Code;
  34. let countrySelect2 = document.querySelector('select[name="account_screening_profile[country_code]"]');
  35. for(let i=0; i<countrySelect2.options.length; i++){
  36. if(countrySelect2.options[i].innerText === 'United States of America'){
  37. countrySelect2.value = countrySelect2.options[i].value;
  38. break;
  39. }
  40. }
  41. let checkElement = document.querySelector('h4.mb-3');
  42. if(checkElement && checkElement.innerText.trim() === 'Payment method') {
  43. return;
  44. } else {
  45. let saveButton = [...document.querySelectorAll('button')].filter(button => button.innerText.trim() === 'Save')[0];
  46. if (saveButton) saveButton.click();
  47. }
  48. }
  49. window.onload = () => {
  50. GM_xmlhttpRequest({
  51. method: 'POST',
  52. url: 'https://www.meiguodizhi.com/api/v1/dz',
  53. headers: {
  54. 'Content-Type': 'application/json',
  55. },
  56. data: JSON.stringify({
  57. "city": "",
  58. "path": "/",
  59. "method": "refresh"
  60. }),
  61. onload: (response) => {
  62. var data = JSON.parse(response.responseText);
  63. let specificElement = document.querySelector('input[name="user_contact_info[first_name]"]');
  64. if (specificElement) {
  65. fillForm1(data);
  66. } else {
  67. fillForm2(data);
  68. }
  69. },
  70. onerror: (error) => {
  71. console.error('Error during request:', error);
  72. }
  73. });
  74. };