-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt-input.html
208 lines (184 loc) · 6.17 KB
/
prompt-input.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!DOCTYPE html>
<html>
<head>
<title>Prompts</title>
<style>
:root {
--bg-color: #ffffff;
--text-color: #000000;
--button-bg: #eeeeee;
--button-border: #cccccc;
--textarea-bg: #f8f8f8;
--textarea-border: #cccccc;
}
/* Light Mode (Default) */
body {
background-color: var(--bg-color);
color: var(--text-color);
}
button {
width: 4em;
height: 1.5em;
background-color: var(--button-bg);
color: var(--text-color);
border: 1px solid var(--button-border);
border-radius: 3px;
}
button:hover {
background-color: lightgreen;
}
textarea {
width: 100%;
font-size: 1em;
font-family: monospace;
background-color: var(--textarea-bg);
color: var(--text-color);
border: 1px solid var(--textarea-border);
border-radius: 3px;
resize: vertical;
}
.textareaContainer {
margin-top: 1em;
display: flex; /* use flexbox for layout */
align-items: flex-start; /* align items to the top */
}
.textareaContainer textarea {
flex-grow: 1; /* textarea takes up available space */
margin-right: 0.7em; /* add some spacing between textarea and buttons */
margin-bottom: 0; /* remove default margin */
}
.buttonContainer {
display: flex;
flex-direction: column; /* stack buttons vertically */
justify-content: flex-start; /* align buttons to the top */
}
.buttonContainer button {
margin-bottom: 1em; /* add space between buttons */
}
.buttonContainer button:last-child {
margin-bottom: 0; /* remove margin from the last button */
}
#notification {
position: fixed;
top: 10px;
left: 50%;
transform: translateX(-50%);
padding: 10px 20px;
border-radius: 3px;
z-index: 1000;
display: none; /* initially hidden */
color: black;
font-family: monospace;
}
#notification.show {
display: block; /* make it visible */
background-color: lightgreen;
}
#notification.error {
display: block; /* make it visible */
background-color: salmon;
}
/* Dark Mode */
@media (prefers-color-scheme: dark) {
:root {
--bg-color: #121212;
--text-color: #ffffff;
--button-bg: #333333;
--button-border: #555555;
--textarea-bg: #222222;
--textarea-border: #555555;
}
button:hover {
background-color: darkgreen;
}
}
</style>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text fill='black' y='.9em' font-size='90'>⏎</text></svg>" media="(prefers-color-scheme: light)">
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text fill='white' y='.9em' font-size='90'>⏎</text></svg>" media="(prefers-color-scheme: dark)">
</head>
<body>
<!-- basic prompt (customise prompt to your needs) -->
<div class="textareaContainer">
<textarea rows="4"></textarea>
<div class="buttonContainer">
<button class="send-to-localhost-button">Send</button>
<button class="duplicate-button">Copy</button>
</div>
</div>
<!-- basic prompt (customise prompt to your needs) -->
<div class="textareaContainer">
<textarea rows="4"></textarea>
<div class="buttonContainer">
<button class="send-to-localhost-button">Send</button>
<button class="duplicate-button">Copy</button>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.body.addEventListener('click', function(event) {
if (event.target.classList.contains('send-to-localhost-button')) {
const textarea = event.target.closest('.textareaContainer').querySelector('textarea'); // traverse to .textareaContainer
const text = textarea.value;
const notification = document.createElement('div');
notification.id = 'notification';
notification.textContent = 'sending ...';
document.body.appendChild(notification);
notification.classList.add('show');
// customize port number to your needs
fetch('http://localhost:4242', {
method: 'POST',
body: text,
headers: {
'Content-Type': 'text/plain'
}
})
.then(response => {
if (!response.ok) {
console.error('http error', response);
notification.textContent = `error: ${response.status} ${response.statusText}`;
notification.classList.add('error');
} else {
console.log('text sent to localhost:4242');
notification.textContent = 'sent successfully';
notification.classList.remove('error');
}
return response.text();
})
.then(data => {
console.log('response from server:', data);
textarea.focus();
})
.catch(error => {
console.error('error sending text to localhost:4242:', error);
notification.textContent = 'error sending data';
notification.classList.add('error');
textarea.focus();
})
.finally(() => {
// remove notification after 4 seconds
setTimeout(() => {
notification.classList.remove('show');
notification.classList.remove('error');
document.body.removeChild(notification);
}, 4000);
});
}
if (event.target.classList.contains('duplicate-button')) {
const container = event.target.closest('.textareaContainer'); // traverse to .textareaContainer
const newContainer = container.cloneNode(true);
const originalTextarea = container.querySelector('textarea');
const newTextarea = newContainer.querySelector('textarea');
newTextarea.value = originalTextarea.value;
container.parentNode.insertBefore(newContainer, container.nextSibling);
}
});
// set focus on the first textarea and move the cursor to the end
const firstTextarea = document.querySelector('textarea');
if (firstTextarea) {
firstTextarea.focus();
firstTextarea.selectionStart = firstTextarea.selectionEnd = firstTextarea.value.length;
}
});
</script>
</body>
</html>