This commit is contained in:
cilame 2022-10-10 21:33:53 +08:00
parent 47ffbd755b
commit 220248c0f2

View File

@ -1732,99 +1732,4 @@ chrome.extension.sendMessage({getcookie:true, domain:document.domain}, function(
// 由于 chrome.storage.local.get 是一个异步操作所以导致读配置结束的回调执行时head 已经加载完毕
// 如果一些 script 在 head 之中加载就可能挂钩不到最原始的函数,但是直接修改代码又太重,所以这里简单挂钩几个非常核心的函数
// 供给我后续开发使用,这些挂钩默认存在,只有在关闭插件时才不会进行挂钩操作。
inject_script(`
!function(){
var saf;
;(function(){
var $toString = Function.toString
, cacheI = []
, cacheS = []
, idxI = [].indexOf.bind(cacheI)
, pushI = [].push.bind(cacheI)
, pushS = [].push.bind(cacheS)
Object.defineProperty(Function.prototype, 'toString', {
"enumerable": !1, "configurable": !0, "writable": !0,
"value": function toString() {
return typeof this == 'function' && cacheS[idxI(this)] || $toString.call(this);
}
})
function safe_func(func, name){
if (-1 == idxI(func)){
pushI(func)
pushS(\`function \${name || func.name || ''}() { [native code] }\`)
}
return func
};
safe_func(Function.prototype.toString, 'toString')
saf = safe_func
})();
window.vilame_getter = window.vilame_getter || {}
!function(){
// hook ajax
try{ var _desc = Object.getOwnPropertyDescriptors(XMLHttpRequest.prototype).open; window.vilame_getter.v_open = _desc.value }catch(e){ return }
var _new_val = saf(function open(){
return window.vilame_getter.v_open.apply(this, arguments)
})
try{ Object.defineProperty(XMLHttpRequest.prototype, 'open', { value: _new_val, enumerable: _desc['enumerable'], configurable: _desc['configurable'], writable: _desc['writable'], }) }catch(e){ }
}();
!function(){
try{ var _desc = Object.getOwnPropertyDescriptors(XMLHttpRequest.prototype).send; window.vilame_getter.v_send = _desc.value }catch(e){ return }
var _new_val = saf(function send(){
return window.vilame_getter.v_send.apply(this, arguments)
})
try{ Object.defineProperty(XMLHttpRequest.prototype, 'send', { value: _new_val, enumerable: _desc['enumerable'], configurable: _desc['configurable'], writable: _desc['writable'], }) }catch(e){ }
}();
!function(){
try{ var _desc = Object.getOwnPropertyDescriptors(XMLHttpRequest.prototype).setRequestHeader; window.vilame_getter.v_setRequestHeader = _desc.value }catch(e){ return }
var _new_val = saf(function setRequestHeader(){
return window.vilame_getter.v_setRequestHeader.apply(this, arguments)
})
try{ Object.defineProperty(XMLHttpRequest.prototype, 'setRequestHeader', { value: _new_val, enumerable: _desc['enumerable'], configurable: _desc['configurable'], writable: _desc['writable'], }) }catch(e){ }
}();
!function(){
try{ var _desc = Object.getOwnPropertyDescriptors(HTMLFormElement.prototype).submit; window.vilame_getter.v_submit = _desc.value }catch(e){ return }
var _new_val = saf(function submit(){
return window.vilame_getter.v_submit.apply(this, arguments)
})
try{ Object.defineProperty(HTMLFormElement.prototype, 'submit', { value: _new_val, enumerable: _desc['enumerable'], configurable: _desc['configurable'], writable: _desc['writable'], }) }catch(e){ }
}()
!function(){
try{ var _desc = Object.getOwnPropertyDescriptors(Element.prototype).setAttribute; window.vilame_getter.v_setAttribute = _desc.value }catch(e){ return }
var _new_val = saf(function setAttribute(){
return window.vilame_getter.v_setAttribute.apply(this, arguments)
})
try{ Object.defineProperty(Element.prototype, 'setAttribute', { value: _new_val, enumerable: _desc['enumerable'], configurable: _desc['configurable'], writable: _desc['writable'], }) }catch(e){ }
}()
!function(){
// hook fetch
window.vilame_getter.v_fetch = window.fetch
window.fetch = saf(function fetch(){
return window.vilame_getter.v_fetch.apply(this, arguments)
})
window.vilame_getter.v_Request = function(){}
window.Request = function(_Request) {
var bind = Function.bind;
var unbind = bind.bind(bind);
function instantiate(constructor, args) {
return new (unbind(constructor, null).apply(null, args));
}
var names = Object.getOwnPropertyNames(_Request);
for (var i = 0; i < names.length; i++) {
if (names[i]in Request)
continue;
var desc = Object.getOwnPropertyDescriptor(_Request, names[i]);
Object.defineProperty(Request, names[i], desc);
}
function Request(url, config) {
window.vilame_getter.v_Request(arguments)
return instantiate(_Request, arguments)
}
Request.prototype = _Request.prototype
return saf(Request);
}(Request);
}()
}()
`)
// 构造了调试注入功能,所以前面的钩子删除