-
Notifications
You must be signed in to change notification settings - Fork 45
/
index.html
43 lines (41 loc) · 1.58 KB
/
index.html
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
<!doctype html>
<html>
<head>
<title> My profile page </title>
</head>
<body>
<script>
var source = 'https://raw.githubusercontent.com/wizardamigosinstitute/peer-wizardamigosinstitute/master/public/browser/bundle.js'
ajax(source, function fetchScript (data) {
var script = document.createElement('script')
script.setAttribute('id', 'public/browser/bundle.js')
script.innerHTML = data
document.body.appendChild(script)
})
/************************************************************************
HELPER
************************************************************************/
function ajax (params, callback) {
var url = typeof params === 'string' ? params : params.url
var method = params.method || (params.data ? 'POST': 'GET')
var body = params.data
var H = params.headers ? params.headers : params.body ? {
'X-Requested-With' :'XMLHttpRequest',
'Content-Type' :'application/x-www-form-urlencoded'
} : {}
var xhr = new XMLHttpRequest()
xhr.open(method, url)
for (var key in H) xhr.setRequestHeader(key, H[key])
xhr.onload = xhr.onerror = function (response) {
var Hjson = {}, h = xhr.getAllResponseHeaders()
;(h.match(/([^\n\r:]+):([^\n\r]+)/g)||[]).forEach(function(item){
var tmp = item.split(': ')
Hjson[tmp[0]] = tmp[1]
})
if (callback) callback(this.response, response, xhr, Hjson)
}
xhr.send(body||null)
}
</script>
</body>
</html>