Help With Making Refresher

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

  1. II_warlord_II

    II_warlord_II Level III

    Joined:
    Aug 13, 2008
    Messages:
    532
    Likes Received:
    31
    Hey,
    I'm trying to make refresher (very basic one)
    Using JavaScript, So I Can Install it in greasemonkey.
    My plan is to use it as a
    "Restock Refresher"
    Refreshes with between sec feature
    7 - 12 sec.

    What I have is.
    // ==UserScript==
    // @name Neopets : Refresher
    // @description Automatically refreshes a page
    // @include http://REPLACE.THIS.COM
    // ==/UserScript==

    // Minimum refresh time (in seconds)
    var refreshMin = 7;
    // Maximum refresh time (in seconds)
    var refreshMax = 12;

    setTimeout(function()
    {

    // Determine the number of seconds between min and max
    var randSpan = (refreshMax - refreshMin) + 1;
    // Random time between minimum and maximum
    var randTime = Math.floor(Math.random() * randSpan) + refreshMin;
    // Convert seconds to milliseconds
    var randTimeMS = randTime * 1000;

    window.setInterval('location.reload()', randTimeMS);

    return true;
    },0);

    dont work...
     
  2. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    Javascript has a Math.random() function, which will return a random decimal number between 0 and 1. You can use this function to make a random number between two given ones:
    Code (Text):
    1. Math.prototype.rand = function (min, max)
    2. {
    3.     return (max - min) * Math.random() + min;
    4. }
    Once you put this snippet in your code, just use Math.rand(6000, 12000) to generate a random number of milliseconds to wait between the two given values.
     
  3. II_warlord_II

    II_warlord_II Level III

    Joined:
    Aug 13, 2008
    Messages:
    532
    Likes Received:
    31
    Oh thanks!
    mm...what do you think about
    having a refresher for Restocking btw?
    good idea?
     
  4. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    I don't know if that's really worth it... an auto-haggler would be more useful, I think.
     
  5. II_warlord_II

    II_warlord_II Level III

    Joined:
    Aug 13, 2008
    Messages:
    532
    Likes Received:
    31
    i'm planning to use it together...
    auto refresher every 7 - 12 sec
    then i use auto haggler to buy. =)
    yes?

    the reason, i would want to use auto refresher, is because...
    me myself, can't stop refreshing!!! lol...i refreshes every 2sec or 3 sec, thinking that i might have miss something...
    so, if i make it auto...that should stop me from refreshing too quick...

    also... i want to use it in magic shop...
     
  6. domini212

    domini212 Level III

    Joined:
    Jun 30, 2008
    Messages:
    454
    Likes Received:
    7
    Did the autohaggler work?
     
  7. Heya_old

    Heya_old Level IV

    Joined:
    Mar 31, 2008
    Messages:
    928
    Likes Received:
    46
    lol i use auto haggler, and an auto refresher script that ricky helped me write :D

    heres what mine looks like:

    var SECOND = 1000 ;
    var MINUTE = 60 * SECOND ;
    var MIN = 2
    var MAX = 6
    var PERIOD = (MAX - MIN) * Math.random() + MIN * SECOND ; // random time between x - y seconds. Change MIN and MAX if you want it to refresh faster or slower.

    // refresh

    window.setTimeout( function() {window.location.reload() ;}, PERIOD);

    i'm working on adding a funtion where if it has more then 5 items, refresh between this, and less then 5 refresh alittle faster... but i can't seem to get it to work :(