Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use-strict';
- (function(){
- var SNATCHER = function($){
- console.log('snatching');
- var attorneyID;
- var captchaImg = $('img[alt="jcaptcha image"]');
- var captchaSrc = captchaImg.prop('src');
- var base64img;
- var currentID = $.get( "http://docket.theexpertinstitute.com/captcha/nybar_get_id.php");
- // if on detail page
- var detail_check= $('strong').filter(function(){ return $(this).text() === "Attorney Detail"});
- if(detail_check.length > 0){
- currentID.done(function(remoteID){
- if(getUrlVars()["attorneyId"] == remoteID ){
- save_result.done(location.reload(true));
- } else {
- window.location.replace("http://iapps.courts.state.ny.us/attorney/AttorneyDetails?attorneyId="+remoteID);
- }
- })
- var info_table = $('body > table > tbody > tr:nth-child(2) > td:nth-child(2) > table').html();
- // Save result
- var save_result =$.ajax({
- type: "POST",
- url: "http://docket.theexpertinstitute.com/captcha/save_result.php",
- data: {
- ID: getUrlVars()["attorneyId"],
- table: info_table
- }
- });
- }
- // if on 500 error page
- var bad_id_check = $('h1').filter(function(){ return $(this).text() === "HTTP Status 500 - "});
- if(bad_id_check.length){
- var bad_result =$.ajax({
- type: "POST",
- url: "http://docket.theexpertinstitute.com/captcha/save_result.php",
- data: {
- ID: getUrlVars()["attorneyId"],
- table: ""
- }
- });
- bad_result.done(function(){
- currentID.done(function(remoteID){
- window.location.replace("http://iapps.courts.state.ny.us/attorney/AttorneyDetails?attorneyId="+remoteID);
- })
- })
- }
- (failed_attempt_check = function(){
- if (window.location == "http://iapps.courts.state.ny.us/attorney/fail.html"){
- var cookies = Cookies.get();
- $.each(cookies, function(key, value) {
- Cookies.remove(key, { path: '' });
- });
- window.location.replace("http://iapps.courts.state.ny.us/attorney/AttorneyDetails?attorneyId="+currentID);
- }
- })();
- /* Get Url value */
- function getUrlVars()
- {
- var vars = [], hash;
- var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
- for(var i = 0; i < hashes.length; i++)
- {
- hash = hashes[i].split('=');
- vars.push(hash[0]);
- vars[hash[0]] = hash[1];
- }
- return vars;
- }
- /* Convert image to base64 */
- function getBase64FromImageUrl(url) {
- var img = new Image();
- img.crossOrigin = "Anonymous";
- img.setAttribute('crossOrigin', 'anonymous');
- img.src = url;
- img.onload = function () {
- console.log("converting");
- var canvas = document.createElement("canvas");
- canvas.width =this.width;
- canvas.height =this.height;
- var ctx = canvas.getContext("2d");
- ctx.drawImage(this, 0, 0);
- var dataURL = canvas.toDataURL("image/jpg");
- //alert(dataURL.replace(/^data:image\/(png|jpg);base64,/, ""));
- dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
- base64img = dataURL;
- //console.log(base64img);
- };
- }
- //captcha page
- if(captchaImg.length){ //if on a captcha page
- getBase64FromImageUrl(captchaSrc); // convert image function
- setTimeout(function() { // wait for image (base64img) to be built;
- var stripped_base64img = base64img.replace("data:image/png;base64,", "base64:");
- var decode_image =$.ajax({
- type: "POST",
- headers: {
- Accept : "application/json"
- },
- url: "http://api.dbcapi.me/api/captcha",
- data: {
- username: "test_tasa",
- password: "testing1234",
- captchafile :stripped_base64img
- }
- });
- decode_image
- .done(function(response){
- console.log('captcha decoding done:',response);
- if(response.text !== ""){
- submitCaptcha(response.text);
- } else {
- reportFailedCaptcha(response.captcha);
- }
- }).fail(function(error) {
- console.log( error );
- });
- }, 1000);
- }
- /*Submit captcha */
- function submitCaptcha(captcha){
- $('#jcaptcha_answer').val(captcha);
- $('#jcaptcha_form').submit();
- }
- /* handle failed captcha */
- function reportFailedCaptcha(captchaID){
- var confirmCaptcha = function(){
- return $.ajax({
- type: "GET",
- headers: {
- Accept : "application/json"
- },
- url: "http://api.dbcapi.me/api/captcha/"+captchaID,
- success: function(response){
- if(response.text !==""){
- submitCaptcha(response.text);
- } else {
- console.log('retrying...');
- confirmCaptcha();
- }
- }
- });
- }
- setTimeout(function(){
- // confirmCaptcha(function(response){
- // console.log('captcha confirmed with text:',response);
- // });
- confirmCaptcha();
- },5000);
- }
- };//end snatcher
- var timer = function() {
- if (window.$) {
- SNATCHER(window.$);
- window.clearTimeout(timer);
- } else {
- window.setTimeout(timer, 100);
- }
- };
- timer();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement