This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
85 lines (82 loc) · 2.69 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
<html>
<head>
<!-- Fun fact: this file was mostly generated by GPT -->
<title>Text Surfer</title>
<script src="https://cdn.tailwindcss.com?plugins=typography"></script>
<style>
/* Loader animation */
.dot-animation {
display: flex;
align-items: center;
justify-content: center;
}
.dot {
margin-right: 0.3rem;
width: 0.8rem;
height: 0.8rem;
background-color: #4299e1;
border-radius: 50%;
animation: dot-animation 1s infinite;
}
.dot:nth-child(2) {
animation-delay: 0.3s;
}
.dot:nth-child(3) {
animation-delay: 0.6s;
}
@keyframes dot-animation {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
/* Remove backticks around inline code */
code::before {
content: '' !important
}
code::after {
content: '' !important
}
</style>
</head>
<body>
<div class="container mx-auto max-w-2xl">
<h1 class="text-2xl text-center font-bold mt-4">Ask me a question</h1>
<div class="flex items-center justify-center mt-4 mb-8">
<input type="text" class="w-2/3 p-2 border border-gray-400 rounded-lg" id="text" placeholder="Ask me a question" />
<button class="p-2 ml-2 bg-blue-500 text-white rounded-lg" id="summarize">Answer</button>
</div>
<article class="prose lg:prose-sm mt-4 mx-auto" id="summary"></article>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js"></script>
<script>
const summarizeButton = document.getElementById('summarize')
const textInput = document.getElementById('text')
const summaryDiv = document.getElementById('summary')
const markdown = new showdown.Converter()
const loading = '<div class="dot-animation mb-8"><div class="dot"></div><div class="dot"></div><div class="dot"></div></div>'
textInput.addEventListener("keydown", (event) => {
if (event.keyCode === 13) {
summarizeButton.click()
}
})
summarizeButton.addEventListener('click', async () => {
try {
summaryDiv.innerHTML = loading
const text = textInput.value
const response = await fetch(`/answer?question=${text}`)
md = await response.text()
summaryDiv.innerHTML = markdown.makeHtml(md)
} catch (error) {
console.error(error)
summaryDiv.innerHTML = '<p class="text-center font-bold text-xl">Something went wrong. Please try again.</p>'
}
})
</script>
</body>
</html>