hook demo
// ==UserScript==
// @name hook demo
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1
// @description try to take over the world!
// @author You
// @run-at document-start
// @match https://bbs.tampermonkey.net.cn/demo/hook.html
// @grant none
// ==/UserScript==
let hookGlobalFunc=window.globalFunc;
// hook普通全局变量
window.globalFunc=function(p){
return hookGlobalFunc("hook "+p);
}
let hookGlobalObject=window.globalObject;
// hook原型链
let hookPrototypeFunc=hookGlobalObject.prototype.prototypeFunc;
hookGlobalObject.prototype.prototypeFunc = function (p) {
hookPrototypeFunc("hook"+p);
}
window.globalObject=function(){
let ret=new hookGlobalObject();
let hookFunc=ret.func;
// hook对象中的方法
ret.func=function(p){
return hookFunc("hook"+p);
}
let hookThisFunc=ret.thisFunc;
// hook对象中的方法
let tmpI=0;
ret.thisFunc=function(p){
return hookThisFunc.apply(this,["hook"+p]);
}
return ret;
}
let hookAnonymous=window.anonymous;
// hook匿名
let i = 0;
setInterval(() => {
i++;
}, 1000);
window.anonymous=function(anonymous){
return hookAnonymous(function () {
document.querySelector('#object-anonymous').innerHTML = "hook第" + i + "次";
});
}