tesseractJSautofill

auto fill captcha text by tesseract.js

Bu script direkt olarak kurulamaz. Başka scriptler için bir kütüphanedir ve meta yönergeleri içerir // @require https://update.greatest.deepsurf.us/scripts/489988/1347251/tesseractJSautofill.js

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name          tesseractJSautofill
// @namespace     https://greatest.deepsurf.us
// @version       0.0.2
// @description   auto fill captcha text by tesseract.js
// @match         *://*/*
// @grant         none
// ==/UserScript==

// @require     https://unpkg.com/tesseract.js/dist/tesseract.min.js
const init_worker = async (language) => {
  const lang = language;
  const server = 'https://unpkg.com';
  const langPath = `${server}/@tesseract.js-data/${lang}/4.0.0_best_int`;
  const worker = await Tesseract.createWorker(lang, 1, {
    corePath: `${server}/tesseract.js-core`,
    workerPath: `${server}/tesseract.js/dist/worker.min.js`,
    langPath: langPath,
    logger: () => {
      console.debug('init worker', `${server}/tesseract.js/dist/worker.min.js`);
    },
  });

  return worker;
};

const img_src_to_base64 = (img) => {
  // https://stackoverflow.com/a/22172860
  let canvas = document.createElement('canvas');
  // https://developer.mozilla.org/docs/Web/API/HTMLImageElement/naturalWidth
  canvas.width = img.naturalWidth;
  // https://developer.mozilla.org/docs/Web/API/HTMLImageElement/naturalHeight
  canvas.height = img.naturalHeight;
  let ctx = canvas.getContext('2d');
  ctx.drawImage(img, 0, 0);
  return ctx.canvas.toDataURL('image/png');
};

const get_captcha_text = async (imgTag, worker) => {
  let node = document.querySelector(imgTag);
  const ret = await worker.recognize(img_src_to_base64(node));
  // console.debug(ret);
  const ret_text = ret.data.text;
  // console.debug(ret_text);
  return ret_text;
};

const auto_fill_captcha_text = async (
  imgTag,
  valueTag,
  loginTag = '',
  delayTime = 3000,
  failFunction = 'reload',
  language = 'eng',
  textLength = 4,
  textType = '\\d'
) => {
  const worker = await init_worker(language);

  let captcha_text = await get_captcha_text(imgTag, worker);
  let optimised_text = captcha_text.trim().split(' ').join('');

  const regex = RegExp(`${textType}{${textLength}}`);

  console.debug(regex, optimised_text, regex.test(optimised_text));

  if (optimised_text.length === textLength && regex.test(optimised_text)) {
    document.querySelector(valueTag).value = optimised_text;
    console.debug('reloadCounter', sessionStorage.getItem('reloadCounter'));
    sessionStorage.setItem('reloadCounter', '0');
    if (loginTag.length > 0) {
      document.querySelector(loginTag).click();
    }
  } else {
    document.querySelector(valueTag).value = '';
    sessionStorage.setItem(
      'reloadCounter',
      `${Number(sessionStorage.getItem('reloadCounter')) + 1}`
    );
    console.debug('reloadCounter', sessionStorage.getItem('reloadCounter'));

    if (failFunction === 'null') return;
    setTimeout(() => {
      if (failFunction === 'reload') {
        location.reload();
      }
    }, delayTime);
  }
};