MoreCAPTCHA

Google reCAPTCHA on steroids.

Ekde 2017/07/02. Vidu La ĝisdata versio.

// ==UserScript==
// @name        MoreCAPTCHA
// @description Google reCAPTCHA on steroids.
// @namespace   https://eugenox.appspot.com/
// @include     https://www.google.com/recaptcha/api2/bframe?*
// @version     1.0
// @run-at      document-start
// @grant       unsafeWindow
// ==/UserScript==

const SPEED = 5;
  
var selector = new class {
  constructor() {
    this.selecting = undefined;
  }

  handle(event) {
    var tiles = new Set(document.querySelectorAll('#rc-imageselect td').values()), tile = event.target;

    while (tile && ! tiles.has(tile)) {
      tile = tile.parentNode;
    }

    if (tile) {
      event.stopPropagation();
      event.preventDefault();

      let selected = 'selected' in tile.dataset && tile.dataset.selected == 'true';

      if (this[event.type](selected)) {
        tile.dataset.selected = this.selecting;

        tile.firstElementChild.click();
      }
    }
  }

  mouseover(selected) {
    return ! (this.selecting === undefined || this.selecting === selected);
  }

  mousedown(selected) {
    this.selecting = ! selected;

    return true;
  }

  mouseup(selected) {
    this.selecting = undefined;

    return false;
  }
};

window.addEventListener('load', function(event) {
  var sheet = document.body.appendChild(document.createElement('style')).sheet;

  sheet.insertRule(
    '.rc-imageselect-table-42, .rc-imageselect-table-33, .rc-imageselect-table-44' +
    `{ transition-duration: ${1 / SPEED}s !important }`, 0);
  sheet.insertRule(
    '.rc-imageselect-dynamic-selected' + 
    `{ transition-duration: ${2 / SPEED}s !important }`, 1);
  sheet.insertRule(
    '.rc-imageselect-progress' +
    `{ transition-duration: ${1 / SPEED}s !important }`, 2);
  sheet.insertRule(
    '.rc-image-tile-overlay' +
    `{ transition-duration: ${1 / SPEED}s !important }`, 3);

  var handler = selector.handle.bind(selector);

  for (let name of ['mouseover', 'mousedown', 'mouseup']) {
    document.body.addEventListener(name, handler, false);
  }
});

function publish(func) {
  if (typeof exportFunction == 'function') {
    return exportFunction(func, unsafeWindow);
  }
  
  return func;
}

var __setTimeout = unsafeWindow.setTimeout.bind(unsafeWindow);

unsafeWindow.setTimeout = publish(function(callback, delay) {
  return __setTimeout(callback, Number(delay) / SPEED);
});