bux.gs and b-u-x.net autoclicker (with timer killer)

By greyg00 Last update Mar 1, 2009 — Installed 7,862 times.

Add Syntax Highlighting (this will take a few seconds, probably freezing your browser while it works)

// ==UserScript==
// @name           bux.gs and b-u-x.net autoclicker
// @description    I think this is the only autoclicker available for bux.gs and b-u-x.net. It's fully Working and includes a javascript captcha reader
// @version        1
// @include        *bux.gs/viewads*
// @include        *b-u-x.net/viewads.php*
// ==/UserScript==


var links = document.evaluate('//a[contains(@href,"adclick.php?ID=") and text()]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);


var div = document.createElement('div');
div.setAttribute('id','BC_surfAd');
div.setAttribute('style','display:none;visibility:hidden;');
div.innerHTML = '';
document.body.appendChild(div);


//for(var x=0; x<links.snapshotLength; x++)
//    GM_log(links.snapshotItem(x).href)


start(0);




function start(now){

    if(now >= links.snapshotLength || links.snapshotItem(now).textContent.match(/reset/i)){
        setTimeout(function()
        {
            window.location.reload();
        },240000);
        return;
    }


    div.innerHTML = '';

    GM_xmlhttpRequest({
        'url':links.snapshotItem(now).href,
        'method':('GET'),
        'headers':{
            'Referer':window.location.href,
            'Content-Type':('application/xml')
        },
        'onload':function(responseDetails)
        {

            var fetchedHTML = responseDetails.responseText;
            if(!/<body[^>]*>/i.test(fetchedHTML))
                fetchedHTML = '<body>'+fetchedHTML;
            if(!/<\/body>/i.test(fetchedHTML))
                fetchedHTML += '</body>';
            fetchedHTML = fetchedHTML.split(/<body[^>]*>([\s\S]*)<\/body>/i)[1];

            div.innerHTML = fetchedHTML;

            setTimeout(function()
            {
                proceed(now)
            },1000);

        }
    });
    return;
}


function proceed(now, secondCycle){

    var toClickParameters = div.innerHTML.match(/success.location.href="finished.php\?ad=(\d+)&code=(\w+)";/);
    var toClick = 'http://'+window.location.hostname+'/finished.php?ad='+toClickParameters[1]+'&code='+toClickParameters[2];

    var images = div.getElementsByTagName('img');

    for (var x in images)
        if(images[x].src.match(/php\?width=40/i))
            get_code(images[x]);


    GM_xmlhttpRequest({
        'url':toClick,
        'method':('GET'),
        'headers':{
            'Referer':links.snapshotItem(now).href,
            'Content-Type':('application/xml')
        },
        'onload':function(responseDetails)
        {
            var click = responseDetails.responseText.match(/<b>(\w+)<\/b>/)[1];
            GM_log('response:'+click);

            for(var x in letters){
                if(letters[x] == click){
                    callBack(++x,toClick, now);
                    return;
                }
                letters[x] = letters[x].replace('v','y');           //Fix common mistakes in reading captchas
                letters[x] = letters[x].replace('b','h');           //
            }                                                       //
            click = click.replace('v','y');                         //
            click = click.replace('b','h');                         //

            if(!secondCycle)
                proceed(now, true);
        }
    });

}

function callBack(x, toClick, now)
{
    GM_xmlhttpRequest({
        'url':toClick+'&cap='+x,
        'method':('GET'),
        'headers':{
            'Referer':links.snapshotItem(now).href,
            'Content-Type':('application/xml')
        },
        'onload': function(responseDetails){
            GM_log(responseDetails.responseText);
            if(responseDetails.responseText.match('ok.gif'))
                links.snapshotItem(now).parentNode.innerHTML = '<font style="font-weight: normal;" color="#660000"><strike>'+links.snapshotItem(now).innerHTML+'</strike></font>';
            start(now + 1);
            return;
        }
    });
    return;
}





////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////          THE CODE AFTER THIS COMMENT IS ENTIRELY               ////
////                  FOR CAPTCHA READING                           ////
////                                                                ////
////          AND IS ISPIRED BY Shn AND HIS SCRIPT                  ////
////  (MY CODE IS MUCH SIMPLER SINCE HE IS 100 TIMES                ////
////                BETTER THAN ME AND I DON'T USE NEURAL NET)      ////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////



var receptors = [
[1, 0], [3, 0], [6, 0], [9, 0], [12, 0], [15, 0], [18, 0], [20, 0],
[0, 1], [10, 1], [11, 1], [21, 1],
[1, 2], [5, 2], [7, 2], [14, 2], [16, 2], [20, 2],
[2, 3], [4, 3], [8, 3], [10, 3], [11, 3], [13, 3], [17, 3], [19, 3],
[0, 4], [5, 4], [16, 4], [21, 4],
[1, 5], [3, 5], [6, 5], [9, 5], [12, 5], [15, 5], [18, 5], [20, 5],
[0, 6], [5, 6], [16, 6], [21, 6],
[2, 7], [4, 7], [8, 7], [10, 7], [11, 7], [13, 7], [17, 7], [19, 7],
[1, 8], [5, 8], [7, 8], [14, 8], [16, 8], [20, 8],
[0, 9], [10, 9], [11, 9], [21, 9],
[1, 10], [3, 10], [6, 10], [9, 10], [12, 10], [15, 10], [18, 10], [20, 10]
];

var preWeights = [
[0,0,1,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,0,0,1,0,0,0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,1,0,1,0,1,0,0,1,1,0,0,1,1,'2','0'],
[0,1,1,0,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,0,1,1,1,0,1,1,0,0,1,1,0,0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0,0,1,1,'2','1'],
[0,0,1,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,0,1,1,1,0,1,1,0,0,1,1,0,0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,1,0,1,0,1,0,0,1,1,0,0,1,1,'2','2'],
[0,0,1,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,0,0,1,1,0,0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0,0,1,1,'2','3'],
[0,0,1,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0,0,1,1,'3','4'],
[0,0,1,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,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1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,1,0,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,'z','126'],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,0,0,1,1,1,0,0,1,1,0,1,1,1,0,1,1,1,0,1,0,1,0,0,1,0,0,1,0,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,'z','127'],
[1,0,0,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,0,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0,1,1,0,0,1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,'z','128'],
];


var stat = new Array();
var letters = new Array();


function get_code(image)
{
    var num = letters.length;
    letters[num] = '';

    var canvas = unsafeWindow.document.createElement("canvas");
    canvas.width = image.width;
    canvas.height = image.height;
    canvas.getContext("2d").drawImage(image, 0, 0);

    var cropped_canvas = unsafeWindow.document.createElement("canvas");
    cropped_canvas.width = 15;
    cropped_canvas.height = 23;

    var w2 = image.width/2;

    var image_data = [canvas.getContext("2d").getImageData(0, 0, w2, image.height),
    canvas.getContext("2d").getImageData(w2, 0, w2, image.height)];

    cleaning(image_data[0]);
    cleaning(image_data[1]);


    for(var i in image_data)
    {
        canvas.getContext("2d").putImageData(image_data[i], 0, 0, 0, 0, image_data[i].width, image_data[i].height);

        var edges = find_edges(image_data[i]);

        cropped_canvas.getContext("2d").drawImage(canvas, edges[0], edges[1], edges[2], edges[3], 0, 0, edges[2], edges[3]);

        image_data[i] = cropped_canvas.getContext("2d").getImageData(0, 0, cropped_canvas.width-4, cropped_canvas.height-1);

    }


    for(var m in image_data){
        var states = [];
        var x, y;

        for (var i in receptors)
        {
            x = receptors[i][0];
            y = receptors[i][1];
            i = x*4+y*4*image_data[m].width;

            if (image_data[m].data[i] == 255)
            {
                states.push(0);
            }
            else
            {
                states.push(1);
            }
        }

        stat.push("\n["+states+", '"+num+"', '']");
        letters[num] += match(states)
    }
    return;
}



function cleaning(image_data)
{

    //Cleaning
    for (var x = 0; x < image_data.width; x++){
        for (var y = 0; y < image_data.height; y++){
            var i = x*4+y*4*image_data.width;

            if ((Math.abs(image_data.data[i] - image_data.data[i+1]) < 130) &&
                (Math.abs(image_data.data[i]-image_data.data[i+2]) < 130) &&
                (Math.abs(image_data.data[i+1]-image_data.data[i+2]) < 130) &&
                (image_data.data[i+2] > 50))
                {
                image_data.data[i] = 255;
                image_data.data[i+1] = 255;
                image_data.data[i+2] = 255;
                image_data.data[i+3] = 255;
            }
            else{
                image_data.data[i] = 0;
                image_data.data[i+1] = 0;
                image_data.data[i+2] = 0;
                image_data.data[i+3] = 255;
            }
        }
    }

    // NoisePixels
    for (var x = 0; x < image_data.width; x++){
        for (var y = 1; y < image_data.height-1; y++){

            var i = x*4+y*4*image_data.width;
            var above = x*4+(y-1)*4*image_data.width;
            var below = x*4+(y+1)*4*image_data.width;

            if (image_data.data[i] == 255 && image_data.data[above] == 0 && image_data.data[below] == 0)
            {
                image_data.data[i] = 0;
                image_data.data[i+1] = 0;
                image_data.data[i+2] = 0;
            }
        }
    }
    return image_data;
}


function find_edges(image_data)
{
    var minX = image_data.width;
    var minY=image_data.height;
    var maxX=0;
    var maxY=0;

    for (var x = 0; x < image_data.width; x++)
    {
        for (var y = 0; y < image_data.height; y++)
        {
            var i = x*4+y*4*image_data.width;

            if (image_data.data[i] == 0){
                if(x<minX)
                    minX = x;
                if(y<minY)
                    minY = y;
                if(x > maxX)
                    maxX = x;
                if(y > maxY)
                    maxY = y;
            }
        }
    }

    return [minX, minY, maxX-minX, maxY-minY]
}


function match(states)
{
    var err;
    var best = 10000;
    var letter = '';
    for(var x in preWeights){
        err = 0;
        for (var y=0; y<68; y++)
            if(states[y] != preWeights[x][y])
                err++;
        if (err < best){
            best = err;
            bestIndex = x;
            letter = preWeights[x][68];
        }
    }
    if(letter == '')
        letter = 'error'

    return letter;
}