Quantcast

Jump to content


Photo

[UserScript] Neopets Auto Smart Haggle

neopets userscript smart haggle

  • This topic is locked This topic is locked
5 replies to this topic

#1 Nano

Nano
  • a delicious kiwi

  • 325 posts


Users Awards

Posted 19 July 2015 - 04:20 PM

User requested an old script to be converted to Spanish, made it work with all languages.

 

Only tested on Chrome.

 

Not sure if my Smart Haggle function works over 99,999 NP. Couldn't find an item to test it on.

 
// ==UserScript==
// @name         Neopets Auto Smart Haggle
// @namespace    http://www.neocodex.us/
// @version      0.1.2
// @description  Auto Smart Haggle for Neopets Main Shops.
// @author       Freestyle
// @include      *neopets.com/haggle.phtml*
// ==/UserScript==

//Found .repeat somewhere on google by Jacob Relkin.
String.prototype.repeat = function(times) {
   return (new Array(times + 1)).join(this);
};

function smart_haggle(price){
    return price.substring(0,2).repeat(price.length).substring(0,price.length);
}

if(document.getElementsByName("lang")[0].value === "en"){
    var wont = "I wont take less than ";
    var regwont = /I wont take less than (.*) Neopoints/;
    var want = "I want at least ";
    var regwant = /I want at least (.*) Neopoints/;
    var separator = ",";
}else if(document.getElementsByName("lang")[0].value === "nl"){
var wont = "Ik wil zeker niet minder dan ";
    var regwont = /Ik wil zeker niet minder dan  (.*) Neopunten/;
    var want = "Ik wil minstens ";
    var regwant = /Ik wil minstens  (.*) Neopunten/;
    var separator = ".";
}else if(document.getElementsByName("lang")[0].value === "pt"){
var wont = "Não aceito menos que ";
    var regwont = /Não aceito menos que (.*) Neopontos/;
    var want = "Quero, no mínimo, ";
    var regwant = /Quero, no mínimo, (.*) Neopontos/;
    var separator = ".";
}else if(document.getElementsByName("lang")[0].value === "de"){
var wont = "Ich nehme nicht weniger als ";
    var regwont = /Ich nehme nicht weniger als (.*) Neopunkte/;
    var want = "Ich möchte mindestens ";
    var regwant = /Ich möchte mindestens (.*) Neopunkte/;
    var separator = ".";
}else if(document.getElementsByName("lang")[0].value === "fr"){
var wont = "Je ne descendrai pas en-dessous de ";
    var regwont = /Je ne descendrai pas en-dessous de  (.*) Neopoints/;
    var want = "Je veux au moins ";
    var regwant = /Je veux au moins  (.*) Neopoints/;
    var separator = ".";
}else if(document.getElementsByName("lang")[0].value === "it"){
var wont = "Non prenderò meno di ";
    var regwont = /Non prenderò meno di  (.*) Neopunti/;
    var want = "Voglio almeno ";
    var regwant = /Voglio almeno (.*) Neopunti/;
    var separator = ".";
}else if(document.getElementsByName("lang")[0].value === "es"){
var wont = "No acepto menos de ";
    var regwont = /No acepto menos de  (.*) Neopuntos/;
    var want = "Quiero al menos ";
    var regwant = /Quiero al menos  (.*) Neopuntos/;
    var separator = ".";
}else if(document.getElementsByName("lang")[0].value === "ch"){
var wont = "店主说“少于 ";
    var regwont = /店主说“少于  (.*) 尼奥/;
    var want = "店主说“至少要 ";
    var regwant = /店主说“至少要  (.*) 尼奥/;
    var separator = ",";
}else if(document.getElementsByName("lang")[0].value === "zh"){
var wont = "店主說「少於 ";
    var regwont = /店主說「少於  (.*) 尼奥/;
    var want = "店主說「至少要 ";
    var regwant = /店主說「至少要  (.*) 尼奥/;
    var separator = ",";
}else if(document.getElementsByName("lang")[0].value === "ja"){
var wont = "店員が「うーん、 ";
    var regwont = /店員が「うーん、 (.*) NP/;
    var want = "店員が「この品には、少なくとも";
    var regwant = /店員が「この品には、少なくとも (.*) NP/;
    var separator = ",";
}else if(document.getElementsByName("lang")[0].value === "ko"){
var wont = "점원이 '음... ";
    var regwont = /점원이 '음... (.*) NP/;
    var want = "점원이 '이 물건은 아무리 적어도 ";
    var regwant = /점원이 '이 물건은 아무리 적어도 (.*) NP/;
    var separator = ",";
}

if(document.body.innerHTML.indexOf(wont) > -1){
    haggle = document.body.innerHTML.match(regwont);
    document.getElementsByName("current_offer")[0].value = smart_haggle(haggle[1].replace(separator,"").trim());
}else if(document.body.innerHTML.indexOf(want) > -1){
    haggle = document.body.innerHTML.match(regwant); 
    document.getElementsByName("current_offer")[0].value = smart_haggle(haggle[1].replace(separator,"").trim());
}

Edited by Freestyle, 19 July 2015 - 07:57 PM.


#2 gotvacien

gotvacien
  • 74 posts

Posted 22 July 2015 - 07:48 PM

while this looks good and likely will work(havent tested it) why do you constantly redeclare the variables putting

var wont, regwont, want, regwant, separator;

at the top before the repeat function would mean you didnt have to put the var infront of each time you are deciding what your var will be in your if statement

 

you also could have used a switch statement rather then that giant if/elseif tree that would look something like

switch(document.getElementsByName("lang")[0].value){
    case "en":
        wont = "I wont take less than ";
        regwont = /I wont take less than (.*) Neopoints/;
        want = "I want at least ";
        regwant = /I want at least (.*) Neopoints/;
        separator = ",";
        break;
    case "nl":
        etc...
}

again your code is fine but when you start working on larger stuff you want to avoid copy/pasting code thats an easy way to introduce bugs.


Edited by gotvacien, 22 July 2015 - 08:04 PM.


#3 BEDDOEDv

BEDDOEDv
  • 287 posts


Users Awards

Posted 25 July 2015 - 04:47 AM

is it suposed to click the pet too?



#4 Nano

Nano
  • a delicious kiwi

  • 325 posts


Users Awards

Posted 25 July 2015 - 01:41 PM

is it suposed to click the pet too?

 

I haven't added that yet. :) Sometime in the next week when I'm not so ill.



#5 Rhizome

Rhizome
  • 14 posts

Posted 25 July 2015 - 02:04 PM

Woah it is possible to add in a feature to click the pet as well??? That sounds fantastic! Best of luck coding that and get well soon



#6 BEDDOEDv

BEDDOEDv
  • 287 posts


Users Awards

Posted 25 July 2015 - 11:32 PM

I haven't added that yet. :) Sometime in the next week when I'm not so ill.. hope you get well soon buddy

cool 





Also tagged with one or more of these keywords: neopets, userscript, smart haggle

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users