-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinject.js
More file actions
68 lines (58 loc) · 1.79 KB
/
inject.js
File metadata and controls
68 lines (58 loc) · 1.79 KB
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
58
59
60
61
62
63
64
65
66
67
68
/*var Attribute_Array = ['src','href','srcset']
var CONFIG = {
query: location.search.split('?')[1].split('&').map((e, ind) => {if (ind==0) return '';return e.split('=').map((b,i)=>i==0?(ind==1?'?':'&')+b:b).join('=')}).join(''),
url: new URLSearchParams(location.search).get('url')
}
CONFIG.url+=CONFIG.query
window.XMLHttpRequest.prototype.open = new Proxy(window.XMLHttpRequest.prototype.open, {
construct(g, a) {
if (a[1]) a[1] = rewriteURL(a[1])
return Reflect.construct(g, a)
}
})
function rewriteURL(url) {
var Url = new URL(CONFIG.url)
url = url.replace(/^\/\//g, Url.protocol+'//')
if (url.startsWith('http')) return '/proxy?url='+url;
url = '/proxy?url=https://'+Url.hostname+(url.startsWith('/')?url:'/'+url)
console.log(url)
return url
}
window.Element.prototype.setAttribute = new Proxy(window.Element.prototype.setAttribute, {
apply(t, g, a) {
if (Attribute_Array.indexOf(a[0].toLowerCase())>-1) {
g.dataset['proxy_'+a[0]] = a[1]
if (a[0]=='srcset') return Reflect.apply(t, g, a)
a[1] = rewriteURL(a[1])
return Reflect.apply(t, g, a)
}
return Reflect.apply(t, g, a)
}
})
window.Element.prototype.getAttribute = new Proxy(window.Element.prototype.getAttribute, {
apply(t, g, a) {
if (Attribute_Array.indexOf(a[0].toLowerCase())>-1) {
var c = g.dataset['proxy_'+a[0]]||Reflect.apply(t, g, a)
return c||''
}
return Reflect.apply(t, g, a)||''
}
})
Attribute_Array.forEach(attr => {
Object.defineProperty(window.Element, attr, {
get() {
return this.getAttribute(attr)
},
set(val) {
return this.setAttribute(attr, val)
}
})
})
document.currentScript.remove()*/
var $Rhodium = {}
$Rhodium.get = function(obj) {
if (obj==window.location) {
return {}
}
return obj
}