Advertisement
Guest User

Untitled

a guest
Aug 12th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use-strict';
  2. (function(){
  3.     var SNATCHER = function($){
  4.             console.log('snatching');
  5.             var attorneyID;
  6.             var captchaImg = $('img[alt="jcaptcha image"]');
  7.             var captchaSrc = captchaImg.prop('src');
  8.             var base64img;
  9.          
  10.  
  11.             var currentID = $.get( "http://docket.theexpertinstitute.com/captcha/nybar_get_id.php");
  12.  
  13.  
  14.             // if on detail page
  15.             var detail_check= $('strong').filter(function(){ return $(this).text() === "Attorney Detail"});
  16.             if(detail_check.length > 0){
  17.  
  18.                
  19.                 currentID.done(function(remoteID){
  20.                     if(getUrlVars()["attorneyId"] == remoteID ){
  21.                         save_result.done(location.reload(true));
  22.                     } else {
  23.                         window.location.replace("http://iapps.courts.state.ny.us/attorney/AttorneyDetails?attorneyId="+remoteID);
  24.                     }
  25.                 })
  26.  
  27.  
  28.                 var info_table = $('body > table > tbody > tr:nth-child(2) > td:nth-child(2) > table').html();
  29.  
  30.  
  31.                 // Save result
  32.                 var save_result =$.ajax({
  33.                     type: "POST",
  34.                     url: "http://docket.theexpertinstitute.com/captcha/save_result.php",
  35.                     data: {
  36.                         ID: getUrlVars()["attorneyId"],
  37.                         table: info_table
  38.                     }
  39.                 });
  40.                
  41.             }
  42.             // if on 500 error page  
  43.             var bad_id_check = $('h1').filter(function(){ return  $(this).text() === "HTTP Status 500 - "});
  44.             if(bad_id_check.length){        
  45.                 var bad_result =$.ajax({
  46.                     type: "POST",
  47.                     url: "http://docket.theexpertinstitute.com/captcha/save_result.php",
  48.                     data: {
  49.                         ID: getUrlVars()["attorneyId"],
  50.                         table: ""
  51.                     }
  52.                 });
  53.                 bad_result.done(function(){
  54.                     currentID.done(function(remoteID){
  55.  
  56.                             window.location.replace("http://iapps.courts.state.ny.us/attorney/AttorneyDetails?attorneyId="+remoteID);
  57.                     })
  58.                 })
  59.  
  60.             }
  61.              (failed_attempt_check = function(){
  62.                 if (window.location == "http://iapps.courts.state.ny.us/attorney/fail.html"){                    
  63.                     var cookies = Cookies.get();
  64.                     $.each(cookies, function(key, value) {
  65.                         Cookies.remove(key, { path: '' });    
  66.                     });
  67.                     window.location.replace("http://iapps.courts.state.ny.us/attorney/AttorneyDetails?attorneyId="+currentID);
  68.                 }
  69.             })();
  70.  
  71.             /* Get Url value */
  72.             function getUrlVars()
  73.             {
  74.                 var vars = [], hash;
  75.                 var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  76.                 for(var i = 0; i < hashes.length; i++)
  77.                 {
  78.                     hash = hashes[i].split('=');
  79.                     vars.push(hash[0]);
  80.                     vars[hash[0]] = hash[1];
  81.                 }
  82.                 return vars;
  83.             }
  84.  
  85.             /* Convert image to base64 */      
  86.             function getBase64FromImageUrl(url) {
  87.                 var img = new Image();
  88.                   img.crossOrigin = "Anonymous";
  89.                
  90.                     img.setAttribute('crossOrigin', 'anonymous');
  91.                     img.src = url;
  92.                    
  93.                     img.onload = function () {
  94.                       console.log("converting");
  95.                      
  96.                     var canvas = document.createElement("canvas");
  97.                     canvas.width =this.width;
  98.                     canvas.height =this.height;
  99.  
  100.                     var ctx = canvas.getContext("2d");
  101.                     ctx.drawImage(this, 0, 0);
  102.  
  103.                     var dataURL = canvas.toDataURL("image/jpg");
  104.  
  105.                     //alert(dataURL.replace(/^data:image\/(png|jpg);base64,/, ""));
  106.                     dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
  107.                  
  108.                     base64img = dataURL;
  109.                       //console.log(base64img);
  110.                   };
  111.             }
  112.              
  113.              //captcha page
  114.              if(captchaImg.length){ //if on a captcha page
  115.                 getBase64FromImageUrl(captchaSrc); // convert image function  
  116.                
  117.                 setTimeout(function() { // wait for image (base64img) to be built;
  118.  
  119.  
  120.                     var stripped_base64img = base64img.replace("data:image/png;base64,", "base64:");
  121.  
  122.                     var decode_image =$.ajax({
  123.                                 type: "POST",
  124.                                 headers: {
  125.                                      Accept : "application/json"                            
  126.                                  },
  127.                                 url: "http://api.dbcapi.me/api/captcha",
  128.                                 data: {
  129.                                     username: "test_tasa",
  130.                                     password: "testing1234",
  131.                                     captchafile :stripped_base64img
  132.                                 }
  133.                             });
  134.  
  135.                     decode_image
  136.                         .done(function(response){
  137.                             console.log('captcha decoding done:',response);
  138.                             if(response.text !== ""){
  139.                                 submitCaptcha(response.text);    
  140.                             } else {
  141.                                 reportFailedCaptcha(response.captcha);
  142.                             }
  143.                            
  144.                     }).fail(function(error) {
  145.                         console.log( error );
  146.                       });
  147.                 }, 1000);
  148.                
  149.              }
  150.              
  151.              /*Submit captcha */
  152.              function submitCaptcha(captcha){
  153.                 $('#jcaptcha_answer').val(captcha);
  154.                 $('#jcaptcha_form').submit();
  155.              }
  156.  
  157.              /* handle failed captcha */
  158.              function reportFailedCaptcha(captchaID){
  159.                 var confirmCaptcha = function(){
  160.                   return  $.ajax({
  161.                         type: "GET",
  162.                         headers: {
  163.                              Accept : "application/json"                            
  164.                          },
  165.                         url: "http://api.dbcapi.me/api/captcha/"+captchaID,
  166.                         success: function(response){
  167.                             if(response.text !==""){
  168.                                 submitCaptcha(response.text);
  169.                             } else {
  170.                                 console.log('retrying...');
  171.                                 confirmCaptcha();
  172.                             }
  173.                         }
  174.                     });
  175.                 }
  176.                 setTimeout(function(){
  177.                     // confirmCaptcha(function(response){
  178.                     //     console.log('captcha confirmed with text:',response);
  179.                        
  180.                     // });
  181.                     confirmCaptcha();
  182.                 },5000);
  183.              }
  184.  
  185.  
  186.     };//end snatcher
  187.  
  188.      var timer = function() {
  189.          if (window.$) {
  190.            SNATCHER(window.$);
  191.            window.clearTimeout(timer);
  192.          } else {
  193.            window.setTimeout(timer, 100);
  194.          }
  195.        };
  196.        timer();
  197. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement