如何在AJAX-Request之后加载greasemonkey脚本 [英] How to load a greasemonkey script after AJAX-Request

查看:102
本文介绍了如何在AJAX-Request之后加载greasemonkey脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的greasemonkey脚本,可以进行一些简单的dom操作。在加载DOM之后加载greasemonkey脚本,这很好,因此它适用于初始页面。但是在这个网站上(它是推特;-))页面的一部分在xmlhttprequest点击后被加载,这部分没有被我的greasemonkeyscript操纵。

I have a simple greasemonkey script that makes some simple dom manipulation. The greasemonkey script is loaded after the DOM is loaded, that's fine so fare and it does work for the initial Page. But on this site (it's twitter ;-) ) parts of the page get loaded after a click by xmlhttprequest and this part did not get manipulated by my greasemonkeyscript.

在加载xmlhttprequest之后或者在请求更改DOM之后,是否有可能再次运行脚本?

Is there a simple possibility to run the script again after the xmlhttprequest is loaded or after the DOM is changed by the request?

推荐答案

谢谢霍华德。这是正确的方向。

Thanks Howard. It was the way in the right direction.

很难找到一个在minifyied脚本上劫持函数的正确入口点。但是我发现twitter脚本中有一个哈欠。它在Ajax请求之后调用window.onPageChange。 (我想知道这是否是javascript中常见的最佳实践,如果其他人也这样做?)我确实在 http://userscripts.org/scripts/review/47998 确实使用这个可能性来附加事件。

It's quite hard to find the right entry point to hijack a function on a minifyied script. But I found that there is a huck in the twitter script. It does call window.onPageChange after the Ajax request. (I wonder if this is a common best practice in javascript and if other do this as well?) I did found some code on http://userscripts.org/scripts/review/47998 wich does use this posibility to attach events.

        if (typeof unsafeWindow.onPageChange === 'function') {
        var _onPageChange = unsafeWindow.onPageChange;
        unsafeWindow.onPageChange = function(){
            _onPageChange();
            filter();
        };
    } else {
        unsafeWindow.onPageChange = filter;
    }

这篇关于如何在AJAX-Request之后加载greasemonkey脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆