有没有办法从greasemonkey重新加载脚本?
例如: 当我进入某个特定的网站时,来自greasemonkey的脚本可以正常工作,但是当我更改页面时(我想在网站上输入asp),脚本不会重新加载生效...
我该如何解决?
答案 0 :(得分:2)
将Greasemonkey代码包装在函数中,然后设置文档更改事件处理程序来调用它。像这样......
/*--- To "refire" our Greasemonkey code on AJAX changes, we wrap it in
a function and call it on a DOM change event.
*/
var zGbl_DOM_ChangeTimer = '';
var bGbl_ChangeEventListenerInstalled = false;
/*--- Run everything after the document has loaded. Avoids race-
conditions and excessive "churn".
*/
window.addEventListener ("load", MainAction, false);
function MainAction ()
{
if (!bGbl_ChangeEventListenerInstalled)
{
bGbl_ChangeEventListenerInstalled = true;
/*--- Notes:
(1) If the ajax loads to a specific node, add this
listener to that, instead of the whole body.
(2) iFrames may require different handling.
*/
document.addEventListener ("DOMSubtreeModified", HandleDOM_ChangeWithDelay, false);
}
//--- ****************************
//--- *** YOUR CODE GOES HERE. ***
//--- ****************************
}
function HandleDOM_ChangeWithDelay (zEvent)
{
/*--- DOM changes will come hundreds at a time, we wait a fraction
of a second after the LAST change in a batch.
*/
if (typeof zGbl_DOM_ChangeTimer == "number")
{
clearTimeout (zGbl_DOM_ChangeTimer);
zGbl_DOM_ChangeTimer = '';
}
zGbl_DOM_ChangeTimer = setTimeout (function() { MainAction (); }, 222); //-- 222 milliseconds
}
答案 1 :(得分:0)
Greasemonkey应该适用于每个页面加载,所以我认为您遇到的问题是由于用于相关用户脚本的@include / @ exclude规则。你能指点我们这个用户脚本的来源吗?请问你在问题中提到的两个网页网址?