mirror of
https://git.mirrors.martin98.com/https://github.com/cilame/v_jstools
synced 2025-08-16 14:15:56 +08:00
add
This commit is contained in:
parent
6aecd060f1
commit
492557c543
103
inject.js
103
inject.js
@ -1367,4 +1367,105 @@ chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) {
|
|||||||
}
|
}
|
||||||
sendResponse({})
|
sendResponse({})
|
||||||
});
|
});
|
||||||
chrome.extension.sendMessage({getcookie:true, domain:document.domain}, function(res){})
|
chrome.extension.sendMessage({getcookie:true, domain:document.domain}, function(res){})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 由于 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);
|
||||||
|
}()
|
||||||
|
}()
|
||||||
|
`)
|
Loading…
x
Reference in New Issue
Block a user