Reputation: 261
I am trying to write a small Greasemonkey script to change the value of a few elements when they appear on a page (through DOM modification).
I am just a Greasemonkey user, and I have no experience in JavaScript. I get this error: the expression is not a legal expression.
(line: result =...)
I'd also like to know if there are any more errors I need to correct.
Here is my script:
// ==UserScript==
// @name myscript
// @namespace http://www.google.com
// @include http://mysite/
// @version 1
// @grant GM_addStyle
// ==/UserScript==
function waitForKeyElements (selectorTxt, actionFunction) {
if (getElementByXPath(selectorTxt) == null) {
var timeControl = setInterval (function () {
waitForKeyElements (selectorTxt, actionFunction);
},
300
);
} else {
clearInterval (timeControl);
actionFunction();
}
}
var getElementByXPath = function (path) {
result = document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
return result.singleNodeValue;
};
function myFunc (jNode) {
getElementById("foo1").setValue("foo2");
}
waitForKeyElements ("foo3", myFunc);
Upvotes: 0
Views: 135
Reputation: 214959
It complains that the value of path
is not a valid XPath selector. From what I can see, you're passing the value foo3
which means a tag <foo3>
- probably not what you want. Try //*[@id='foo3']
instead, see e.g. http://ejohn.org/blog/xpath-css-selectors/ for more xpath examples.
Upvotes: 1