有什么用?
做油猴插件时,有些功能需要通过覆盖源程序的代码实现,不过有些程序比较鸡贼,会通过调用函数的 toString() 属性以检测函数是否覆盖 w(゚Д゚)w
于是就有了这段代码,通过直接覆盖 Function.prototype.toString ,彻底阻断这种检测方式。
Github
https://github.com/SolomonLeon/toString_hack
示例
alert.toString() // 'function alert() { [native code] }'
alert = disguisef(alert, ()=>{return "0"}) // 覆盖原函数
alert.toString() // 'function alert() { [native code] }'
alert.toString.toString() // 'function toString() { [native code] }'
兼容
chrome 和 firefox 均可用。