-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfriendship2.html
More file actions
378 lines (334 loc) · 15.3 KB
/
friendship2.html
File metadata and controls
378 lines (334 loc) · 15.3 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>friendship2 ٩(◕‿◕。)۶</title>
<style>
@font-face {
font-family: 'heart font';
src: url(fonts/heartfont.ttf) format('truetype');
}
body {
padding-left: 2rem !important;
color: rgb(93, 22, 55);
margin: 0;
padding: 0;
}
/** hide things that don't have the showiniframe class */
.iframe > :not(.showiniframe) {
display: none;
}
button {
/* prevent double tap to zoom */
touch-action: manipulation;
}
.break-all {
word-break: break-all;
}
#bracelet {
margin-top: 50px;
height: 400px;
display: block;
margin-left: auto;
margin-right: auto;
}
#tie-button {
margin-top: 20px;
padding: 10px 20px;
font-size: 16px;
}
#buttons {
display: flex;
justify-content: center;
margin-top: 20px;
}
</style>
</head>
<body>
<h1><a href="?">friendship2 (◕‿◕)</a></h1>
<p>make a friendship bracelet for someone please (´。• ω •。`) ♡</p>
<div id="meta">
</div>
<svg id="bracelet" viewBox="0 0 400 400" class="showiniframe">
<defs>
<path id="leftPath" d="M 250,400 C 250,250 100,150 100,50" stroke="black" stroke-width="2" />
<path id="rightPath" d="M 250,400 C 250,250 400,150 400,50" stroke="black" stroke-width="2" />
<path id="fullPath" d="M 100,0
A 100,100 0 1,0 100,200
A 100,100 0 1,0 100,0" fill="none" stroke="black" transform="rotate(-90 100 100)" />
</defs>
<!-- <use id="useLeftPath" href="#leftPath" />
<use id="useRightPath" href="#rightPath" /> -->
<text fill="black" font-size="20">
<textPath id="leftTextPath" href="#leftPath"></textPath>
<textPath id="rightTextPath" href="#rightPath"></textPath>
<textPath id="fullTextPath" href="#fullPath"></textPath>
</text>
</svg>
<div id="embedinstructions">
</div>
<section id="builder">
<div id="buttons">
<div id="left">
<h2>left (๑˃ᴗ˂)ﻭ</h2>
<!-- heart emojis -->
<button onclick="addToBracelet('left', '💛')">💛</button>
<button onclick="addToBracelet('left', '💚')">💚</button>
<button onclick="addToBracelet('left', '💙')">💙</button>
<button onclick="addToBracelet('left', '💜')">💜</button>
<button onclick="addToBracelet('left', '💖')">💖</button>
<button onclick="addToBracelet('left', '💕')">💕</button>
<button onclick="addToBracelet('left', '💞')">💞</button>
<button onclick="addToBracelet('left', '💓')">💓</button>
<button onclick="addToBracelet('left', '💗')">💗</button>
<button onclick="addToBracelet('left', '💘')">💘</button>
<button onclick="addToBracelet('left', '💝')">💝</button>
<button onclick="addToBracelet('left', '💟')">💟</button>
<button onclick="addToBracelet('left', '🔵')">🔵</button>
<button onclick="addToBracelet('left', '🔴')">🔴</button>
<button onclick="addToBracelet('left', '⚫')">⚫</button>
<button onclick="addToBracelet('left', '⚪')">⚪</button>
<button onclick="addToBracelet('left', '🔺')">🔺</button>
<button onclick="addToBracelet('left', '🔻')">🔻</button>
<button onclick="addToBracelet('left', '🔸')">🔸</button>
<button onclick="addToBracelet('left', '🔹')">🔹</button>
<button onclick="addToBracelet('left', '🔶')">🔶</button>
<button onclick="addToBracelet('left', '🔷')">🔷</button>
<button onclick="addToBracelet('left', '🟢')">🟢</button>
<button onclick="addToBracelet('left', '🟠')">🟠</button>
<button onclick="addToBracelet('left', '🟡')">🟡</button>
<button onclick="addToBracelet('left', '🟣')">🟣</button>
<button onclick="addToBracelet('left', '🟤')">🟤</button>
<button onclick="addToBracelet('left', 'A')">A</button>
<button onclick="addToBracelet('left', 'B')">B</button>
<button onclick="addToBracelet('left', 'C')">C</button>
<button onclick="addToBracelet('left', 'D')">D</button>
<button onclick="addToBracelet('left', 'E')">E</button>
<button onclick="addToBracelet('left', 'F')">F</button>
<button onclick="addToBracelet('left', 'G')">G</button>
<button onclick="addToBracelet('left', 'H')">H</button>
<button onclick="addToBracelet('left', 'I')">I</button>
<button onclick="addToBracelet('left', 'J')">J</button>
<button onclick="addToBracelet('left', 'K')">K</button>
<button onclick="addToBracelet('left', 'L')">L</button>
<button onclick="addToBracelet('left', 'M')">M</button>
<button onclick="addToBracelet('left', 'N')">N</button>
<button onclick="addToBracelet('left', 'O')">O</button>
<button onclick="addToBracelet('left', 'P')">P</button>
<button onclick="addToBracelet('left', 'Q')">Q</button>
<button onclick="addToBracelet('left', 'R')">R</button>
<button onclick="addToBracelet('left', 'S')">S</button>
<button onclick="addToBracelet('left', 'T')">T</button>
<button onclick="addToBracelet('left', 'U')">U</button>
<button onclick="addToBracelet('left', 'V')">V</button>
<button onclick="addToBracelet('left', 'W')">W</button>
<button onclick="addToBracelet('left', 'X')">X</button>
<button onclick="addToBracelet('left', 'Y')">Y</button>
<button onclick="addToBracelet('left', 'Z')">Z</button>
<button onclick="popLeft()">remove from left</button>
</div>
<div id="right">
<h2>right (≧◡≦)</h2>
<button onclick="addToBracelet('right', '💛')">💛</button>
<button onclick="addToBracelet('right', '💚')">💚</button>
<button onclick="addToBracelet('right', '💙')">💙</button>
<button onclick="addToBracelet('right', '💜')">💜</button>
<button onclick="addToBracelet('right', '💖')">💖</button>
<button onclick="addToBracelet('right', '💕')">💕</button>
<button onclick="addToBracelet('right', '💞')">💞</button>
<button onclick="addToBracelet('right', '💓')">💓</button>
<button onclick="addToBracelet('right', '💗')">💗</button>
<button onclick="addToBracelet('right', '💘')">💘</button>
<button onclick="addToBracelet('right', '💝')">💝</button>
<button onclick="addToBracelet('right', '💟')">💟</button>
<button onclick="addToBracelet('right', '🔵')">🔵</button>
<button onclick="addToBracelet('right', '🔴')">🔴</button>
<button onclick="addToBracelet('right', '⚫')">⚫</button>
<button onclick="addToBracelet('right', '⚪')">⚪</button>
<button onclick="addToBracelet('right', '🔺')">🔺</button>
<button onclick="addToBracelet('right', '🔻')">🔻</button>
<button onclick="addToBracelet('right', '🔸')">🔸</button>
<button onclick="addToBracelet('right', '🔹')">🔹</button>
<button onclick="addToBracelet('right', '🔶')">🔶</button>
<button onclick="addToBracelet('right', '🔷')">🔷</button>
<button onclick="addToBracelet('right', '🟢')">🟢</button>
<button onclick="addToBracelet('right', '🟠')">🟠</button>
<button onclick="addToBracelet('right', '🟡')">🟡</button>
<button onclick="addToBracelet('right', '🟣')">🟣</button>
<button onclick="addToBracelet('right', '🟤')">🟤</button>
<button onclick="addToBracelet('right', 'A')">A</button>
<button onclick="addToBracelet('right', 'B')">B</button>
<button onclick="addToBracelet('right', 'C')">C</button>
<button onclick="addToBracelet('right', 'D')">D</button>
<button onclick="addToBracelet('right', 'E')">E</button>
<button onclick="addToBracelet('right', 'F')">F</button>
<button onclick="addToBracelet('right', 'G')">G</button>
<button onclick="addToBracelet('right', 'H')">H</button>
<button onclick="addToBracelet('right', 'I')">I</button>
<button onclick="addToBracelet('right', 'J')">J</button>
<button onclick="addToBracelet('right', 'K')">K</button>
<button onclick="addToBracelet('right', 'L')">L</button>
<button onclick="addToBracelet('right', 'M')">M</button>
<button onclick="addToBracelet('right', 'N')">N</button>
<button onclick="addToBracelet('right', 'O')">O</button>
<button onclick="addToBracelet('right', 'P')">P</button>
<button onclick="addToBracelet('right', 'Q')">Q</button>
<button onclick="addToBracelet('right', 'R')">R</button>
<button onclick="addToBracelet('right', 'S')">S</button>
<button onclick="addToBracelet('right', 'T')">T</button>
<button onclick="addToBracelet('right', 'U')">U</button>
<button onclick="addToBracelet('right', 'V')">V</button>
<button onclick="addToBracelet('right', 'W')">W</button>
<button onclick="addToBracelet('right', 'X')">X</button>
<button onclick="addToBracelet('right', 'Y')">Y</button>
<button onclick="addToBracelet('right', 'Z')">Z</button>
<button onclick="popRight()">remove from right</button>
</div>
</div>
<input type="text" id="creator" placeholder="your name (required)" required />
<input type="text" id="recipient" placeholder="recipient's name (required)" required />
<button id="tie-button" onclick="tieBracelet()">tie bracelet</button>
</section>
<section>
<h2>others braclets ˖✧◝(⁰▿⁰)◜✧˖° </h2>
newest to oldest
<ul>
</ul>
</section>
<footer>
<a href="/">← max bo</a>
<a href="https://github.com/MaxwellBo/maxwellbo.github.io/blob/master/friendship2.html">source</a>
</footer>
<script type="module">
// tag the document with an iframe CSS class if it's being rendered in an iframe
if (window.self !== window.top) {
// set iframe on the body
document.body.classList.add('iframe');
}
const urlParams = new URLSearchParams(window.location.search);
const braceletId = urlParams.get('id');
if (braceletId) {
fetchBracelet(braceletId);
}
function addToBracelet(side, emoji) {
if (side === 'left') {
document.getElementById('leftTextPath').textContent += emoji;
} else if (side === 'right') {
document.getElementById('rightTextPath').textContent += emoji;
}
}
function popLeft() {
const leftTextPath = document.getElementById('leftTextPath').textContent;
document.getElementById('leftTextPath').textContent = leftTextPath.slice(0, -1);
}
function popRight() {
const rightTextPath = document.getElementById('rightTextPath').textContent;
document.getElementById('rightTextPath').textContent = rightTextPath.slice(0, -1);
}
async function tieBracelet() {
const leftText = document.getElementById('leftTextPath').textContent;
const rightText = document.getElementById('rightTextPath').textContent;
const creator = document.getElementById('creator').value;
const recipient = document.getElementById('recipient').value;
const fullText = leftText + rightText;
if (!creator || !recipient) {
alert('please tell me your name and the recipient\'s name (。•́︿•̀。)');
return;
}
// explain that bracelet is being tied and to wait
alert('tying bracelet... please wait (´・ᴗ・ ` )');
// Send the POST request
const response = await fetch('https://mbo-friendship2.web.val.run', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
content: fullText,
creator,
recipient,
plea: "please don't abuse this, i'm just trying to make something fun (。•́︿•̀。)"
})
});
if (!response.ok) {
alert('failed to tie bracelet. please try again (。•́︿•̀。)');
return;
}
const responseData = await response.json();
alert(`bracelet tied!!! \(≧▽≦)/ ID: ${responseData.id}`);
// redirect to the new bracelet
window.location.href = `friendship2.html?id=${responseData.id}`;
}
async function fetchBracelet(id) {
const response = await fetch(`https://mbo-friendship2.web.val.run?id=${id}`, {
method: 'GET'
});
if (!response.ok) {
alert('failed to fetch bracelet. please check the ID and try again (。╯︵╰。)');
return;
}
const bracelet = await response.json();
// set the title
document.title = bracelet.content;
if (document.getElementById('leftTextPath')) {
document.getElementById('leftTextPath').remove();
}
if (document.getElementById('rightTextPath')) {
document.getElementById('rightTextPath').remove();
}
document.getElementById('fullTextPath').textContent = bracelet.content;
const useFullPath = document.createElementNS('http://www.w3.org/2000/svg', 'use');
useFullPath.setAttribute('href', '#fullPath');
document.getElementById('bracelet').appendChild(useFullPath);
// hide the builder section
document.getElementById('builder').style.display = 'none';
// add the creator, recipient and id to the meta section
const meta = document.getElementById('meta');
meta.innerHTML = `
<i>
creator: ${bracelet.creator}<br />
recipient: ${bracelet.recipient}<br />
id: ${bracelet.id}<br />
created at: ${bracelet.createdAt}
</i>
`;
// add embed instructions explaining how to iframe the bracelet
const embedInstructions = document.getElementById('embedinstructions');
embedInstructions.innerHTML = `
<p>copy and paste this code into your website to embed this bracelet</p>
<pre style="overflow-y: scroll">
<iframe src="maxbo.me/friendship2.html?id=${bracelet.id}" style="border: none;"></iframe>
</pre>
<img src="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${encodeURIComponent(window.location.href)}" />
`;
}
async function fetchBracelets() {
const response = await fetch('https://mbo-friendship2.web.val.run', {
method: 'GET'
});
if (!response.ok) {
alert('Failed to fetch bracelets. Please try again.');
return;
}
const bracelets = await response.json();
const ul = document.querySelector('ul');
ul.innerHTML = '';
// reverse the bracelets so the newest ones are at the top
bracelets.reverse();
for (const bracelet of bracelets) {
const li = document.createElement('li');
if (bracelet.id === "5212b733-6602-4074-980e-ffa83b13a75c") {
// debug
continue
}
li.innerHTML = `<a class="break-all" href="friendship2.html?id=${bracelet.id}">${bracelet.content}</a>`;
ul.appendChild(li);
}
}
fetchBracelets();
window.popLeft = popLeft;
window.popRight = popRight;
window.addToBracelet = addToBracelet;
window.tieBracelet = tieBracelet;
</script>
</body>
</html>