Using JavaScript and Greasemonkey to reload just one tab in Firefox?

12,195

Solution 1

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);

Solution 2

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:
12,195

Related videos on Youtube

Neil Spencer
Author by

Neil Spencer

Updated on September 18, 2022

Comments

  • Neil Spencer
    Neil Spencer over 1 year

    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?

    • Laoujin
      Laoujin over 11 years
      http://ww.bbc.co.uk doesn't exist?
    • Neil Spencer
      Neil Spencer over 11 years
      Sorry - that was just a typo
  • Neil Spencer
    Neil Spencer over 11 years
    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
    Neil Spencer over 11 years
    Brilliant - many thanks for this. The script is now indeed only operating on the page I want rather than all pages.