我的用户脚本的任务非常简单 - 通过XHR桥接功能监听XHR请求,处理收到的数据并将其返回。当然,一切都是透明的。拦截来自GreaseMonkey脚本的AJAX(XHR)请求
我碰到这个答复How can I intercept XMLHttpRequests from a Greasemonkey script?来到SO - 这提供了以下的代码片段:
(function(open) {
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
this.addEventListener("readystatechange", function() {
console.log(this.readyState);
}, false);
open.call(this, method, url, async, user, pass);
};
})(XMLHttpRequest.prototype.open);
代码工作时,通过萤火推预期。但是,它不会在Greasemonkey脚本中做任何事情。
在进一步的搜索,我碰到另一个回答:how intercept xhr with greasemonkey - 其中提到:
Greasmonkey和3.X的Firefox目前不支持“原型” - 属性。请看下面的票信息 http://greasemonkey.devjavu.com/ticket/164
我有两个基本查询:
- 这是否适用于Fx的v3.5.x以及? (注意:devjavu.com上的门票链接不可访问)
- 什么是签名
(function(){})()
用Javascript表示。 (请耐心,我不是高级JS的专家)。
继托马斯的回答(至Q#2),这里是别人的指针: http://www.hunlock.com/blogs/Functional_Javascript#quickIDX5 – Jumper 2009-12-08 17:37:03