Javascript 从用户脚本空间重新定义Firefox中的本机浏览器功能
在FireFox中使用下面的代码,可以重新定义本机函数(在Chrome中,您可以只执行Javascript 从用户脚本空间重新定义Firefox中的本机浏览器功能,javascript,firefox,greasemonkey,redefine,Javascript,Firefox,Greasemonkey,Redefine,在FireFox中使用下面的代码,可以重新定义本机函数(在Chrome中,您可以只执行document.func=newfunc或与下面相同的操作,但不使用injectind代码),对于小的新函数,可以使用injectind代码,但是如果需要与userscript中的其他函数或变量通信,则需要插入userscript的整个代码 因此,我正在寻找一种方法,从UserScript的空间中重写\重新定义\etc FireFox中的本机函数,而无需注入 // ==UserScript== // ==/U
document.func=newfunc
或与下面相同的操作,但不使用injectind代码),对于小的新函数,可以使用injectind代码,但是如果需要与userscript中的其他函数或变量通信,则需要插入userscript的整个代码
因此,我正在寻找一种方法,从UserScript的空间中重写\重新定义\etc FireFox中的本机函数,而无需注入
// ==UserScript==
// ==/UserScript==
function doh4x()
{
window.history.__proto__.pushState = function(a, b, url) {window.location.href = url;}
}
function inject(func)
{
var source = func.toString();
var script = document.createElement('script');
script.text = "("+ source +")()";
document.head.appendChild(script);
}
inject(doh4x);
使用
unsafeWindow.history.__proto__.pushState = function (a, b, url) {
window.location.href = url;
};