Auto Click "I'm not a robot"

Automatically clicks the "I'm not a robot" checkbox on reCaptcha V2, reCaptcha V2 callback, reCaptcha V2 Enterprise, and hCaptcha captchas

  1. // ==UserScript==
  2. // @name Auto Click "I'm not a robot"
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.9
  5. // @description Automatically clicks the "I'm not a robot" checkbox on reCaptcha V2, reCaptcha V2 callback, reCaptcha V2 Enterprise, and hCaptcha captchas
  6. // @author JJJ
  7. // @match *://*/*
  8. // @icon https://pngimg.com/uploads/robot/robot_PNG96.png
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. // Constants for selectors and attributes
  17. const CHECKBOX = "#checkbox";
  18. const ARIA_CHECKED = "aria-checked";
  19.  
  20. // Utility function to select a single element
  21. function qSelector(selector) {
  22. return document.querySelector(selector);
  23. }
  24.  
  25. // Utility function to check if an element is hidden
  26. function isHidden(el) {
  27. return (el.offsetParent === null);
  28. }
  29.  
  30. // Handler for reCaptcha V2
  31. const reCaptchaV2Handler = {
  32. // Find the checkbox element for reCaptcha V2
  33. findCheckboxElement() {
  34. return document.querySelector('.recaptcha-checkbox-border') ||
  35. document.querySelector('[role="checkbox"][aria-labelledby="recaptcha-anchor-label"]') ||
  36. qSelector(CHECKBOX);
  37. },
  38. // Solve the reCaptcha V2 by clicking the checkbox
  39. solve() {
  40. const checkbox = this.findCheckboxElement();
  41. if (checkbox && !isHidden(checkbox) && checkbox.getAttribute(ARIA_CHECKED) !== "true") {
  42. checkbox.click();
  43. }
  44. }
  45. };
  46.  
  47. // Handler for reCaptcha V2 callback
  48. const reCaptchaV2CallbackHandler = {
  49. // Find the callback function for reCaptcha V2
  50. findCallbackFunction() {
  51. if (typeof ___grecaptcha_cfg !== 'undefined') {
  52. const keys = Object.keys(___grecaptcha_cfg.clients).filter(key => key !== 'load');
  53. for (const key of keys) {
  54. const client = ___grecaptcha_cfg.clients[key];
  55. if (client && typeof client.hl?.l?.callback === 'function') {
  56. return client.hl.l.callback;
  57. }
  58. }
  59. }
  60. return null;
  61. },
  62. // Solve the reCaptcha V2 by invoking the callback function
  63. solve() {
  64. const callbackFn = this.findCallbackFunction();
  65. if (typeof callbackFn === 'function') {
  66. callbackFn();
  67. }
  68. }
  69. };
  70.  
  71. // Handler for reCaptcha V2 Enterprise
  72. const reCaptchaV2EnterpriseHandler = {
  73. // Find the checkbox element for reCaptcha V2 Enterprise
  74. findEnterpriseCheckboxElement() {
  75. return document.querySelector('.enterprise-checkbox') ||
  76. document.querySelector('[aria-labelledby="recaptcha-accessible-status"]');
  77. },
  78. // Solve the reCaptcha V2 Enterprise by clicking the checkbox
  79. solve() {
  80. const checkbox = this.findEnterpriseCheckboxElement();
  81. if (checkbox && !isHidden(checkbox) && checkbox.getAttribute(ARIA_CHECKED) !== "true") {
  82. checkbox.click();
  83. }
  84. }
  85. };
  86.  
  87. // Handler for hCaptcha
  88. const hCaptchaHandler = {
  89. // Find the checkbox element for hCaptcha
  90. findCheckboxElement() {
  91. return document.querySelector('.hcaptcha-checkbox') ||
  92. document.querySelector('[aria-labelledby="hcaptcha-anchor-label"]');
  93. },
  94. // Solve the hCaptcha by clicking the checkbox
  95. solve() {
  96. const checkbox = this.findCheckboxElement();
  97. if (checkbox && !isHidden(checkbox) && checkbox.getAttribute(ARIA_CHECKED) !== "true") {
  98. checkbox.click();
  99. }
  100. }
  101. };
  102.  
  103. // Main captcha solver that tries to solve all types of captchas
  104. const captchaSolver = {
  105. solve() {
  106. reCaptchaV2Handler.solve();
  107. reCaptchaV2CallbackHandler.solve();
  108. reCaptchaV2EnterpriseHandler.solve();
  109. hCaptchaHandler.solve();
  110. }
  111. };
  112.  
  113. // Initialize a MutationObserver to detect changes in the DOM
  114. function initializeObserver() {
  115. const observer = new MutationObserver((mutations) => {
  116. for (const mutation of mutations) {
  117. if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
  118. captchaSolver.solve();
  119. }
  120. }
  121. });
  122.  
  123. observer.observe(document.body, { childList: true, subtree: true });
  124. }
  125.  
  126. // Initialize the script
  127. function init() {
  128. captchaSolver.solve();
  129.  
  130. // Periodically try to solve captchas
  131. setInterval(() => {
  132. captchaSolver.solve();
  133. }, 1000);
  134. }
  135.  
  136. // Check if the document is still loading
  137. if (document.readyState === 'loading') {
  138. document.addEventListener('DOMContentLoaded', () => {
  139. initializeObserver();
  140. init();
  141. });
  142. } else {
  143. initializeObserver();
  144. init();
  145. }
  146.  
  147. // Compatibility check for supported browsers
  148. const userAgent = navigator.userAgent.toLowerCase();
  149. const isCompatibleBrowser = ['chrome', 'edg', 'brave', 'firefox'].some(browser => userAgent.includes(browser));
  150.  
  151. console.log(isCompatibleBrowser ? 'Running on a compatible browser' : 'Running on an unsupported browser');
  152. })();