Recaptcha Skipper

Try to skip google recaptcha error page automatically through reloading the page. If not, redirect to configurable url

当前为 2021-09-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Recaptcha Skipper
  3. // @namespace c4ca4238a0b923820dcc509a6f75849b
  4. // @version 0.3
  5. // @description Try to skip google recaptcha error page automatically through reloading the page. If not, redirect to configurable url
  6. // @author _SUDO
  7. // @match https://www.google.com/sorry/*
  8. // @grant GM_addStyle
  9. // @compatible chrome Chrome + Tampermonkey or Violentmonkey
  10. // @compatible firefox Firefox + Greasemonkey or Tampermonkey or Violentmonkey
  11. // @compatible opera Opera + Tampermonkey or Violentmonkey
  12. // @compatible edge Edge + Tampermonkey or Violentmonkey
  13. // @compatible safari Safari + Tampermonkey or Violentmonkey
  14. // ==/UserScript==
  15. /* jshint esversion: 6 */
  16.  
  17. (function (){
  18. 'use strict';
  19. const config = {
  20. redirect_to: true, // Will redirect the actual searched query to the defined url (from ?q=[terms])
  21. redirect_to_url: 'https://duckduckgo.com/?q=', // if you like DuckDuckGo for example... https://duckduckgo.com/?q=
  22. promp_redirect: true, // Create UI to cancel redirection
  23. verbose_logging: false
  24. }
  25.  
  26. const logger = (...args) => {
  27. if (!config.verbose_logging) {
  28. return;
  29. }
  30. console.log(...args)
  31. }
  32.  
  33.  
  34. class SkipCaptcha {
  35. constructor() {
  36. this.url = false
  37. this.tries = 1
  38. }
  39.  
  40. // Create a 3sec counter to allow the user to cancel automatic redirection
  41. create_Redirect_UI () {
  42. if (!config.promp_redirect) return this; // Will automatically allow
  43.  
  44. let redirect_allowed = true // By default it's automatically allowed redirect
  45.  
  46. // Add progress bar style
  47.  
  48. GM_addStyle(`
  49. #UIcounter {
  50. box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25) inset;
  51. }
  52. #UIcounter[value] {
  53. /* Reset the default appearance */
  54. -webkit-appearance: none;
  55. -moz-appearance: none;
  56. appearance: none;
  57.  
  58. /* Get rid of default border in Firefox. */
  59. border: none;
  60.  
  61. /* Dimensions */
  62. width: 100%;
  63. height: 20px;
  64. }
  65.  
  66. #UIcounter[value]::-moz-progress-bar {
  67. background-color: #09c;
  68. background-image:
  69. /* the stripe layer */linear-gradient(45deg, rgba(255, 255, 255, 0.16) 25%, rgba(0, 0, 0, 0) 25%, rgba(0, 0, 0, 0) 50%, rgba(255, 255, 255, 0.16) 50%, rgba(255, 255, 255, 0.16) 75%, rgba(0, 0, 0, 0) 75%, rgba(0, 0, 0, 0)), linear-gradient(to right, #09c, #f44);
  70.  
  71. /* we also need background-size, because the stripe must repeat every 20 pixels */
  72. background-size: 60px 50px, 100%;
  73. }`)
  74.  
  75. document.body.innerHTML += `
  76. <div id="userUI" style="position: fixed; bottom: 5px; right: 5px; background: #f9f9f9; z-index: 999999;border-radius: 5px; box-shadow: 0 0 5px -1px;border: 1px solid gray;display: grid;grid-template-columns: 0.3fr 1.6fr;">
  77. <a id="redirect" style="cursor: pointer; text-align: center;font-size: 24px;box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25) inset;margin: 0;padding-top: 21px;border-radius: 5px 0 0 5px;text-decoration: none;color: black;">►</a>
  78. <div>
  79. <p style="margin: 15px;">You will be automatically redirected...</p>
  80. <progress id="UIcounter" max="${100}" value="0" style="width: 100%; height: 15px;"></progress>
  81. <div>
  82. </div>`
  83. const UI = document.getElementById('userUI')
  84. const UI_skipBTN = document.getElementById('redirect')
  85. const UI_Counter = document.getElementById('UIcounter')
  86. let counter = 0
  87.  
  88. logger('Started countdown')
  89. const processBar = setInterval(() => {
  90. if (counter >= 100) {
  91. logger('Ended countdown')
  92. remove_event()
  93. clearInterval(processBar)
  94. }
  95. counter = counter >= 100 ? 100 : counter+5
  96. UI_Counter.value = counter
  97. }, 135)
  98.  
  99. // This event will allows us to just force skip
  100. const event_skip = UI_skipBTN.addEventListener('click', () => {
  101. logger('User clicked, cancelled redirect.')
  102. clearInterval(processBar)
  103.  
  104. this.handle_redirects()
  105. }, {once: true})
  106.  
  107. const event = UI.addEventListener('click', () => {
  108. if (counter != 100) {
  109. redirect_allowed = false
  110. logger('User clicked, cancelled redirect.')
  111. clearInterval(processBar)
  112. }
  113. }, {once: true})
  114.  
  115. const remove_event = () => {
  116. logger('Removed Event Listener')
  117. UI.removeEventListener('click', event, true)
  118. }
  119.  
  120. return new Promise(resolve => {
  121. setTimeout(() => {
  122. logger('Redirect Status:', redirect_allowed)
  123. resolve(redirect_allowed)
  124. }, 3000)
  125. })
  126. }
  127.  
  128. checkAttemps () {
  129. // Will check if there's a value of previous retries on the sesion storage, if not create one
  130. const storage = sessionStorage
  131. const storage_name = 'Captch_Retries'
  132.  
  133. // Check if it's already a value
  134. if (storage.getItem(storage_name)) {
  135. this.tries = storage.getItem(storage_name)
  136. logger('Retries saved:', this.tries)
  137. if (!typeof this.tries === 'number') {
  138. logger('Value not a number, parsing to integer...')
  139. this.tries = parseInt(this.tries)
  140. }
  141. logger('Adding an attemt to saved retries...')
  142. this.tries++
  143. storage.setItem(storage_name, this.tries)
  144.  
  145. logger('New set value stored:', this.tries)
  146. }
  147. else {
  148. logger('Any previous retries saved, creating a new storage item with value of', this.tries)
  149. storage.setItem(storage_name, this.tries)
  150. }
  151.  
  152. logger('checkAttemps', this.tries)
  153.  
  154. return this
  155. }
  156.  
  157. async redirectURL_to_Google () {
  158. // Forced await
  159. const response = await this.create_Redirect_UI()
  160. if (!response) {
  161. logger('User cancelled redirect')
  162. return;
  163. }
  164. this.handle_redirects()
  165.  
  166. return this
  167. }
  168.  
  169. handle_redirects () {
  170. if (this.url) {
  171. if (this.tries < 3) {
  172. window.location = this.url
  173. } else {
  174. if (config.redirect_to) {
  175. this.redirect_to_user_defined_url()
  176. } else {
  177. logger('Not redirecting, too many retries:', this.url, this.tries)
  178. }
  179. }
  180. } else {
  181. logger('ERROR: no url finded!')
  182. }
  183.  
  184. return this
  185. }
  186.  
  187. redirect_to_user_defined_url () {
  188. logger(`Redirecting to "${config.redirect_to_url}"`)
  189.  
  190. // this.url is the <title> string and we have to convert to an URL to use URLSearchParams constructor
  191. const gen_URL_to_search = new URL(this.url)
  192. const getSearchedParams = new URLSearchParams(gen_URL_to_search.search).get('q') // Only get que Query searched
  193. const newURL = config.redirect_to_url + getSearchedParams
  194. logger('Google search params:', getSearchedParams)
  195. logger('New URL generated to redirect:', newURL)
  196.  
  197. // Send to the new url formated
  198. window.location = newURL
  199.  
  200. // If works properly, a return isn't necesary
  201. // return this
  202. }
  203.  
  204. getURL () {
  205. // The search url/terms are in the page url and body,
  206. // because I'am lazy I will get it from the title element
  207. const url = document.getElementsByTagName('title')[0].textContent
  208. if (url.lenght != 0) {
  209. this.url = url
  210. }
  211. logger('URL:', this.url)
  212.  
  213. return this
  214. }
  215.  
  216. init () {
  217. logger('Initilizing...')
  218. this.getURL().checkAttemps().redirectURL_to_Google()
  219. }
  220. }
  221.  
  222. const init = new SkipCaptcha().init()
  223.  
  224. if (document.readyState === 'complete') {
  225. init
  226. } else {
  227. document.addEventListener('readystatechange', function () {
  228. if (document.readyState === 'complete') {
  229. init
  230. }
  231. })
  232. }
  233. })()