-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdynamic_index.js
48 lines (39 loc) · 1.49 KB
/
dynamic_index.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
<html>
<body>
<h1 id="bucket"></h1>
<table id="listing" style="border-spacing: 2em 0em;">
<tr><th>Object</th><th>Size (bytes)</th><th>Date</th></tr>
</table>
<script>
let bucket = (window.location.href.match(/^.*\//))[0];
function listingXMLDocToTableStr(xmldoc) {
let eValue = (e, tag) =>
e.getElementsByTagName(tag)[0].firstChild.nodeValue;
return Array
.from(xmldoc.getElementsByTagName('Contents'))
.map(c =>
({'name' : eValue(c, 'Key'),
'size' : eValue(c, 'Size'),
'date' : eValue(c, 'LastModified')}))
.filter(c =>
! c.name.match(/.*_ameta$/))
.map(c =>
`<tr>
<td><a href="${c.name}">${c.name}</a></td>
<td>${c.size}</td>
<td>${c.date}</td>
</tr>`)
.join('\n');
};
document.getElementById('bucket').innerHTML = bucket;
fetch(bucket)
.then(response =>
response.text())
.then(str =>
(new window.DOMParser()).parseFromString(str, "text/xml"))
.then(xmldoc =>
document.getElementById('listing').innerHTML +=
listingXMLDocToTableStr(xmldoc));
</script>
</body>
</html>