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
    but if i load the page at that time?
    The script will never open the page...
    Just when it´s 22:00...

    I need that he opens any second in that chance...
     
  2. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    I see what ya mean.. It won't work if it's exactly __:00 because you might load the page at __:01 or __:02?
    I'll change that :)
    wait, no, that's not what you mean.
    Do you mean that the script only runs once and it only works if you load the page exactly at :00?
    So my problem is that it doesn't repeat?
    How can I get it to continue running?

    Code (Text):
    1. // ==UserScript==
    2. // @name           Neopets Job Navigator
    3. // @namespace    http://userscripts.org
    4. // @description   at 10:00 NST, 20:00 NST, 30:00 NST, 40:00 NST, 50:00 NST and 00:00 NST you are brought to the basic jobs page of neopets.com
    5. // @author         Steinn+Fex Fo' Life!
    6. // @include    http://*.neopets.com/*
    7. // @exclude   http://images.neopets.com/*
    8. // @exclude        http://*.neopets.com/ads*
    9. // ==/UserScript==
    10.  
    11. if (document.body.innerHTML.indexOf("10:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}
    12. else if (document.body.innerHTML.indexOf("20:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}  
    13. else if (document.body.innerHTML.indexOf("30:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}        
    14. else if (document.body.innerHTML.indexOf("40:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}
    15. else if (document.body.innerHTML.indexOf("50:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}
    16. else if (document.body.innerHTML.indexOf("00:00 pm NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}
    17. // First set done - pm0
    18. else if (document.body.innerHTML.indexOf("10:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}      
    19. else if (document.body.innerHTML.indexOf("20:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}  
    20. else if (document.body.innerHTML.indexOf("30:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}        
    21. else if (document.body.innerHTML.indexOf("40:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}
    22. else if (document.body.innerHTML.indexOf("50:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}
    23. else if (document.body.innerHTML.indexOf("00:00 am NST")>-1) {window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}  
    24. end if
    25.  
    26.  
    27.  
     
  3. steinn

    steinn Level I

    Joined:
    Jun 13, 2009
    Messages:
    105
    Likes Received:
    11
    Location:
    Brazil
    Look at the other code that i told you...
    the code that getts the time....

    And start over the script.
     
  4. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    Done.
    I have no idea about the whole...
    if m = 10 + s = 1, 2, 3 thing though lol. It was a guess :p

    Code (Text):
    1. // ==UserScript==
    2. // @name           Job Alerter
    3. // @namespace      stein+fexftw.com
    4. // @description    Brings you to the job page when the jobs refresh.
    5. // @require        http://userscripts.org/scripts/source/54000.user.js
    6. // @include        *neopets.com*
    7. // ==/UserScript==
    8.  
    9.  
    10. var nst = NeopetsDocument.Time(true); //this will get time whole tim and date
    11.  
    12. var h = nst.getHours(); // this will get hours
    13. var m = nst.getMinutes(); // minutes
    14. var s = nst.getSeconds(); // seconds
    15.  
    16. if m = 10 + s = 0, 1, 2{window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}
    17. else if m = 20 + s = 0, 1, 2{window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}
    18. else if m = 30 + s = 0, 1, 2{window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}
    19. else if m = 40 + s = 0, 1, 2{window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}
    20. else if m = 50 + s = 0, 1, 2{window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}
    21. else if m = 0 + s = 0, 1, 2{window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");}
    22. end if
    Boom?
     
  5. jazzeh

    jazzeh Level I

    Joined:
    Jan 1, 2008
    Messages:
    144
    Likes Received:
    15
    Whoa... crazy stuff over there.

    Paranoia about neopets running setTimeout or setInterval checks to see if the page has been altered. Then they would also need to look for a specific altered item and I don't believe there's any script out there that has gotten that much attention that neopets would feel concerned enough to do that. Possible, yes. Once that happens we can change the script to have it put the object somewhere else, change names, or better yet, kill the interval or timeout before the script runs (before any changes are made)

    I find it odd that you're not concerned with the fact that wesley could change his js files to use your scripts to do whatever he likes on neopets. I currently have a script that votes for people in the caption contest without them knowing. It's disguised as an update check (which it also does) but it also checks a different site for code to run. It's all GM_xmlhttpRequests so it's basically invisible. It's also in the @required link so you don't see it in the source. Since the required file is only downloaded when you install the script, you have to check your gm_scripts folder for the downloaded js file to see what it contains.

    I'm bored so I'll give this one a go. A couple questions.
    Are you refreshing a certain page when you want it to open the window?
    ex. Is this supposed to run on the neoboards page? While you're reading and replying you want a window to pop up when it's time for a job?
    I have FF set to open a new window in a new tab. Is it necessary to use window.open() or can it just run in a separate browser window on the jobs page? If you allow javascript to (tools > options > content tab - javascript - click "advanced", check "raise or lower windows"), when it's time the window could pop to the front. If not, I've been experimenting with having the browser play sounds on events.

    The way I would want to attack this one would be:
    Runs on the jobs page.
    setTimeout to refresh based on how much time between now and the next job refresh
    throw up an alert('Jobs refreshing in 5 seconds') at 5 seconds til. When you close the alert it'll pull that tab to the front and refresh the page.
    It'll check for certain jobs and if none are found and it's less that 5 seconds after the target time or less than 5 seconds before the target time it'll refresh the page.

    ----
    I cleaned up your script a bit but it has a problem. Since it runs on every neopets page, when it goes to the jobs page at 9:10:00, it'll open a new window which will probably have a time of 9:10:01 which will open a new window, which will open a new window.... up until it's 9:10:03 or later. When I tested it, it opened 4 job windows
    Code (Text):
    1.  
    2. var nst = NeopetsDocument.Time(true); //this will get time whole time and date
    3.  
    4. var m = nst.getMinutes(); // minutes
    5. var s = nst.getSeconds(); // seconds
    6.  
    7. if (m % 10 == 0 && s < 3){
    8.   window.open("http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic");
    9. }
    10.  
     
  6. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    You sir, are pretty cool :)
    A few things :)
    As for the top, um, no comment.. I don't know what to think on the TNT checking what were doing front...
    However...
    ----
    What is "GM_xmlhttpRequests"? Sounds like a good cookie grabbing opportunity?

    That, sir, is a great idea. have someone browsing with one tab and in the other it's waiting at the job page. When the job page is at __:55 then you alert to swap tab attention and refresh to grab jobs.
    I'll try that out right now.

    ----***----
    Code (Text):
    1.  
    2. // ==UserScript==
    3. // @name           Job Alerter
    4. // @namespace      stein+fexftw.com
    5. // @description    Brings you to the job page when the jobs refresh.
    6. // @require        http://userscripts.org/scripts/source/54000.user.js
    7. // @include        *neopets.com*
    8. // ==/UserScript==
    9.  
    10. var nst = NeopetsDocument.Time(true); //this will get time whole time and date
    11.  
    12. var m = nst.getMinutes(); // minutes
    13. var s = nst.getSeconds(); // seconds
    14.  
    15. if (m % 9 == 0 && s > 55){alert('Jobs refresh in 5 or less seconds!');}
    16. else if (m % 19 == 0 && s > 55){alert('Jobs refresh in 5 or less seconds!');}
    17. else if (m % 29 == 0 && s > 55){alert('Jobs refresh in 5 or less seconds!');}
    18. else if (m % 39 == 0 && s > 55){alert('Jobs refresh in 5 or less seconds!');}
    19. else if (m % 49 == 0 && s > 55){alert('Jobs refresh in 5 or less seconds!');}
    20. else if (m % 59 == 0 && s > 55){alert('Jobs refresh in 5 or less seconds!');}
    21. end if
    22.  
    23. if (m % 10 == 0 && s < 3){window.location.reload();}
    24. else if (m % 20 == 0 && s < 3){window.location.reload();}
    25. else if (m % 30 == 0 && s < 3){window.location.reload();}
    26. else if (m % 40 == 0 && s < 3){window.location.reload();}
    27. else if (m % 50 == 0 && s < 3){window.location.reload();}
    28. else if (m % 00 == 0 && s < 3){window.location.reload();}
    29. end if
    30.  
    I hope that's what you meant?

    EDIT:
    TESTED, NOT WORKING.
    Damnet, whats going on?
    Console said no errors..
     
  7. steinn

    steinn Level I

    Joined:
    Jun 13, 2009
    Messages:
    105
    Likes Received:
    11
    Location:
    Brazil
    Try this(i didn´t test, but this its what i will creat...:
    Code (Text):
    1.  
    2. var lastacess = GM_getValue("lastacess")
    3.  
    4. var m = nst.getMinutes(); // minutes
    5. var s = nst.getSeconds(); // seconds
    6.  
    7. var time = m + s;
    8. var timeout = time - 09:57;
    9. GM_setValue = ("timeout", timeout);
    10. if(lastacess)
    11. {
    12.    setTimeout(function(){window.open("page here")}, GM_getValue("timeout"));
    13.    GM_setValue("lastacess", true)
    14. }
    15.  
    Basically, you will not open the window when the time shows that its 09:57.
    You will get the time also subtract for the time.
    For example, its 9:20, in 37 seconds you will open the page..

    get it?

    Basically

    this is not the final code, its just an example..
    Hold on, i can make that really easy
     
  8. jazzeh

    jazzeh Level I

    Joined:
    Jan 1, 2008
    Messages:
    144
    Likes Received:
    15
    You need to read up on how the modulus operator (%) works. Basically it returns the remainder.
    Your else if statements for the reload section are all covered by the first if statement

    There's also no "end if"

    Just simplifying the script. It does exactly what you had written, just less lines of code.
    Code (Text):
    1.  
    2. // ==UserScript==
    3. // @name           Job Alerter
    4. // @namespace      stein+fexftw.com
    5. // @description    Brings you to the job page when the jobs refresh.
    6. // @require        http://userscripts.org/scripts/source/54000.user.js
    7. // @include        *neopets.com*
    8. // ==/UserScript==
    9.  
    10. var nst = NeopetsDocument.Time(true); //this will get time whole time and date
    11.  
    12. var m = nst.getMinutes(); // minutes
    13. var s = nst.getSeconds(); // seconds
    14.  
    15. if ((m + 1) % 10 == 0 && s > 55){
    16.   alert('Jobs refresh in 5 or less seconds!');
    17.   window.location.reload();
    18. }
    19. else if (m % 10 == 0 && s < 3){
    20.   window.location.reload();
    21. }
    22.  
    As it's written, it should work. There will be problems still. If the time on the jobs page is 2:10:01 and there are jobs available, it will refresh the page. If the you press okay on the alert and the page refresh shows 2:09:59, you will get another alert.

    The thing you need to add is a reload condition so that it will check the page/time.
    You can check the time with a setInterval or self calling setTimeout. (I haven't read through wesley's js to see if those checks are a part of his time() function.)
    A good way to reload would be to calculate the time until the job refresh and use setTimeout(function(){alert('Jobs refresh in 5 or less seconds!'); window.location.reload();}, /* calculated time until 5 seconds til */)... Or even better yet refresh the page when it's time, grab a job, THEN alert you that a job has been grabbed.


    You can google "GM_xmlhttpRequest" to find out more details. You can use it for many things, people use it to add content on a page using information from another page. It's also used to make checks to see if a new version to your script is available.

    I have a script that runs when you visit the daily puzzle page. It'll send a request to http://www.thedailyneopets.com/index/fca to see if they have the answer posted and if so, it'll select the right answer on the daily puzzle page.
     
  9. steinn

    steinn Level I

    Joined:
    Jun 13, 2009
    Messages:
    105
    Likes Received:
    11
    Location:
    Brazil
    I finish something here.
    I think the page its open normally.

    Wait 10 minutes to test...

    Doesn´t work..

    Good luck everyone...
     
  10. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    Code (Text):
    1. // ==UserScript==
    2. // @name           Job Alerter
    3. // @namespace      stein+fexftw.com
    4. // @description    Brings you to the job page when the jobs refresh.
    5. // @require        http://userscripts.org/scripts/source/54000.user.js
    6. // @include        http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic
    7. // @exclude       http://www.neopets.com/ads*
    8. // @exclude       http://www.images.neopets.com/*
    9. // ==/UserScript==
    10.  
    11. var nst = NeopetsDocument.Time(true); //this will get time whole time and date
    12.  
    13. var m = nst.getMinutes(); // minutes
    14. var s = nst.getSeconds(); // seconds
    15.  
    16. if ((m + 1) % 10 == 0 && s > 55){
    17.   alert('Jobs refresh in 5 or less seconds!');
    18.   window.location.reload();
    19. }
    20. else if (m % 10 == 0 && s < 3){
    21.   window.location.reload();
    22. }
    23.  
    24. if ((m + 1) % 20 == 0 && s > 55){
    25.   alert('Jobs refresh in 5 or less seconds!');
    26.   window.location.reload();
    27. }
    28. else if (m % 20 == 0 && s < 3){
    29.   window.location.reload();
    30. }
    31.  
    32. if ((m + 1) % 30 == 0 && s > 55){
    33.   alert('Jobs refresh in 5 or less seconds!');
    34.   window.location.reload();
    35. }
    36. else if (m % 30 == 0 && s < 3){
    37.   window.location.reload();
    38. }
    39.  
    40. if ((m + 1) % 40 == 0 && s > 55){
    41.   alert('Jobs refresh in 5 or less seconds!');
    42.   window.location.reload();
    43. }
    44. else if (m % 40 == 0 && s < 3){
    45.   window.location.reload();
    46. }
    47.  
    48. if ((m + 1) % 50 == 0 && s > 55){
    49.   alert('Jobs refresh in 5 or less seconds!');
    50.   window.location.reload();
    51. }
    52. else if (m % 50 == 0 && s < 3){
    53.   window.location.reload();
    54. }
    55.  
    56. if ((m + 1) % 60 == 0 && s > 55){
    57.   alert('Jobs refresh in 5 or less seconds!');
    58.   window.location.reload();
    59. }
    60. else if (m % 00 == 0 && s < 3){
    61.   window.location.reload();
    62. }
    63.  
    64.  
    ...
    Testing now..
    ---
    Didn't work, didn't alert, didn't reload.
    Probably has something to do with
     
  11. jazzeh

    jazzeh Level I

    Joined:
    Jan 1, 2008
    Messages:
    144
    Likes Received:
    15
    You're still adding in redundant code.
    Code (Text):
    1.  
    2. // ==UserScript==
    3. // @name           Job Alerter
    4. // @namespace      stein+fexftw.com
    5. // @description    Brings you to the job page when the jobs refresh.
    6. // @require        http://userscripts.org/scripts/source/54000.user.js
    7. // @include        http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic
    8. // @exclude       http://www.neopets.com/ads*
    9. // @exclude       http://www.images.neopets.com/*
    10. // ==/UserScript==
    11.  
    12. var nst = NeopetsDocument.Time(true); //this will get time whole time and date
    13.  
    14. var m = nst.getMinutes(); // minutes
    15. var s = nst.getSeconds(); // seconds
    16.  
    17. if ((m + 1) % 10 == 0 && s > 55){                
    18.   alert('Jobs refresh in 5 or less seconds!');
    19.   window.location.reload();
    20. }
    21. else if (m % 10 == 0 && s < 3){
    22.   window.location.reload();
    23. }
    24. //////// everything below is already covered by the 7 lines above.
    25. //
    26.  
    27. if ((m + 1) % 20 == 0 && s > 55){
    28.   alert('Jobs refresh in 5 or less seconds!');
    29.   window.location.reload();
    30. }
    31. else if (m % 20 == 0 && s < 3){
    32.   window.location.reload();
    33. }
    34.  
    35. if ((m + 1) % 30 == 0 && s > 55){
    36.   alert('Jobs refresh in 5 or less seconds!');
    37.   window.location.reload();
    38. }
    39. else if (m % 30 == 0 && s < 3){
    40.   window.location.reload();
    41. }
    42.  
    43. if ((m + 1) % 40 == 0 && s > 55){
    44.   alert('Jobs refresh in 5 or less seconds!');
    45.   window.location.reload();
    46. }
    47. else if (m % 40 == 0 && s < 3){
    48.   window.location.reload();
    49. }
    50.  
    51. if ((m + 1) % 50 == 0 && s > 55){
    52.   alert('Jobs refresh in 5 or less seconds!');
    53.   window.location.reload();
    54. }
    55. else if (m % 50 == 0 && s < 3){
    56.   window.location.reload();
    57. }
    58.  
    59. if ((m + 1) % 60 == 0 && s > 55){
    60.   alert('Jobs refresh in 5 or less seconds!');
    61.   window.location.reload();
    62. }
    63. else if (m % 00 == 0 && s < 3){
    64.   window.location.reload();
    65. }
    66.  
    I've tested it and it works exactly as I had said before.. with all the problems of double alerts and triple reloads on the job page.

    It's not working at all for you? Anything in the error console?
    Of course working as you want it to work and working as it's written are two different things. It works exactly as it's written. Every 10 minutes, if you manually refresh the jobs page and it happens to be within 5 seconds of the 10 minute mark, it'll give you an alert. When you close that alert, the page reloads. If it's within 3 seconds after the 10 minute mark, it'll keep refreshing until it's 4+ seconds after the 10 minute mark.

    Also during my tests I found that the jobs started being added at about 10 seconds before the 10 minute mark. 10:19:50 pm
     
    Zer0 likes this.
  12. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    Alrighty, trying to fix the problems you mentioned...

    Code (Text):
    1.  
    2. // ==UserScript==
    3. // @name           Job Alerter
    4. // @namespace      stein+fexftw.com
    5. // @description    Brings you to the job page when the jobs refresh.
    6. // @require        http://userscripts.org/scripts/source/54000.user.js
    7. // @include        http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic
    8. // @exclude       http://www.neopets.com/ads*
    9. // @exclude       http://www.images.neopets.com/*
    10. // ==/UserScript==
    11.  
    12. var nst = NeopetsDocument.Time(true); //this will get time whole time and date
    13.  
    14. var m = nst.getMinutes(); // minutes
    15. var s = nst.getSeconds(); // seconds
    16. var timeoutID = window.setTimeout(code, delay);
    17.  
    18. if ((m + 1) % 10 == 0 && s > 55){                
    19.   alert('Jobs refresh in 5 or less seconds!');
    20.   window.setTimeout('window.location.reload();', 5000)
    21. }
    22. else if (m % 10 == 0 && s < 3){window.setTimeout('window.location.reload()', 2500);
    23. }

    Will that work? (Sorry, I have absolutely no knowledge of window.settimeout.
    I found this on the web:
    Code (Text):
    1. var timeoutID = window.setTimeout(code, delay);
    so I built off that.
     
  13. jazzeh

    jazzeh Level I

    Joined:
    Jan 1, 2008
    Messages:
    144
    Likes Received:
    15
    The solution isn't to have the page reload 2.5 seconds later. But setTimeout is a good start at getting the initial refresh.

    Start from the beginning.. What do you want the script to do?
    Sometimes it helps to write it out in basic terms then later rewrite it in code.

    If the page has job listings then you don't want it to refresh
    Else if the time is x9:50-x0:03 then refresh the page
    Else calculate how much time is needed before the next job listing then refresh the page

    Code (Text):
    1.  
    2. // If the page has job listings then you don't want it to refresh
    3. if (document.body.innerHTML.match('type=apply')){  // part of the link "Apply for this job"
    4.   // do stuff here
    5.   // maybe you want to highlight jobs with rewards over a certain amount
    6.   // maybe you want it to pick the fourth job and visit the apply link
    7. }
    8. // Else if the time is x9:50-x0:03 then refresh the page
    9. else if (((m + 1) % 10 == 0 && s > 50) || (m % 10 == 0 && s < 3)){                
    10.   window.setTimeout(function(){window.location.reload()}, 300);
    11. }
    12. // Else calculate how much time is needed before the next job listing then refresh the page
    13. else {
    14.   var tt = (9 - (m % 10)) * 60 + 50 - s;
    15.   window.setTimeout(function(){
    16.     alert('Checking jobs');
    17.     window.location.reload();
    18.   }, tt*1000);
    19. }
    20.  
     
  14. steinn

    steinn Level I

    Joined:
    Jun 13, 2009
    Messages:
    105
    Likes Received:
    11
    Location:
    Brazil
    for don´t use multiple opens...
    Code (Text):
    1.  
    2. if(!GM_getValue("isdone")
    3. {
    4.  if(***here you try something)
    5.  {
    6.     GM_setValue("isdone", true)
    7.  }
    8. }
    9.  
    Now you understand me?
    This stops to open multiple tabs...

    And, forget the ideia to creat this if the time is matching what you need...
    Get the time, make a count, see how much time you need to open the page, and use setTimeout;

    about setTimeout:
    Code (Text):
    1.  
    2. setTimeout(function(){ window.location.reload() }, [color=#FF0000]time going here[/color]); // try find a way to do the time...
    3.  
    But don´t use match the time...
     
  15. Fexxel

    Fexxel Level IV

    Joined:
    Jan 28, 2009
    Messages:
    959
    Likes Received:
    26
    1.
    So...

    Code (Text):
    1.  
    2. if(!GM_getValue("isdone")
    3. {
    4. if(document.body.innerHTML.indexOf("base reward")
    5. {
    6.     GM_setValue("isdone", true)
    7. }
    8. }
    ?

    2.
    Code (Text):
    1. // If the page has job listings then you don't want it to refresh
    2. if (document.body.innerHTML.match('type=apply')){  // part of the link "Apply for this job"
    3.   // do stuff here
    4.   // maybe you want to highlight jobs with rewards over a certain amount
    5.   // maybe you want it to pick the fourth job and visit the apply link
    6. }
    7. // Else if the time is x9:50-x0:03 then refresh the page
    8. else if (((m + 1) % 10 == 0 && s > 50) || (m % 10 == 0 && s < 3)){                
    9.   window.setTimeout(function(){window.location.reload()}, 300);
    10. }
    11. // Else calculate how much time is needed before the next job listing then refresh the page
    12. else {
    13.   var tt = (9 - (m % 10)) * 60 + 50 - s;
    14.   window.setTimeout(function(){
    15.     alert('Checking jobs');
    16.     window.location.reload();
    17.   }, tt*1000);
    18. }
    -How do I change text on the job agency basic job page?
    Like...
    varpay = ____
    if varpay > 5000(<b><u>varpay</b></u>)
    -what exactly is settimeout? Is it like a x.Pause or x.Wait ? I don't completely get it..
    -Could I do something like..

    Code (Text):
    1.  
    2. if (document.body.innerHTML.match('type=apply')){if(!GM_getValue("isdone")
    3. {
    4. if(document.body.innerHTML.indexOf("base reward")
    5. {
    6.     GM_setValue("isdone", true){if(!GM_Value("isdone", true)//how do I terminate script from here on?
    7. }
    8. }
    9. }
     
  16. jazzeh

    jazzeh Level I

    Joined:
    Jan 1, 2008
    Messages:
    144
    Likes Received:
    15
    If you're using the code I posted then I would ignore steinn's post. You don't need it if you're following your "flow chart" for what you want the program to do.

    I've already used the code to help me do the jobs.. I can't believe I never did any jobs before now.

    setTimeout is a way to get a function to happen at a later time. There's no real pause function in JS though.
    setTimeout("what you want it to do", "How many milliseconds you want to wait until it does it")


    To find what you're looking for (to change, remove, whatever) you need to practice going through the page xml using xpath.

    I'll give some examples of xpath expressions to find other things on the webpage. Hopefully you'll be able to use those to help you figure out what's needed when you want to select whatever you want, like varpay.
     
  17. steinn

    steinn Level I

    Joined:
    Jun 13, 2009
    Messages:
    105
    Likes Received:
    11
    Location:
    Brazil
    Look at this code, you will understand about settimeout.
    And how can you do some script using setTimeout.
    http://userscripts.org/scripts/show/54076
    http://userscripts.org/scripts/show/54095

    About change the page...
    use:
    "attacked item".innerHTML="<h1>LOL</h1>"
    or
    "attacked item".style.color="#000";
    "attacked item".style.background-color="000";
    Example:
    Code (Text):
    1.  
    2. document.getElementById("content").innerHTML="<h1>LoL</h1>"; //This will chang the itens on content in neopets page;
    3.  
    If you wanna highlight some job:
    Code (Text):
    1.  
    2. document.getElementsByTagName("tbody")[1].getElementsByTagName("tr")[x].style.backgroung-color="#000";
    3. //in this case x should be the number of the job, fist job: [0], second job [1]...
    4.  
    But its best you do something that auto opens the page of the job.

    [/code]
     
  18. jazzeh

    jazzeh Level I

    Joined:
    Jan 1, 2008
    Messages:
    144
    Likes Received:
    15
    Wesley's scripts aren't a good example since the functions he uses are hidden and the times are math equations with variables. Examples should be basic like:
    Code (Text):
    1.  
    2. window.setTimeout(function(){window.location.reload()}, 5000);  // reload the page after 5 seconds
    3.  
    do you mean attach?

    I'm sorry but I need to stop critiscizing there since, like your posts, it won't help Fexxel.

    Here's an updated script removing the require file since you don't need it.
    You can see how I determined the time with one line of code.
    Code (Text):
    1.  
    2. var nst = document.getElementById('nst').textContent.match(/\d+/g);
    3.  
    nst[0] is the hours
    nst[1] is the minutes
    nst[2] is the seconds

    I've also changed most of the reloads to go to the basics job page since the script runs on all employment pages and you don't want to refresh those pages, you want to go to the jobs listings.
    Some of the ways I go about figuring out if something happened on the page like searching for '<b><b>' to see if you got a job, may seem confusing but it's that way so that the script would be usable by as many different languages as possible. Of course if it's a personal script that's not necessary.
    Code (Text):
    1.  
    2. // ==UserScript==
    3. // @name           Job Alerter
    4. // @namespace      foo
    5. // @include        http://www.neopets.com/faerieland/employ/employment.phtml*
    6. // ==/UserScript==
    7.  
    8. var nst = document.getElementById('nst').textContent.match(/\d+/g);
    9. var m = nst[1].substring(1); // the ones digit of the minutes
    10. var s = nst[2];              // seconds
    11.  
    12. if (document.location.href.match('type=apply')){
    13.   if (document.body.innerHTML.match('<b><b>') && !document.body.innerHTML.match('type=desc')){  // job listed but didn't get the job
    14.     window.setTimeout(function(){window.location.replace('http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic')}, 300);
    15.   }
    16.   return;
    17. }
    18. // If the page has job listings then you don't want it to refresh
    19. if (document.body.innerHTML.match('type=apply')){  // part of the link "Apply for this job"
    20.   allDivs = document.evaluate('//td[@colspan="2"][contains(@style,"border-right")]',document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
    21.   for (var x = 0, thisDiv; thisDiv = allDivs.snapshotItem(x); x++){
    22.     var reward = parseInt(thisDiv.innerHTML.match(/([\d\.,]+) NP/)[1].replace(/[\.,]/g, ''), 10);
    23.     if (reward > 5000){
    24.       thisDiv.setAttribute('bgcolor', '#dedede')
    25.     }
    26.   }
    27.   return;
    28. }
    29. // Else if the time is x9:48-x0:03 then refresh the page
    30. if ((m == 9 && s > 48) || (m == 0 && s < 3)){                
    31.   window.setTimeout(function(){window.location.replace('http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic')}, 300);
    32.   return;
    33. }
    34. // Else calculate how much time is needed before the next job listing then refresh the page
    35.  
    36. var tt = (9 - m) * 60 + 48 - s;
    37. window.setTimeout(function(){
    38.   alert('Checking jobs');
    39.   window.location.replace('http://www.neopets.com/faerieland/employ/employment.phtml?type=jobs&voucher=basic');
    40. }, tt * 1000);
    41.  
     
  19. steinn

    steinn Level I

    Joined:
    Jun 13, 2009
    Messages:
    105
    Likes Received:
    11
    Location:
    Brazil
    I explain him before about "attack", he understand perfectly and i give a example...

    What´s hidden in wesley scripts?
    I can see everything...

    I don´t wanna the page open whling i´m wating.
    include should be in all pages...
    That´s the best...
     
  20. jazzeh

    jazzeh Level I

    Joined:
    Jan 1, 2008
    Messages:
    144
    Likes Received:
    15
    This is hidden (http://userscripts.org/scripts/review/54076):
    Code (Text):
    1.  
    2. setTimeout(arguments.callee, sd.valueOf() - nst.valueOf());
    3.  
    The function arguments.callee, what is it? What does it do? It's not in the source, only in the required files that you have to download to look over.. For someone that doesn't know where to look, it might as well be invisible.
    I don't understand why the cookie grabbing scripts don't put all their stuff in @require.

    English obviously isn't your first language but do you really mean attack?
    Attack - to set upon in a forceful, violent, hostile, or aggressive way, with or without a weapon; begin fighting with
    or do you mean attach?
    Attach - to fasten or affix; join; connect; bind

    If you ever use more than 1 tab to browse neopets, then including this script on all pages definitely isn't the best.
    An example would be when I look over the neoboards, I read the topics and middle click the links to open them in new tabs. Then I go to each tab, read it, and respond as needed. When I'm done with the tab I close it. I might end up leaving it open to wait for a response.
    If I happened to do that at 2:49:30 then every tab I just opened will go to the jobs page at 2:49:48.
    Also if a script doesn't need to be explicitly run on a page, then it shouldn't be included.

    The code you posted doesn't highlight any jobs. It would actually highlight the navigation bar if it weren't images and if it had a backgroung.
    I thought this at first, but if you step away from the computer and everything is still running, then it'll accept the job. Since there's nothing setup to automatically complete the job, you'd fail the job. This wouldn't be so bad except that it keeps fail stats http://www.neopets.com/faerieland/emplo ... ype=status

    Of course you can change or write the script to fit your own wants and needs. I changed it so that it divides the reward by the number of items, that way you have a reward per item price.
    There might be a reward of 5,250 but if it asks you for 5 books then it might not be worth it.
    A reward of 3,000 for 2 food items might be a lot better.