const prompts = [
"How are you today?",
"What's your favorite color?",
"Tell me a joke.",
];
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>
`;
}
export async function promptSelectorHandler(req) {
const html = generatePromptSelector();
return new Response(html, {
headers: { "Content-Type": "text/html" },
});
}