mirror of
https://git.mirrors.martin98.com/https://github.com/cilame/v_jstools
synced 2025-08-14 23:06:14 +08:00
add
This commit is contained in:
parent
2abcfe7de2
commit
304873cb8b
@ -12,6 +12,9 @@ function html_script_replacer(body, replacer, url){
|
||||
if (!script.children.length){
|
||||
continue
|
||||
}
|
||||
if (script.attribs.type != 'text/javascript' && script.attribs.type !== undefined){
|
||||
continue
|
||||
}
|
||||
var jscode = ''
|
||||
for (var j = 0; j < script.children.length; j++) {
|
||||
jscode += script.children[j].data
|
||||
|
@ -16,12 +16,7 @@
|
||||
function make_fake_window(){
|
||||
if (window.globalThisWindow){ return window.globalThisWindow }
|
||||
var _win = {}
|
||||
var win = new Proxy(_win, {
|
||||
has: function(a,b){ return true },
|
||||
set: function(a,b,c){ return filter_log('set', b, c), window[b]=c },
|
||||
get: function(a,b){
|
||||
if (!(b in window) && typeof b != 'symbol'){ throw ReferenceError(b + ' is not defined') }
|
||||
var r, t = true;
|
||||
function mainobj(b, r){
|
||||
switch(b){
|
||||
case 'window':
|
||||
case 'self':
|
||||
@ -52,16 +47,33 @@
|
||||
case 'location': r = make_cache_hooker(location, 'window.location'); break
|
||||
default: r = window[b]; break
|
||||
}
|
||||
if (!(b == Symbol.unscopables || b == Symbol.toStringTag || b == Symbol.toPrimitive) && t){ filter_log('window', 'get', b, r) }
|
||||
return r
|
||||
}
|
||||
var win = new Proxy(_win, {
|
||||
has: function(a,b){ return true },
|
||||
set: function(a,b,c){ return filter_log('window set', b, c), window[b]=c },
|
||||
get: function(a,b){
|
||||
var r = mainobj(b)
|
||||
if (!(b == Symbol.unscopables || b == Symbol.toStringTag || b == Symbol.toPrimitive)){ filter_log('window', 'get', b, r) }
|
||||
return r
|
||||
},
|
||||
})
|
||||
var interceptor = new Proxy(_win, {
|
||||
has: function(a,b){ return true },
|
||||
set: function(a,b,c){ return filter_log('window set', b, c), window[b]=c },
|
||||
get: function(a,b){
|
||||
if (!(b in window) && typeof b != 'symbol'){ throw ReferenceError(b + ' is not defined') } // win 和 interceptor 的区别在这里
|
||||
var r = mainobj(b)
|
||||
if (!(b == Symbol.unscopables || b == Symbol.toStringTag || b == Symbol.toPrimitive)){ filter_log('window', 'get', b, r) }
|
||||
return r
|
||||
},
|
||||
})
|
||||
window.globalThisWindow = _win
|
||||
return Object.defineProperty(_win, 'v_run', {set:function(v){ v(win) }})
|
||||
return Object.defineProperty(_win, 'v_run', {set:function(v){ v.call(win, interceptor) }})
|
||||
}
|
||||
return make_fake_window()
|
||||
})().v_run = function(win){
|
||||
with (win){
|
||||
})().v_run = function(inter){
|
||||
with (inter){
|
||||
/////////////////////////////////////////
|
||||
|
||||
|
||||
@ -70,7 +82,8 @@ with (win){
|
||||
|
||||
|
||||
// 将需要被 window hook 的代码放在这里面
|
||||
|
||||
console.log(this == window)
|
||||
console.log(window.a)
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user