-2

I am trying to figure out how to refresh the page after the dom loads. If the dom loads and there is not a specific text on the page, it refreshes and keeps looping till that text is found.

// ==UserScript==
// @name       My Fancy New Userscript
// @namespace  http://use.i.E.your.homepage/
// @version    0.1
// @description  enter something useful
// @match      http://stackoverflow.com/questions/8192126/clicking-a-button-on-a-page-using-a-greasemonkey-userscript-in-chrome/8192413#8192413
// @copyright  2012+, You
// @require    http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
// ==/UserScript==

function available() {
  var nodeList = document.querySelectorAll('.table');
  if (nodeList[0].innerHTML.indexOf( "Not available." ) != -1) {
    Location.reload();
    else {
     alert("Hello! I am an alert box!!"); 
    }
  }
}

$(function() {
  available();
});
  • that sounds a bit dodgy, will it not just result in a never ending redirect loop? – diggersworld May 23 '14 at 18:50
  • not if the text is found, but what difference would it make, there is no guarantee that text will ever appear. Also, you should post examples of what you have tried. – Justin E May 23 '14 at 19:07
  • Added my code so far. Tampermonkey is not letting me enable the script for some reason. – user3670037 May 23 '14 at 19:51

2 Answers2

0

To reload the page with javascript:

Location.reload();

You'll need some way of checking for your bit of text as well. Without seeing your DOM structure I can't give an accurate answer to that aspect.

diggersworld
  • 12,770
  • 24
  • 84
  • 119
0

Location must be lower case.

location.reload(); 


By the way, passing a true as a param means that the page will load from the server instead than loading from caché.

Josep Alsina
  • 2,762
  • 1
  • 16
  • 12