gpt4 book ai didi

windows - 有没有办法重新加载 greasemonkey 脚本?

转载 作者:可可西里 更新时间:2023-11-01 10:29:52 25 4
gpt4 key购买 nike

有没有办法从 greasemonkey 重新加载脚本?

例如:当我进入某个特定网站时,greasemonkey 中的脚本可以正常工作,但是当我更改页面时(我猜是网站中的 asp),脚本不会重新加载以生效...

我该如何解决?

最佳答案

将您的 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
}

关于windows - 有没有办法重新加载 greasemonkey 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3042264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com