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
// Define the prompts
const prompts = [
"How are you today?",
"What's your favorite color?",
"Tell me a joke.",
];
// Function to generate HTML for the prompt selector
function generatePromptSelector() {
const options = prompts.map(prompt => `<option value="${prompt}">${prompt}</option>`).join("");
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prompt Selector</title>
<style>
body { font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; }
select, button { font-size: 16px; margin: 10px 0; }
#result { margin-top: 20px; font-weight: bold; }
</style>
</head>
<body>
<h1>Prompt Selector</h1>
<div id="prompt-selector-container">
<select id="promptSelect">
<option value="">Select a prompt...</option>
${options}
</select>
<br>
<button id="submitBtn">Submit</button>
<div id="result"></div>
</div>
<script>
function handlePromptSelection() {
const select = document.getElementById('promptSelect');
const result = document.getElementById('result');
const selectedPrompt = select.value;
if (selectedPrompt) {
result.textContent = \`Selected prompt: \${selectedPrompt}\`;
} else {
result.textContent = "Please select a prompt.";
}
}
document.getElementById('submitBtn').addEventListener('click', handlePromptSelection);
</script>
</body>
</html>
`;
}
// HTTP handler function
export async function promptSelectorHandler(req) {
const html = generatePromptSelector();
return new Response(html, {
headers: { "Content-Type": "text/html" },
});
}