DeathByCatpcha API Wrapper

API wrapper for using DeathByCaptcha's decaptcha service

Bu script direkt olarak kurulamaz. Başka scriptler için bir kütüphanedir ve meta yönergeleri içerir // @require https://update.greasyfork.org/scripts/9125/158918/DeathByCatpcha%20API%20Wrapper.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 yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

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.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

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!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

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

// ==UserScript==
// @name        DeathByCatpcha API Wrapper
// @grant       GM_xmlhttpRequest
// ==/UserScript==


function DeathByCaptcha (dbc_user, dbc_pass) {
  this.user = dbc_user;
  this.pass = dbc_pass;

  this.balance = function balance(callback) {
    var reqUrl = 'http://api.dbcapi.me/api/user';
    var formData = new FormData();
    formData.append('username', this.user);
    formData.append('password', this.pass);

    GM_xmlhttpRequest({
      method: 'POST',
      headers: {
        'Accept': 'application/json'
      },
      data: formData,
      url: reqUrl,
      onload: function (response) {
        if (response.status === 200) {
          var balance = JSON.parse(response.responseText).balance;
          callback(null, balance);
        } else {
          callback(new Error(response.status), null);
        }
      }
    });
  };

  this.report = function report(capId, callback) {
    var reportUrl = 'http://api.dbcapi.me/api/captcha/' + capId + '/report';
    var formData = new FormData();
    formData.append('username', this.user);
    formData.append('password', this.pass);

    GM_xmlhttpRequest({
      method: 'POST',
      data: formData,
      url: reportUrl,
      onload: function (response) {
        if (response.status === 200) {
          console.log('DeathByCaptcha: captcha reported as incorrect');
          callback(null);
        } else {
          callback(new Error(response.status));
        }
      }
    });
  };

  this.solve = function solve(imgNode, callback) {

    //create base64 uri
    var canvas = document.createElement('CANVAS');
    var ctx = canvas.getContext('2d');
    canvas.height = imgNode.height;
    canvas.width = imgNode.width;
    ctx.drawImage(img, 0, 0);
    var imgB64 = canvas.toDataURL().replace(/data:image\/(png|jpg);base64,/, 'base64:');

    //create form to submit to DBC
    var formData = new FormData();
    formData.append('username', this.user);
    formData.append('password', this.pass);
    formData.append('captchafile', imgB64);

    //upload captcha to DBC
    GM_xmlhttpRequest({
      method: 'POST',
      data: formData,
      url: 'http://api.dbcapi.me/api/captcha',
      onload: function (response) {

        //return http errors
        switch (response.status) {
          case 403:
            console.error('DeathByCaptcha: 403 Forbidden - Invalid credentails or insufficient credits');
            callback(new Error(403));
            return;
          case 400:
            console.error('DeathByCaptcha: 300 Bad Request');
            callback(new Error(400));
            return;
          case 500:
            callback(new Error(500));
            console.error('DeathByCaptcha: 500 Internal Server Error');
            return;
          case 503:
            console.error('DeathByCaptcha: 503 Service Temporarily Unavailable');
            callback(new Error(503));
            return;
        }

        console.log('DeathByCaptcha: Uploaded captcha');
        console.log("DeathByCaptcha: URL - " + response.finalUrl);


        //check every 2 seconds if captcha is solved
        var pollTimer = setInterval(function () {
          GM_xmlhttpRequest({
            method: 'GET',
            headers: {
              'Accept': 'application/json'
            },
            url: capUrl,
            onload: function (response) {
              console.log('DeathByCaptcha: Checking for solved captcha.');

              if (response.status === 404) {
                clearInterval(pollTimer);
                console.log('DeathByCaptcha: Captcha ID Not Found.');
                callback(new Error(404));

              } else if (response.status === 200) {


                var solution = JSON.parse(response.responseText).text;
                var capId = JSON.parse(response.responseText).captcha;

                if (solution !== '') {
                  clearInterval(pollTimer);
                  console.log('DeathByCaptcha: Captcha solved');

                  callback(null, solution, capId);
                }
              }
            }
          });
        }, 2000);
      }
    });
  };
}