GM Autohaggler no longer working?

Discussion in 'Neopets Guides' started by lottgre1, Mar 5, 2013.

  1. lottgre1

    lottgre1 Level I

    Joined:
    Jan 30, 2013
    Messages:
    58
    Likes Received:
    0
    The Greasemonkey autohaggler that I've been using for over a month now has stopped working, I think it might have to do with the URL on the page but im not sure. Any help would be appreciated :)

    **EDIT

    I fixed it, i had to uninstall and reinstall Greasemonkey from my browser...the neopet shop pages wouldn't even load the whole way when it was broken
     
  2. Junior

    Junior Administrator
    Staff Member

    Joined:
    Nov 8, 2009
    Messages:
    3,350
    Likes Received:
    169
    Location:
    I come from a land down under! (Maaaate!)
    Post the GM Script? Or if its one that you paid for, PM it to me?

    And can you explain your theory more? Why would it have something to do with the URL?
     
  3. lottgre1

    lottgre1 Level I

    Joined:
    Jan 30, 2013
    Messages:
    58
    Likes Received:
    0
    // ==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+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);
     
  4. lottgre1

    lottgre1 Level I

    Joined:
    Jan 30, 2013
    Messages:
    58
    Likes Received:
    0
  5. lakerzfan27

    lakerzfan27 Newbie

    Joined:
    Apr 5, 2013
    Messages:
    13
    Likes Received:
    0
    it is working fine for me if that helps
     
  6. harrytools

    harrytools Level I

    Joined:
    Mar 22, 2013
    Messages:
    58
    Likes Received:
    1
    Try re installing the script i would say. Might solve the problem.
     
  7. redthunder

    redthunder Level I

    Joined:
    Jun 24, 2010
    Messages:
    40
    Likes Received:
    0
    I know for me I had to change some of the code in it