waitForKeyElements 中的这段代码有什么作用?
What does this code in waitForKeyElements do?
我在 Greasemonkey 中使用 waitForKeyElements 并且不理解这个片段:
if (!alreadyFound) {
//--- Call the payload function.
var cancelFound = actionFunction (jThis);
if (cancelFound)
btargetsFound = false;
else
jThis.data ('alreadyFound', true);
}
actionFunction
是我传入的回调。它应该只有 return undefined
除非我将它编码为 return 东西,对吗?在什么条件下我会这样做? btargetsFound
需要为 True 才能阻止 waitForKeyElements 稍后调用自身。所以 return 某种程度上意味着 "one of the elements I found, even though I found it and called the payload function on it, I still need to retry?"
是的,你的理解是正确的。另一种说法是回调可以 return true
说 "This element matches the selector, but isn't the one that I want, try again later"。我猜这是针对你想要的东西是通过多次 AJAX 调用在几个阶段构建的情况,或者类似的东西。
请注意,returning true
将导致下次计时器触发时使用相同的元素再次调用回调。
我在 Greasemonkey 中使用 waitForKeyElements 并且不理解这个片段:
if (!alreadyFound) {
//--- Call the payload function.
var cancelFound = actionFunction (jThis);
if (cancelFound)
btargetsFound = false;
else
jThis.data ('alreadyFound', true);
}
actionFunction
是我传入的回调。它应该只有 return undefined
除非我将它编码为 return 东西,对吗?在什么条件下我会这样做? btargetsFound
需要为 True 才能阻止 waitForKeyElements 稍后调用自身。所以 return 某种程度上意味着 "one of the elements I found, even though I found it and called the payload function on it, I still need to retry?"
是的,你的理解是正确的。另一种说法是回调可以 return true
说 "This element matches the selector, but isn't the one that I want, try again later"。我猜这是针对你想要的东西是通过多次 AJAX 调用在几个阶段构建的情况,或者类似的东西。
请注意,returning true
将导致下次计时器触发时使用相同的元素再次调用回调。