【发布时间】:2013-12-02 19:47:43
【问题描述】:
下面的代码可以在 FireFox 原生函数中重新定义(在 Chrome 中你可以只做 document.func = newfunc 或与下面相同但没有注入代码的事情),注入对于小的新函数是可以的,但如果需要的话为了与用户脚本中的其他函数或变量进行通信,需要注入用户脚本的整个代码,
所以我正在寻找一种方法,可以在不注入的情况下从 UserScript 的空间覆盖\重新定义\等 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);
【问题讨论】:
标签: javascript firefox greasemonkey redefine