greasemonkey - JavaScript error on small script -
i trying write small greasemonkey script change value of few elements when appear on page (through dom modification).
i greasemonkey user, , have no experience in javascript. error: the expression not legal expression. (line: result =...)
i'd know if there more errors need correct.
here 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);
it complains value of path not valid xpath selector. can see, you're passing value foo3 means tag <foo3> - not want. try //*[@id='foo3'] instead, see e.g. http://ejohn.org/blog/xpath-css-selectors/ more xpath examples.
Comments
Post a Comment