有没有办法重新加载 Greasemonkey 脚本?

发布于 2024-09-06 00:54:53 字数 135 浏览 5 评论 0原文

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

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

我该如何解决它?

It's there a way to reload a script from greasemonkey ?

For example:
When I enter on some specific website, the script from the greasemonkey works correctly, but when I change the page (asp in the website I guess), the script doesn't reload to take effect...

How can I solve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〃温暖了心ぐ 2024-09-13 00:54:53

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

Wrap your Greasemonkey code in a function and then set a document change event-handler to call it. Like so...

/*--- 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
}
み青杉依旧 2024-09-13 00:54:53

Greasemonkey 应该在每个页面加载上工作,所以我认为您遇到的问题是由于用于相关用户脚本的 @include/@exclude 规则造成的。您能给我们指出这个用户脚本的来源吗?以及您在问题中提到的两个页面网址?

Greasemonkey should work on every page load, so I think that the problem you are experiencing is due to the @include/@exclude rules used for the userscript in question. Can you please point us to the source of this user script? and the two page urls that you refer to in your question please?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文