Auto haggle

Discussion in 'Code Snippets and Tutorials' started by II_warlord_II, Oct 11, 2008.

  1. II_warlord_II

    II_warlord_II Level III

    Joined:
    Aug 13, 2008
    Messages:
    532
    Likes Received:
    31
    this is a java scripts (.js)
    i'm planning to make .xpi
    extension for firefox
    to autohaggle
    right now, i'm having problem with MATHS~!
    lol...the extension work, but it haggled at higher price, you see
    if the item cost 1200, it will 1292 or something like that.
    Is there a way for me, to use the %feature, like 95% of the X (shop keeper's offer)?

    // ==UserScript==
    // @name AutoHaggle
    // @description Auto Haggles On Neopets
    // @include http://*.neopets.*/haggle.phtml*
    // @include http://neopets.*/haggle.phtml*
    // ==/UserScript==

    function GetBetween(zStr, zStart, zEnd){
    var zStr = zStr; var zStart = zStart; var zEnd = zEnd;
    var z1 = zStr.indexOf(zStart); var z2 = zStr.indexOf(zEnd, z1);
    if(z2 > z1 && z1 > -1){
    return zStr.substring(z1 + zStart.length,z2);
    }else{
    return "";
    }
    }

    function SmartHaggle(priceth){
    var pricelength = priceth.length;
    var returnval = priceth.charAt(0) + priceth.charAt(1);
    for (i = 2; i < pricelength; i++)
    {
    returnval = returnval + priceth.charAt( Math.round(Math.random()) );
    }
    return returnval;
    }

    var URL = window.location.href; URL = URL.toLowerCase();
    if(URL.indexOf("neopets.") > 0){
    var DOMAIN = "neopets";
    }

    if(DOMAIN == "neopets"){
    var strHTML = document.body.innerHTML;
    if(strHTML.indexOf("I want at least ") > 1){
    var haggle = GetBetween(strHTML,"<b>The Shopkeeper says 'I want at least "," Neopoints for this great item.'");
    document.getElementsByName("current_offer")[0].value = SmartHaggle(haggle.replace(",",""));
    }else if(strHTML.indexOf("I wont take less than ") > 1){
    var haggle = GetBetween(strHTML,"<b>The Shopkeeper says 'I wont take less than "," Neopoints for it.'");
    document.getElementsByName("current_offer")[0].value = SmartHaggle(haggle.replace(",",""));
    }
     
  2. SoC

    SoC Moderator
    Staff Member

    Joined:
    Jan 24, 2007
    Messages:
    4,551
    Likes Received:
    105
    Location:
    Maaaaaaanchester!
    Don't make legit RSing even harder.

    But, use the first two numbers repeated, (NO idea how to code but ill give some examples)
    Stocks 5000 = Haggles 5050
    Stocks 10000 = Haggles 10101
    Stocks 154323 = Haggles 151515

    ALSO looks a MILLION times more legit,
    as thats what us legit people use :)
     
  3. II_warlord_II

    II_warlord_II Level III

    Joined:
    Aug 13, 2008
    Messages:
    532
    Likes Received:
    31
    that's what i'm trying to do.
    i try to use the var .charAt(0) and var .charAt(1)
     
  4. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    Code (Text):
    1. function autoHaggle(original_price)
    2. {
    3.     var new_price = '';
    4.     var alternate = false;
    5.     while (new_price.length < original_price.toString().length)
    6.     {
    7.         new_price+= original_price.toString().charAt(alternate ? 1 : 0);
    8.     }
    9.     return new_price;
    10. }
    Exactly what SoC said. :)
    If you have any question just ask ;)
     
  5. II_warlord_II

    II_warlord_II Level III

    Joined:
    Aug 13, 2008
    Messages:
    532
    Likes Received:
    31
    thanks alot...
    i managed to make it.
    hehe...
    now i'm just have to test it out...
    its not greasemonkey script i'm making.
    its FF extension...
    i believe it would be faster in recognising the page and so on
     
  6. expon

    expon Administrator
    Staff Member

    Joined:
    Oct 30, 2006
    Messages:
    1,393
    Likes Received:
    56
    Location:
    UK
    I don't get how this works.. alternate is always false so isn't it always going to be the chartAt(0) ?
    :s maybe I'm just missing something obvious :lol:
     
  7. II_warlord_II

    II_warlord_II Level III

    Joined:
    Aug 13, 2008
    Messages:
    532
    Likes Received:
    31
    charAt(alternate ? 1 : 0);
    ? is use, so is 1 else 0
     
  8. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    Whoops, forgot a line. :p
    Code (Text):
    1. function autoHaggle(original_price)
    2. {
    3.     var new_price = '';
    4.     var alternate = false;
    5.     while (new_price.length < original_price.toString().length)
    6.     {
    7.         new_price+= original_price.toString().charAt(alternate ? 1 : 0);
    8.         alternate = !alternate;
    9.     }
    10.     return new_price;
    11. }
     
  9. expon

    expon Administrator
    Staff Member

    Joined:
    Oct 30, 2006
    Messages:
    1,393
    Likes Received:
    56
    Location:
    UK
    oh that's better :D
    I like your way of doing it :)
     
  10. II_warlord_II

    II_warlord_II Level III

    Joined:
    Aug 13, 2008
    Messages:
    532
    Likes Received:
    31
    i got, this firefox extension.
    which auto hanggle for you.
    it seem to work...
    should i contribute it to the site?
     
  11. Zer0

    Zer0 Level IV

    Joined:
    Mar 2, 2008
    Messages:
    3,037
    Likes Received:
    180
    Location:
    Home sweet home
    I don't think so, unless you get permission from the author. I think its technically copyrighted.
    So unless its explicitly released under the GPL or some other copyleft license, you shouldn't re-distribute it w/o permission.
     
  12. II_warlord_II

    II_warlord_II Level III

    Joined:
    Aug 13, 2008
    Messages:
    532
    Likes Received:
    31
    well, what i meant, was i made it myself, with a bunch of friends.
    i compressed as .xpi files
    so it can be install as firefox add-on
     
  13. Zer0

    Zer0 Level IV

    Joined:
    Mar 2, 2008
    Messages:
    3,037
    Likes Received:
    180
    Location:
    Home sweet home
    Oh, in that case, feel free to upload it. :)
     
  14. domini212

    domini212 Level III

    Joined:
    Jun 30, 2008
    Messages:
    454
    Likes Received:
    7
    Do you think this will be safe to use in the magic shop?
     
  15. II_warlord_II

    II_warlord_II Level III

    Joined:
    Aug 13, 2008
    Messages:
    532
    Likes Received:
    31
    im trying to get a 3 month sshell account to test it out now...
     
  16. domini212

    domini212 Level III

    Joined:
    Jun 30, 2008
    Messages:
    454
    Likes Received:
    7
    let me know how it goes. Would u like me to help. Can I import the above script onto greasmonkey to test?
     
  17. II_warlord_II

    II_warlord_II Level III

    Joined:
    Aug 13, 2008
    Messages:
    532
    Likes Received:
    31
    well, i changed a bit on the script.
    that's just a part of the calculation,
    using the first 2 number to haggle.

    1299 NPs, would haggle 1212 or 1222 or 1211
     
  18. domini212

    domini212 Level III

    Joined:
    Jun 30, 2008
    Messages:
    454
    Likes Received:
    7
    I tried to load the original script that you posted on here onto greasmonkey but it didnt work.. if you want you can message me the script to test for you. If not I hope your script makes it on to the download section soon. especially for the magic shop
     
  19. Heya_old

    Heya_old Level IV

    Joined:
    Mar 31, 2008
    Messages:
    928
    Likes Received:
    46
    heres the auto haggler i use :)
     
    Rhett and domini212 like this.