This commit is contained in:
cilame 2021-10-22 23:30:04 +08:00
parent 2abcfe7de2
commit 304873cb8b
2 changed files with 54 additions and 38 deletions

View File

@ -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

View File

@ -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)