Userscript in javascript/jQuery to watch a page for specific changes in link text -


i'm trying create userscript watch page changes in link text. script should:

  1. refresh after 10 seconds page if there no links present.
  2. refresh page if there links present contain keyword don't want (in example word don't care "phone").
  3. alert me when there link present doesn't contain keyword (even if there think contains said keyword). in example, word should trigger should "email", want alerted whenever there link doesn't contain word "phone".

i've come jsfiddle sort of simulate page watching script here, top section simulate random changes on page may take place. in example want alerted when keyword "email" appears, whether or not other link present.

and here horrible attempt @ trying write this. don't know why can't seem wrap head around proper logic , loop needed accomplish this. i've been on place , it's such mess it's not useful jumping off point anymore. appreciated.

var worklinks = $("td > a").length,         newlink = false,     = -1;  function reloadpage() {   settimeout(function() {     location.reload();   }, 10000); }  console.log(worklinks);  if (worklinks === 0) {    reloadpage();  } else if (worklinks > 0) {    while (newlink === false && < links) {      i++;     var links = $("td > a").eq(i).text();      if (links.indexof('phone') < -1) {       alert('new link');       newlink = true;       break;     } else {       reloadpage();     }   }   } 

alright, deryck pointed out error , found more. had few wrongly named variables. , tried loop again. time worked.

here's working jsfiddle.

here's edited code:

var worklinks = $("td > a").length;  function reloadpage() {   settimeout(function() {     location.reload();   }, 10000); }  console.log(worklinks);  if (worklinks === 0) {    reloadpage();  } else if (worklinks > 0) {    var links = $('td > a').length;    (i = 0; < links; i++) {          var links = $("td > a").eq(i).text();      if (links.indexof('phone') < 0) {       alert('new link');       break;     } else {       reloadpage();     }   }   } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -