Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am new to Greasemonkey and javascript but have found the script below to reload a page every 5 minutes.

// ==UserScript==
// @name        Auto Reload Protopage
// @namespace   http://blog.monstuff.com/archives/cat_greasemonkey.html
// @description Reload pages every 5 minutes
// @include     http://ww.bbc.co.uk
    // @grant               none
// ==/UserScript==

// based on code by Julien Couvreur
// and included here with his gracious permission

var numMinutes = 5;
window.setTimeout("document.location.reload();", numMinutes*60*1000);

This works but it reloads all the open tabs every 5 minutes and not just the one specified in the @include statement.

Is there any way of doing this?

share|improve this question
    
http://ww.bbc.co.uk doesn't exist? –  Laoujin Oct 25 '12 at 22:33
    
Sorry - that was just a typo –  Neil Spencer Oct 27 '12 at 18:36

2 Answers 2

up vote 3 down vote accepted

That code has a corrupt metadata block, spaces are critical for that block, and extra spaces at the beginning of a line can break it -- causing the script to fire for all pages (the default behavior).

Update: The appearance of a corrupt block may just be a display bug here at SuperUser. Will investigate in a bit.
Updatier: The corrupt block is real, the OP's code is indented by a mix of tabs and spaces, which fooled SU's raw-post editor, but not the final display.

Also, the @include directive is specifying a webpage that doesn't exist. ww., versus www.. That line should be:

// @include     http://www.bbc.co.uk/

Or possibly:

// @include     http://www.bbc.co.uk/*

if you want more than just the home page effected.

Putting it all together and using setTimeout in the recommended way (Avoid use of "auto eval()"):

// ==UserScript==
// @name        Auto Reload Protopage
// @namespace   http://blog.monstuff.com/archives/cat_greasemonkey.html
// @description Reload pages every 5 minutes
// @include     http://www.bbc.co.uk/
// @grant       none
// ==/UserScript==

// based on code by Julien Couvreur
// and included here with his gracious permission

var numMinutes = 5;
setTimeout (location.reload, numMinutes*60*1000);
share|improve this answer
    
Brilliant - many thanks for this. The script is now indeed only operating on the page I want rather than all pages. –  Neil Spencer Oct 27 '12 at 18:35
    
You're welcome. If/since this solves the issue, please check the check-mark next to this answer. –  Brock Adams Oct 27 '12 at 20:11

I'm not sure how to do this in Javascript, but Firefox has an addon called ReloadEvery. Install it, restart FF and then right click on the page and choose ReloadEvery and a time.

share|improve this answer
1  
Yes - but then every time I open Firefox and go to the website I need to activate ReloadEvery. What I would like is for the reload to be automatically activated just by going to the page. The javascript above does this but also reloads all other tabs that are open. –  Neil Spencer Oct 25 '12 at 20:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.