Quantcast

Jump to content


Photo

[Request] Converting a Tampermonkey Auto-Haggle Script for use on Spanish Neopets


  • Please log in to reply
6 replies to this topic

#1 Rhizome

Rhizome
  • 14 posts

Posted 19 July 2015 - 12:16 PM

Hello,

 

I'm trying to get this script to work on a Spanish translated neopets. I tried replacing the necessary english text for the two prompts with the spanish version, but that didn't work. Could anyone do this for me? (I know nothing about coding ): ) 

 

 


 

   // ==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);

Much appreciated!



#2 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 19 July 2015 - 12:26 PM

I'm not going to help fix my own code which was stolen from our programming section years ago.



#3 Rhizome

Rhizome
  • 14 posts

Posted 19 July 2015 - 12:31 PM

I had no part in that though, like I said I don't know jack about coding. Additionally, I literally have no idea what you're talking about I found this in one of the threads on this site (I've been lurking for a while).

 

I mean if you're not going to help, why bother responding? Don't want to come off as rude but...



#4 Grimley

Grimley
  • The greatest trick the Devil ever pulled was convincing the world he didn't exist

  • 3840 posts


Users Awards

Posted 19 July 2015 - 12:38 PM

I had no part in that though, like I said I don't know jack about coding. Additionally, I literally have no idea what you're talking about I found this in one of the threads on this site (I've been lurking for a while).

 

I mean if you're not going to help, why bother responding? Don't want to come off as rude but...

 

He's, ummm, a Programmer...and as such, he kinda doesn't want to modify it for someone who picked up HIS code to mess with for their own purposes. It's not unlike taking a painting or other piece of art and then deciding to "make it your own": the request wasn't a cool one to make. Now if you you had written it yourself and were seeking assistance, that's another story. ;)



#5 Rhizome

Rhizome
  • 14 posts

Posted 19 July 2015 - 12:42 PM

He's, ummm, a Programmer...and as such, he kinda doesn't want to modify it for someone who picked up HIS code to mess with for their own purposes. It's not unlike taking a painting or other piece of art and then deciding to "make it your own": the request wasn't a cool one to make. Now if you you had written it yourself and were seeking assistance, that's another story. ;)

I'm not sure I agree with this rationale... It's on this site, he's on this site, the code is for users to use.... It's not like this was illegal procured or anything. In your art analogy this is like going to a gallery, getting a free small copy of A (ONE) piece and going home and editing it. Obviously I'm not going around and saying its my own or giving it to others so there shouldn't be a problem..... I'd keep it in my personal care.

 

At no point do I say this is mine in fact I explicitly said I know nothing about coding. Wowsers, guys.

 

 

Edit for one grammar mistake...


Edited by Rhizome, 19 July 2015 - 12:47 PM.


#6 Nano

Nano
  • a delicious kiwi

  • 325 posts


Users Awards

Posted 19 July 2015 - 02:39 PM

I have got it working in Spanish. Will only post it if @Waser Lave gives the all clear though.

But I removed the captcha part. (Edited the copy I use)

 

 

Edit: Can't tag Waser. :(

 

Edit 2: Coded something from scratch.

 

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


Edited by Freestyle, 19 July 2015 - 04:23 PM.


#7 Rhizome

Rhizome
  • 14 posts

Posted 19 July 2015 - 06:56 PM

You da best!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users