-
Notifications
You must be signed in to change notification settings - Fork 0
/
landing.js
177 lines (174 loc) · 4.92 KB
/
landing.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
module.exports = (
`
<div>
<head>
<title>fffetch</title>
<link href="https://fonts.googleapis.com/css?family=Space+Mono" rel="stylesheet">
<style>
* {
box-sizing: border-box;
}
body, html {
font-family: 'Space Mono';
}
h2 {
font-family: 'Space Mono', monospace;
}
.container {
max-width: 500px;
margin: 0 auto;
padding: 20px;
}
.content {
padding-top: 30px;
}
a {
color: #000;
}
svg {
width: 30px;
height: 30px;
}
.nounderline {
text-decoration: none;
}
.mt1 {
margin-top: 1rem;
}
.ml05 {
margin-left: 0.5rem;
}
.s-i {
font-family: 'Space Mono';
outline: none;
padding: 1rem;
}
.s-s {
width: 32%;
}
.logger {
width: 100%;
margin-top: 30px;
height: 140px;
padding: 5px;
overflow: scroll;
background-color: #000;
}
.logger span {
font-size: 0.7rem;
color: white;
display: block;
}
.logger span.error {
color: red;
}
.logger span.success {
color: green;
}
form label span {
padding-bottom: 30px;
}
form button {
border: 0;
cursor: pointer;
padding: 12px 18px;
background-color: black;
color: white;
}
pre {
color: light-grey;
font-family: 'Space Mono';
font-size: 11px;
border: 1px solid black;
padding-top: 1em;
margin: 15px 0 15px 0;
width: 585px;
}
</style>
</head>
<div class='container'>
<h2>
fffetch
</h2>
<div class='content'>
fetch an array of urls to prepopulate facebook open graph data
</div>
<div style='margin-top: 20px;'>
example json file:
<pre>
{
"urls": [
"https://thecouch.nyc",
"https://kevingreen.sucks"
]
}
</pre>
</div>
<div style='margin-top: 20px;'>
<form id='form'>
<div style='margin-bottom: 10px;'>
<label for='current_namespace' style='width: 108%'>
<input required class='js-file s-i' style='width: 100%; padding-left: 0;' name='file' type='file' />
</label>
</div>
<div class='mt1'>
<button type='submit' id='magic'>Pew pew pew</button>
</div>
</form>
</div>
<div class='logger'>
<div id='logger'></div>
<span>this is the logger...</span>
</div>
<div class='content'>
<p>Created by <a href="https://thecouch.nyc">The Couch</a></p>
<p><a href="https://github.com/the-couch/fffetch">Contribute</a></p>
</div>
</div>
<script>
var form = document.getElementById('form')
var logger = document.getElementById('logger')
var magic = document.getElementById('magic')
var jsonForm = {}
form.addEventListener('submit', (e) => {
e.preventDefault()
var file = form.elements.file.files[0]
magic.innerHTML = 'Doing stuff...'
var fr = new FileReader()
fr.onload = function(e) {
var parsedFile = JSON.parse(fr.result)
var urls = parsedFile.urls
urls.forEach(function(url) {
fetch('/api/fetch', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({url: url})
}).then((response) => {
return response.json()
}).then((json) => {
if (json.error) {
var span = document.createElement('span')
span.classList.add('error')
span.innerHTML = json.msg
let logP = logger.parentNode
logP.insertBefore(span, logger)
magic.innerHTML = 'Try again'
} else {
var span = document.createElement('span')
span.innerHTML = 'successfully fetched ' + url
let logP = logger.parentNode
logP.insertBefore(span, logP.childNodes[0])
magic.innerHTML = 'pew pew pew'
}
})
})
}
fr.readAsText(file)
})
</script>
</div>
`
)