-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
209 lines (204 loc) · 6.97 KB
/
index.html
File metadata and controls
209 lines (204 loc) · 6.97 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Strunk & White Style Checker</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Playwrite+DE+Grund:wght@100..400&family=The+Girl+Next+Door&display=swap"
rel="stylesheet"
/>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: "Georgia", "Times New Roman", serif;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 3rem 1rem;
background: #f9f6f1;
}
#container {
width: 100%;
max-width: 900px;
display: flex;
flex-direction: column;
border: 1px solid #e0d9cf;
}
#header {
padding: 1.5rem 2rem 0.75rem;
border-bottom: 1px solid #e0d9cf;
}
#header h1 {
font-size: 1.25rem;
font-weight: normal;
font-style: italic;
letter-spacing: 0.02em;
}
#header p {
font-size: 0.8rem;
color: #777;
margin-top: 0.25rem;
}
#messages {
overflow-y: auto;
padding: 2rem;
display: flex;
flex-direction: column;
gap: 1.5rem;
min-height: 450px;
max-height: 70vh;
}
.msg {
line-height: 1.6;
max-width: 80%;
}
.msg.user {
align-self: flex-end;
text-align: right;
font-family: "The Girl Next Door", cursive;
}
.msg.assistant {
font-family: "Playwrite DE Grund", cursive;
font-weight: 400;
font-size: 0.85rem;
}
.msg .role {
font-size: 0.7rem;
text-transform: uppercase;
letter-spacing: 0.08em;
color: #999;
margin-bottom: 0.25rem;
font-family: system-ui, sans-serif;
}
.msg .content {
white-space: pre-wrap;
}
.msg.loading .content {
color: #999;
font-style: italic;
}
#input-area {
display: flex;
gap: 1rem;
padding: 1.5rem;
border-top: 1px solid #e0d9cf;
}
#user-input {
flex: 1;
padding: 0.75rem 0;
border: none;
border-bottom: 1px solid #e0d9cf;
font-family: "The Girl Next Door", cursive;
font-size: 1rem;
outline: none;
background: transparent;
}
#user-input:focus {
border-bottom-color: #000;
}
button {
padding: 0.75rem 1.5rem;
background: #000;
color: #fff;
border: none;
font-family: system-ui, sans-serif;
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.05em;
cursor: pointer;
}
button:disabled {
opacity: 0.3;
}
</style>
</head>
<body>
<div id="container">
<div id="header">
<h1>The Elements of Style</h1>
<p>
Paste your writing for a review in the style of Strunk &
White
</p>
</div>
<div id="messages"></div>
<div id="input-area">
<input
type="text"
id="user-input"
placeholder="Paste your writing here..."
autocomplete="off"
/>
<button id="send-btn">Review</button>
</div>
</div>
<script>
const messages = document.getElementById("messages");
const userInput = document.getElementById("user-input");
const sendBtn = document.getElementById("send-btn");
let sessionId = null;
function addMessage(role, text, isLoading = false) {
const div = document.createElement("div");
div.className =
"msg " +
(role === "you" ? "user" : "assistant") +
(isLoading ? " loading" : "");
div.innerHTML =
'<div class="role">' +
role +
'</div><div class="content">' +
text +
"</div>";
messages.appendChild(div);
messages.scrollTop = messages.scrollHeight;
return div;
}
async function send() {
const text = userInput.value.trim();
if (!text) return;
userInput.value = "";
sendBtn.disabled = true;
addMessage("you", text);
const loading = addMessage(
"Strunk & White",
"Reviewing...",
true,
);
try {
const res = await fetch("/chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
message: text,
session_id: sessionId,
}),
});
const data = await res.json();
sessionId = data.session_id;
loading.querySelector(".content").textContent =
data.response;
loading.classList.remove("loading");
} catch (e) {
loading.querySelector(".content").textContent =
"Error: " + e.message;
loading.classList.remove("loading");
}
sendBtn.disabled = false;
userInput.focus();
}
sendBtn.addEventListener("click", send);
userInput.addEventListener("keydown", function (e) {
if (e.key === "Enter") send();
});
userInput.focus();
</script>
</body>
</html>