1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Buttons

Discussion in 'Code Snippets and Tutorials' started by Fexxel, Aug 23, 2009.

  1. steinn

    steinn Level I

    Joined:
    Jun 13, 2009
    Messages:
    105
    Likes Received:
    11
    Location:
    Brazil
    OHH, that not hidden, look at the required pages.
    That´s just for a more clean code...
    You don´t have to download, click in "show source code", and you will see the codes...
    Required don´t hidden anything, cookie grabbing scripts don´t user required cause this will not hidden the code and is more work.

    arguments.callee
    calls the actual function, doesn´t need required for that
    google it.


    Yes, i´m from brazil, my english is t̶o̶t̶a̶l̶l̶y̶ ̶t̶e̶r̶r̶i̶b̶l̶e̶ bad.
    So, if i say something wrong, that means that you don´t understand?
    I THINK fexxel understand everything that i write before.
    and if i type that wrong?

    Ok, I got the wrong element, not tested before

    Code (Text):
    1. document.getElementsByTagName("center")[1].getElementsByTagName("tr")[x].style.backgroundColor="#000";
    2. // x it´s the number of the job...
    That´s good for you?

    well, usually, the jobs that reward more, worth more..
    Impossible do something that grabs the best job.
     
  2. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    Alright, now I'm confused as sh*t.
    I used to understand what both of you were saying, but now I'm just confused as f**k because you guys have been argueing about stuff I don't know (yet?).
    I am CONFUSED.
    ...
    So, back to my questions.
    Code (Text):
    1. if(!GM_getValue("isdone")
    2. {
    3. if(document.body.innerHTML.indexOf("base reward")
    4. {
    5.     GM_setValue("isdone", true)
    6. }
    7. }
    Is this a valid code?
    How do I make it so that if isdone = true then setwindowtimeout to whatever the remainder is of the time left over.

    Now, this:
    Code (Text):
    1. // Else calculate how much time is needed before the next job listing then refresh the page
    2. else {
    3.   var tt = (9 - (m % 10)) * 60 + 50 - s;
    4.   window.setTimeout(function(){
    5.     alert('Checking jobs');
    6.     window.location.reload();
    7.   }, tt*1000);
    8. }
    Its brilliant.
    I love it.
    I UNDERSTAND IT.
    Thank god.
    It's this:
    If the page has jobs already on it, it doesn't do stuff.
    (Else if) the page is between 9:50 - 0:03 then refresh the page.
    NOW THERES THE PROBLEM THOUGH!
    Why would you want to refresh the page if it's 9:50-9:59? The jobs haven't refreshed by then! You need to alert the user, right? Swap the tab?

    So what about...
    Code (Text):
    1.  
    2. else if (m % 10 == 0 && s < 3){                
    3.   window.setTimeout(function(){window.location.reload()}, 300);
    4. }
    5. else if ((m + 1) % 10 == 0 && s > 55){
    6. alert('Refreshing in less than 5 seconds!');
    7. window.settimeout(window.location.reload(), 60000 - (s * 1000)) // this waits until its 10:00, 20:00, ect... and then refreshes. correct?
    8. // I set it to 55 instead of 50 seconds because 10 seconds is a bit longer than 5 seconds :P
    9. }
    Now, is the above ( ^ ) correct? (Is it valid?/Will it work?)

    ---
    As for the highlighting thing.
    Lets figure out how do this...

    document.getElementsByTagName("center")[1].getElementsByTagName("tr")[x].style.backgroundColor=" #FFFF00";
    // x it´s the number of the job...
    Ok, so that makes each "tr" (?) in "center"'s background color yellow. Collrect?
    But wait, that doesn't make sense.
    Is it the job #'s style.background color = yellow?
    And what does this "x" do? Do I have to declare it (like VB... dim x as ___)? What IS x?!

    thanks SO much guys for your help.
     
  3. jazzeh

    jazzeh Level I

    Joined:
    Jan 1, 2008
    Messages:
    144
    Likes Received:
    15
    That's what I had said at the top of page 3. The jobs start loading up at 10 seconds til the 10 minute mark (xx:x9:50).

    The last script I posted works, all you need to do is try it out.
    When it's x9:48 it'll give you an alert.
    After you click the alert it'll bring that tab to the front and go to the jobs page.
    If there are no jobs listed it'll refresh in .3 seconds
    If jobs are listed it'll highlight any with a reward over 5000
    If you manually click on a job and you're too late, it'll go back to the jobs page.
    If you click a job and get it or have reached the max jobs, it'll do nothing.
    If you're on any other page and no new jobs are listed, it'll set a timeout to alert and refresh at x9:48.

    To answer your questions.
    The first set of code is valid but there's no reason you would need it. You'd also have to add in somewhere else a reason to make the GM_value false. Utterly unneeded.
    The second set of code will have a problem because when you have an alert, the script pauses to wait for user input. When the user clicks continue then the script resumes and would then refresh in x amount of seconds where x is calculated from when the script started, not when the button was clicked This is something else you don't need because the jobs start loading at x9:50. In my script I set up the alert at x9:48 which gives 2 seconds to click the alert.

    As for the highlighting thing, that's done in the script too.
    Code (Text):
    1.   allDivs = document.evaluate('//td[@colspan="2"][contains(@style,"border-right")]',document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
    2.   for (var x = 0, thisDiv; thisDiv = allDivs.snapshotItem(x); x++){
    3.     var reward = parseInt(thisDiv.innerHTML.match(/([\d\.,]+) NP/)[1].replace(/[\.,]/g, ''), 10);
    4.     if (reward > 5000){
    5.       thisDiv.setAttribute('bgcolor', '#dedede')
    6.     }
    7.   }
    8.  
    Code (Text):
    1. allDivs = document.evaluate('//td[@colspan="2"][contains(@style,"border-right")]',document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
    allDivs is an array of all the job cells (td). I looked over the html to see that the job cell has a colspan of "2" and in it's style tag it says "border-right". I stuck with doing things (like changing the bgcolor) to the cell instead of each job table.. selecting the table would've been just as easy but using the cell gets the job done.
    We use the for loop to go through each cell and test if the reward is over 5000
    If it's over 5000 then it sets the attribute bgcolor to #dedede (grey).
    (I chose not to set the style attribute because it can have problems when you want to remove an attribute and the tag has other style settings.
    I also could've used
    thisDiv.bgcolor = '#dedede'
    but that can have problems if the tag doesn't already have a bgcolor attribute)
     
  4. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    Alright.
    So pretty much 99.9% of the script is done- well, thats what I thought.
    Now what about a flat out complete fresher?
    Which brings me to my next question- (I'm going to try to use your layout thing)
    How do I make the script click the "Apply for this job",
    and if the page contains "You don't have any job coupons that you can use for this job!" then go back a page, refresh, and click another apply for this job.
    And if any of the jobs chosen contain "You didn't get the job" then go back to the previous page and try again for another job.
    And if any of these jobs are succesfuly grabbed (Containing ___) then go to the shop wizard page with the name of the item needed in the search box of the shop wizard.

    Complex, eh?
    well, we can do that innerhtml thing for all the "if the page contains" thing right?
    And I suppose the wizard wouldn't be too hard, setting a value on the page, right?
    As for clicking the url, I have no idea in hell how to do that :p
     
  5. jazzeh

    jazzeh Level I

    Joined:
    Jan 1, 2008
    Messages:
    144
    Likes Received:
    15
    The same way it goes to the basic jobs page. We used the for loop to go through the jobs and looks at the rewards. Use it to find a job you like and get the url for that job
    window.location.href = 'http://www.neopets.com/jobURLhere.phtml';
    Basic jobs don't require coupons but you should be able to figure it out using everything else already in the script since it already checks to see if you got a job and if you missed it goes back to the job listing
    Already does that.
    Basically the first if statement checks if you didn't get the job so you can add an else in there and that would do stuff when you got the job.
    Have it find the item by using match or taking parts of the string (html)
    thisDiv.innerHTML.match(regex here)[1]; or
    thisDiv.innerHTML.split('cut here')[1].split('cut here')[0];

    if the thisDiv = "3 items:<b>Magic Potion</b>" then you might use
    item = thisDiv.innerHTML.split(':<b>')[1].split('</b>')[0];
    then use
    window.open('http://www.neopets.com/market.phtml?type=wizard&string='+item)
     
  6. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26

    Alright, so my answer is "yes" to everything EXCEPT this part:

    Alright so I like the split thing because it sounds pretty easy to use.
    However, if I do "item = thisDiv.innerHTML.split(':<b>')[1].split('</b>')[0];" then wouldn't that split all things with the bold tags in that div?
    And whats the deal with thisDiv.innerhtml- I understand it means this division of the page in the html, but how do you set the "Div". (By this I mean how do you specify Div)

    Also, you mentioned..
    window.open('http://www.neopets.com/market.phtml?type=wizard&string='+item)
    The post data of shop wiz: (Collected by mehself)
    "type=process_wizard&feedset=0&shopwizard=item+name&table=shop&criteria=exact&min_price=0&max_price=99999"
    How do I set the url to the post page with those items.
    I know you explained some, but that doesn't explain if you have "shopwizard=item+name" because you need to add +'s between each word. --- Thats what I need to learn how to do.
    Along with doing this:
    window.open('http://xxxxx.com/'insertion here'/restofthepageurl'
    or would you do something like...
    window.open('http://xxxxx.com/'insertion here AND the rest of the page url') ?
    Because in VB you do:
    w.request("POST", "http://neopets.com" & ____ & "alksdjfaldskjfaldskfj", google.com)
     
  7. jazzeh

    jazzeh Level I

    Joined:
    Jan 1, 2008
    Messages:
    144
    Likes Received:
    15
    If you look in the script, thisDiv was defined in the 'for' loop
    I just used it there as example code.
    If it doesn't grab what you want, use something different. If you'll notice, the first split has ":<b>" in it. I had just pulled somethings from memory so I doubt it would work but look for something that's common to all job details.
    Then after you define item = ...
    use the following to see what it gives you
    alert(item);
    or if you like to use the error console (which you should get into the habit)
    GM_log(item);
    have you tried just typing it into your URL bar without the '+'
    Code (Text):
    1. http://www.neopets.com/market.phtml?type=wizard&string=serf lens
    otherwise you can take
    item = item.replace(' ', '+');

    As far as using the post data you found, it checks the referrer so you won't be able to visit the ...process_market... url directly unless you install some add-ons. Even then ... hmmm

    What have you tried? You can put any of those things into a test script. If it opens a new window then you've got it right. Also any errors would be reported to the error console. Hint: Look at how I used a variable in the script.
    I had given you code to open the shop wizard search in a new window, I'm not familiar with VB but it looks like you want to find out more info about http://wiki.greasespot.net/GM_xmlhttpRequest or http://www.w3schools.com/XML/xml_http.asp

    There are tons of helps sites about javascript. Here's one: http://www.w3schools.com/jsref/
    The best way to learn is to try. There's also something to be said about doing the work in searching for the answer.