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-21
  4. // @license MIT
  5. // @description try to take over the world!
  6. // @author SMNET
  7. // @grant GM_xmlhttpRequest
  8. // @match https://github.com/github-copilot/signup/billing?*
  9. // @match https://github.com/github-copilot/signup/success
  10. // @namespace https://greasyfork.org/users/1218336
  11. // ==/UserScript==
  12.  
  13. function fillForm3() {
  14. let summaryElement = document.querySelector('summary[data-view-component="true"]');
  15. if(summaryElement) {
  16. summaryElement.click();
  17. setTimeout(() => {
  18. let allowedButton = document.querySelector('button[value="allowed"]');
  19. if(allowedButton) {
  20. allowedButton.click();
  21. setTimeout(() => {
  22. let saveButton = document.getElementById('copilot_settings_submit');
  23. if(saveButton) {
  24. saveButton.click();
  25. } else {
  26. console.error('Could not find the "Save and complete setup" button');
  27. }
  28. }, 1500);
  29. } else {
  30. console.error('Could not find the "Allowed" button');
  31. }
  32. }, 1500);
  33. } else {
  34. console.error('Could not find the summary element');
  35. }
  36. }
  37.  
  38. function fillForm1(data) {
  39. let firstName = data.address.Full_Name.split(" ")[0];
  40. let lastName = data.address.Full_Name.split(" ")[1] || firstName;
  41. document.querySelector('input[name="user_contact_info[first_name]"]').value = firstName;
  42. document.querySelector('input[name="user_contact_info[last_name]"]').value = lastName;
  43. let countrySelect1 = document.querySelector('select[name="user_contact_info[country]"]');
  44. for(let i=0; i<countrySelect1.options.length; i++){
  45. if(countrySelect1.options[i].innerText === 'United States of America'){
  46. countrySelect1.value = countrySelect1.options[i].value;
  47. break;
  48. }
  49. }
  50. }
  51. function fillForm2(data) {
  52. let firstName = data.address.Full_Name.split(" ")[0];
  53. let lastName = data.address.Full_Name.split(" ")[1] || firstName;
  54. document.querySelector('input[name="account_screening_profile[first_name]"]').value = firstName;
  55. document.querySelector('input[name="account_screening_profile[last_name]"]').value = lastName;
  56. document.querySelector('input[name="account_screening_profile[address1]"]').value = data.address.Address;
  57. document.querySelector('input[name="account_screening_profile[city]"]').value = data.address.City;
  58. document.querySelector('input[name="account_screening_profile[region]"]').value = data.address.State;
  59. document.querySelector('input[name="account_screening_profile[postal_code]"]').value = data.address.Zip_Code;
  60. let countrySelect2 = document.querySelector('select[name="account_screening_profile[country_code]"]');
  61. for(let i=0; i<countrySelect2.options.length; i++){
  62. if(countrySelect2.options[i].innerText === 'United States of America'){
  63. countrySelect2.value = countrySelect2.options[i].value;
  64. break;
  65. }
  66. }
  67. let checkElement = document.querySelector('h4.mb-3');
  68. if(checkElement && checkElement.innerText.trim() === 'Payment method') {
  69. return;
  70. } else {
  71. let saveButton = document.querySelector('button[name="submit"][type="submit"]');
  72. if (saveButton) saveButton.click();
  73. }
  74. }
  75. window.onload = () => {
  76. let specificElement = document.querySelector('#copilot_settings_telemetry');
  77. if(specificElement) {
  78. return fillForm3();
  79. }
  80. GM_xmlhttpRequest({
  81. method: 'POST',
  82. url: 'https://www.meiguodizhi.com/api/v1/dz',
  83. headers: {
  84. 'Content-Type': 'application/json',
  85. },
  86. data: JSON.stringify({
  87. "city": "",
  88. "path": "/",
  89. "method": "refresh"
  90. }),
  91. onload: (response) => {
  92. var data = JSON.parse(response.responseText);
  93. specificElement = document.querySelector('input[name="user_contact_info[first_name]"]');
  94. if (specificElement) {
  95. fillForm1(data);
  96. } else {
  97. fillForm2(data);
  98. }
  99. },
  100. onerror: (error) => {
  101. console.error('Error during request:', error);
  102. }
  103. });
  104. };