Quantcast

Jump to content


Photo

Script noob here trying to edit


  • Please log in to reply
2 replies to this topic

#1 Dont

Dont
  • 257 posts


Users Awards

Posted 25 January 2016 - 06:49 PM

Im using wasers OCR haggling script, but i'm super sick of it clicking the pet for me. Basically instead of doing it efficiently it lags and wont let me do it, by the time the script does it I might as well have just haggled mysellf.

 

 

 

 

 

// ==UserScript==
    // @name          Neopets Auto Haggle
    // @namespace     http://www.neofriends.net/
    // @description   Auto haggle in main shops
    // @include       http://neopets.com/haggle.phtml*
    // @include       http://www.neopets.com/haggle.phtml*
    // @include       www.neopets.com/haggle.phtml*
    // @include       neopets.com/haggle.phtml*
    // ==/UserScript==

    function run_cap()
    {
        if (document.location.href.match('haggle.phtml') && (document.body.innerHTML.indexOf("captcha_show.phtml") > -1))
        {
            if(document.body.innerHTML.indexOf("I wont take less than ") > -1)
            {
                start_pos = document.body.innerHTML.indexOf("I wont take less than ") + 22;
                end_pos = document.body.innerHTML.indexOf(" Neopoints for it");
                raw_price = document.body.innerHTML.substr(start_pos,end_pos-start_pos);
                raw_price = raw_price.replace(",","");

                document.body.innerHTML = document.body.innerHTML.replace("value=\"0\"","value=\""+haggle_price(raw_price)+"\"");
            }

            if(document.body.innerHTML.indexOf("I want at least ") > -1)
            {
                start_pos = document.body.innerHTML.indexOf("I want at least ") + 16;
                end_pos = document.body.innerHTML.indexOf(" Neopoints for this great item");
                raw_price = document.body.innerHTML.substr(start_pos,end_pos-start_pos);
                raw_price = raw_price.replace(",","");

                document.body.innerHTML = document.body.innerHTML.replace("value=\"0\"","value=\""+haggle_price(raw_price)+"\"");
            }

            allForms = document.evaluate("//form[@name='haggleform']",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);

            for (var i = 0; i < allForms.snapshotLength; i++)
            {
                thisForm = allForms.snapshotItem(i);

                allImgs = document.evaluate("//input[@type='image']",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);

                for (var i = 0; i < allImgs.snapshotLength; i++)
                {
                    var image = allImgs.snapshotItem(i);

                    if(image)
                    {
                        var newImg = document.createElement("img");
                        newImg.src = image.src;

                        var canvas = unsafeWindow.document.createElement("canvas");
                        canvas.width = newImg.width;
                        canvas.height = newImg.height;

                        canvas.getContext("2d").drawImage(newImg, 0, 0);

                        var image_data = canvas.getContext("2d").getImageData(0, 0, newImg.width, newImg.height);

                        var lowy = 999;
                        var lowx = 999;
                        var low = 999;

                        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;

                                var avg = Math.floor((image_data.data[i]+image_data.data[i+1]+image_data.data[i+2])/3);

                                if (avg < low)
                                {
                                    low = avg;
                                    lowx = x;
                                    lowy = y;
                                }
                            }
                        }

                        var newInput = document.createElement("input");
                        newInput.type="hidden";
                        newInput.name="x";
                        newInput.value=lowx;
                        thisForm.appendChild(newInput);

                        var newInput = document.createElement("input");
                        newInput.type="hidden";
                        newInput.name="y";
                        newInput.value=lowy;
                        thisForm.appendChild(newInput);

                        thisForm.submit();
                    }else{
                        alert("Image error");
                    }
                }
            }
        }
    }

    function haggle_price(raw_price)
    {
        var iVal = new Array(2);

        iVal[0] = raw_price.substr(0,1);
        iVal[1] = raw_price.substr(1,1);

        var x = 0;
        var end_price = "";

        for(x=0; x<raw_price.length; x++)
        {
            end_price += iVal[(x%2)];
        }

        return end_price;
    }

    window.addEventListener('load', run_cap, false);

 

 

 


What the hell can I do to this to change that?



#2 Nano

Nano
  • a delicious kiwi

  • 325 posts


Users Awards

Posted 25 January 2016 - 08:34 PM

http://www.neocodex....o-smart-haggle/



#3 Dont

Dont
  • 257 posts


Users Awards

Posted 25 January 2016 - 10:47 PM

Hmm, i'll test it out on firefox.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users