我正在尝试编写一个小的 Greasemonkey 脚本来更改页面上出现的一些元素的值(通过 DOM 修改)。
我只是一个 Greasemonkey 用户,我没有 JavaScript 经验。我收到此错误:(the expression is not a legal expression.
行:结果 =...)
我也想知道是否还有需要更正的错误。
这是我的脚本:
// ==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);