-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
131 lines (114 loc) · 4.36 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
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
<html>
<head>
<link rel="icon" href="./favicon.png" type="image/png">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="title" content="Dat Utils">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
<link rel="stylesheet" href="/assets/css/bootstrap.min.css">
<title>Dat Utils – Installer</title>
<style>
html {
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";
}
body {
font-size: 14px;
}
:root {
--blue: #536DFE !important;
}
.container {
max-width: 512px;
padding: 64px 64px 32px 64px;
}
.btn {
border-radius: 32px;
}
.btn {
padding-left: 24px;
padding-right: 24px;
}
label {
line-height: 2rem;
}
.row {
margin: 8px;
}
.row .col-sm {
margin: 8px;
}
</style>
</head>
<body>
<div class="container text-center">
<img class="mb-4" src="/favicon.ico" alt="" width="48" height="48">
<h1 class="h2 mb-2 font-weight-bold">Dat Utils</h1>
<h2 class="h4 mb-4 font-weight-normal text-muted">Utility functions for the <a href="dat://beakerbrowser.com/docs/apis/dat.html" target="_blank">DatArchive API</a></h2>
<p>Copy files from one archive to another, check if a file exists, add files or directories in deep paths.</p>
<div class="row">
<div class="col-sm text-center">
<a href="/README.md">Learn More</a>
</div>
<div class="col-sm text-center">
<a href="/REFERENCE.md">Reference</a>
</div>
<div class="col-sm text-center">
<a href="/src/index.js">View Code</a>
</div>
</div>
<div class="card">
<div id="card-content" class="card-body">
<div class="card-title">Add this module to your Dat site!</div>
<p class="text-sm text-muted">Where do you want <code>dat-utils.js</code> to be saved? Specify a valid pathname.</p>
<label for="pathname-input" class="sr-only">Pathname</label>
<input type="text" id="pathname-input" class="form-control" value="/modules/dat-utils.js" placeholder="/modules/dat-utils.js" required>
<div class="checkbox mb-2 mt-2">
<label>
<input id="checkbox-override" type="checkbox" checked value="override"> Override previous installation
</label>
</div>
<button id="install-button" class="btn btn-primary" type="submit">Install Module</button>
</div>
</div>
<p class="mt-4 text-muted"><a href="/LICENSE.md">MIT License</a> – <a href="dat://profile-krismuniz.hashbase.io/" target="_blank">Kristian Muñiz</a> Ⓒ 2018</p>
</div>
<script type="module" defer>
import * as utils from '/src/index.js'
const $ = (s) => document.querySelector(s)
if (window.DatArchive) {
async function init () {
const source = new DatArchive(window.location.toString())
const newPath = $('#pathname-input').value || '/modules/dat-utils.js'
const target = await DatArchive.selectArchive({
title: 'Select your Dat App',
buttonLabel: 'Select',
filter: {
isOwner: true
}
})
const confirmationMessage = `
<code>dat-utils</code> has been installed in <a href="${target.url}${newPath}"><code>${newPath}</code></a>!
`
const install = async () => {
return await utils.copyFile(source, target, '/src/index.js', {
encoding: 'utf8',
new_path: newPath
})
}
if (await utils.fileExists(target, '/modules/dat-utils.js')) {
await install()
$('#card-content').innerHTML = confirmationMessage
} else {
if ($('#checkbox-override').checked) {
await install()
$('#card-content').innerHTML = confirmationMessage
}
}
}
$('#install-button').addEventListener('click', init)
}
</script>
</body>
</html>