-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.html
93 lines (77 loc) · 3.29 KB
/
get.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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MemePI</title>
<link rel="stylesheet" type="text/css" href="shoelace.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="support.css">
</head>
<body>
<script type="text/javascript">
var http = require("http")
var {inspect} = require("util")
function displayFrame(){
var url = document.getElementById('url').value
// document.getElementById('iframe').innerHTML = `<iframe src="${url}" style="width:100vw; height:80vh; left:0;border:none;"></iframe>`
// var req = new XMLHttpRequest();
// req.open('GET', url, false);
// req.send(null);
// var headers = req.getAllResponseHeaders()
frame = document.getElementById('iframe')
frame = frame.contentWindow || frame.contentDocument.document || frame.contentDocument;
frame.document.open()
http.get(url, (res) => {
var {statusCode, headers} = res
var type = headers["content-type"] || headers["Content-type"] || headers["Content-Type"]
let heads = ""
for (key in headers){
let adding = `${key}: ${headers[key]}\n`
heads += adding
}
document.getElementById('headers').innerHTML = heads
document.getElementById('status').innerHTML = statusCode
if (statusCode !== 200) {
let msg = `HTTP error: ${statusCode}<br>${url}`
frame.document.write(msg)
res.resume()
return
}
res.setEncoding("utf8")
let file = ""
res.on('data', (chunk) => {
file += chunk
})
res.on('end', ()=> {
file += type !== "text/html" ? "<style>@font-face {font-family: 'Inconsolata';src: url('./Inconsolata/Inconsolata-Regular.ttf');}body{font-family: 'Inconsolata';}</style>": ""
frame.document.write(file)
})
})
}
</script>
<div class="row">
<div class="col-10 offset-1">
<h1>View <i class="fa fa-camera-retro"></i></h1>
<div class="input-group">
<input type="text" id="url" value="http://">
<button type="button" class="button" onclick="displayFrame()">Check out url</button>
</div>
</div>
</div>
<div class="row">
<div class="col-10 offset-1">
<h3>Headers</h3>
<pre id="headers"></pre>
<h5>Status</h5>
<pre id="status"></pre>
</div>
</div>
<div class="row">
<div class="col-10 offset-1">
<h3>Browser content</h3>
<div id="err"></div>
<iframe class="iframe" id="iframe" width="100%"></iframe>
</div>
</div>
</body>
</html>