-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
57 lines (54 loc) · 1.33 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
(function () {
const oldScripts = document.querySelectorAll('script');
for (let script of oldScripts) {
Object.defineProperty(script, 'src', {
set(v) {
console.log(v);
return v;
},
get() {
return this.src
}
})
}
const RealHTMLScriptElement = HTMLScriptElement
Object.defineProperty(Document.prototype, 'realCreateElement', {
value: Document.prototype.createElement
})
Object.defineProperty(Document.prototype, 'createElement', {
value: function (tagName) {
const realResult = this.realCreateElement(tagName);
if(tagName === 'script') {
realResult.addEventListener('load', function () {
console.log('script load');
console.dir(this);
// console.log('script content', this.innerHTML)
})
const srcDesc = Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src')
Object.defineProperty(realResult, 'realSrc', {
get: srcDesc.get,
set: srcDesc.set
})
Object.defineProperty(realResult, 'src', {
set(v) {
console.log(v);
this.realSrc = v;
return v;
},
get() {
return this.realSrc
}
})
}
return realResult
},
configurable: true,
enumerable: true,
writable: true
})
const tt = document.createElement('script')
tt.src = 'http://127.0.0.1:8080/test.js';
document.body.appendChild(tt);
})()
*/