Quelques techniques classiques à utiliser notamment dans GreaseMonkey.
if (document.location.href.match(new RegExp("myRegex"))) myfunc()
function getNode(xpathStmt, node) { return document.evaluate( xpathStmt, node, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue; } var myXPath = "/html/body/form/table/tbody/tr[2]/td[2]/span"; var myElement = getNode(myXPath, document);
document.getElementById() document.getElementsByClassName() document.getElementByName() document.getElementByTagName() document.getElementByTagNameNS()
el.focus() el.blur() el.click()
NB : Javascript étant monoprocess, les instructions de type sleep ou des boucles de traitements simples sont à proscrire.
setTimeout(fn, delay_ms)
.id = setInterval(fn, delay_ms)
.clearInterval(id)
.function test() {alert("plop");} var id = setInterval(test, 3000); setTimeout("clearInterval(id)", 13000);
Ressource : http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/