This repository has been archived by the owner on Apr 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
skybin.html
189 lines (165 loc) · 5.03 KB
/
skybin.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
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
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>SkyBin | Decentralized Pastebin powered by Sia Skynet</title>
<script>
function generateUUID() {
let uuid = ''
const cs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < 16; i++) {
uuid += cs.charAt(Math.floor(Math.random() * cs.length));
}
return uuid;
}
function save() {
var snippet = document.getElementById("snippet").value
var button = document.getElementById("save-trigger")
button.classList.add("loading")
var blob = new Blob(
[
"<html><head>" +
'<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>' +
"<title>Welcome To Skybin</title></head><body><pre>" +
// Escape HTML entities, including unicode and tags.
snippet.replace(/[\u00A0-\u9999<>\&]/g, function(i) {
return '&#'+i.charCodeAt(0)+';';
}) +
"</pre></body></html>"
],
{ type: "text/html" }
)
var formData = new FormData()
formData.append("file", blob)
const uuid = generateUUID()
fetch(`/skynet/skyfile/${uuid}?filename=skybin.html`, {
method: "POST",
body: formData
})
.then(response => response.json())
.then(result => {
button.classList.remove("loading")
const parts = window.location.hostname.split('.');
const domain = parts.slice(-2).join('.');
var newLink = document.createElement("a")
newLink.href = `https://${domain}/${result.skylink}`
newLink.classList.add("skylink")
newLink.setAttribute("target", "_blank")
newLink.textContent = newLink.href;
document.getElementById("skylinks").appendChild(newLink)
var linkBreak = document.createElement("br")
document.getElementById("skylinks").appendChild(linkBreak)
})
.catch(error => {
button.classList.remove("loading")
console.error("Error:", error)
})
}
</script>
<style type="text/css">
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
"Segoe UI Symbol";
color: #4a5568;
background-color: #fff;
}
h1 {
font-size: 48px;
font-weight: 500;
margin-top: 40px;
margin-bottom: 10px;
}
.wrapper {
display: flex;
height: calc(100vh - 40px);
flex-direction: column;
align-items: center;
justify-content: center;
}
.caps {
font-size: 14px;
font-weight: 600;
text-transform: uppercase;
color: #57b560;
}
.snippet-wrapper {
margin-top: 30px;
background: #ffffff;
box-shadow: 20px 20px 60px #cfcfcf, -20px -20px 60px #ffffff;
overflow: hidden;
border-radius: 20px;
}
#snippet {
padding: 40px;
border: none;
background: transparent;
}
.cta {
margin-top: 40px;
}
.btn {
cursor: pointer;
display: flex;
align-items: center;
padding: 20px 40px;
background: #57b560;
border: none;
color: white;
font-size: 16px;
border-radius: 8px;
font-weight: 600;
}
.btn:hover {
background: #59ad61;
}
.btn:active {
background: #57b560;
}
.btn>svg {
padding-right: 8px;
}
.loading {
background: gray !important;
cursor: not-allowed;
}
#skylinks {
padding-top: 40px;
}
#skylinks>a {
padding-top: 20px;
display: block;
color: #4a5568;
font-size: 18px;
}
</style>
</head>
<body>
<div class="wrapper">
<h1>skybin</h1>
<span class="caps" style="font-size: 16px;">Pastebin, Decentralized & Encrypted.</span>
<div class="snippet-wrapper">
<textarea id="snippet" rows="20" cols="80" placeholder="Paste your snippet here"></textarea>
</div>
<br />
<div class="cta">
<button id="save-trigger" class="btn" type="button" onclick="save()">
<svg width="16" height="16" viewBox="0 0 16 16">
<title>web-hyperlink</title>
<g fill="#ffffff">
<path
d="M13,5.142v2.136C13.595,7.625,14,8.263,14,9v2c0,1.103-0.897,2-2,2H8c-1.103,0-2-0.897-2-2V9 c0-1.103,0.897-2,2-2h1V5H8C5.794,5,4,6.794,4,9v2c0,2.206,1.794,4,4,4h4c2.206,0,4-1.794,4-4V9C16,7.141,14.721,5.589,13,5.142z">
</path>
<path fill="#ffffff"
d="M8,1H4C1.794,1,0,2.794,0,5v2c0,1.859,1.279,3.411,3,3.858V8.722C2.405,8.375,2,7.737,2,7V5 c0-1.103,0.897-2,2-2h4c1.103,0,2,0.897,2,2v2c0,1.103-0.897,2-2,2H7v2h1c2.206,0,4-1.794,4-4V5C12,2.794,10.206,1,8,1z">
</path>
</g>
</svg>
Generate Skynet Link
</button>
</div>
<div id="skylinks"></div>
<span style="margin-top: auto;" class="caps">Powered by Sia Skynet</span>
</div>
</body>
</html>