playground.shiny.space/echo-test.html
Lucas 7a4fa4b312 Fix dark mode flash by inlining critical script
- Move dark mode detection to inline script in HTML head
- Prevents white flash in Firefox by applying theme before render
- Clean up redundant code in dark-mode.js
- Apply fix to all HTML pages for consistent behavior

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-14 04:09:18 +02:00

90 lines
No EOL
3.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Echo Test</title>
<link rel="stylesheet" href="styles.css">
<script>
// Apply dark mode immediately to prevent flash
if (localStorage.getItem('theme') === 'dark') {
document.documentElement.setAttribute('data-theme', 'dark');
}
</script>
</head>
<body>
<button class="dark-mode-toggle" onclick="toggleDarkMode()">🌙</button>
<h1>Echo Test</h1>
<p>Enter some text and click submit to test the echo API endpoint.</p>
<div class="section">
<form id="echoForm">
<div class="form-group">
<label for="textInput">Enter your text:</label>
<input type="text" id="textInput" name="text" placeholder="Type something here..." required>
</div>
<button type="submit" id="submitBtn">Submit</button>
<button type="button" onclick="clearResponse()">Clear</button>
</form>
<div id="responseField" class="response-field">
Response will appear here...
</div>
</div>
<div class="back-link">
<a href="index.html">← Back to Home</a>
</div>
<script>
document.getElementById('echoForm').addEventListener('submit', async function(e) {
e.preventDefault();
const textInput = document.getElementById('textInput');
const responseField = document.getElementById('responseField');
const submitBtn = document.getElementById('submitBtn');
const text = textInput.value.trim();
if (!text) {
responseField.innerHTML = '<span class="error">Please enter some text</span>';
return;
}
// Show loading state
submitBtn.disabled = true;
responseField.innerHTML = '<span class="loading">Sending...</span>';
try {
const formData = new FormData();
formData.append('text', text);
const response = await fetch('/api/echo', {
method: 'POST',
body: formData
});
if (response.ok) {
const data = await response.text();
responseField.innerHTML = `<span class="response">${data}</span>`;
} else {
responseField.innerHTML = '<span class="error">Error: ' + response.status + '</span>';
}
} catch (error) {
responseField.innerHTML = '<span class="error">Network error occurred</span>';
console.error('Error:', error);
} finally {
submitBtn.disabled = false;
}
});
function clearResponse() {
document.getElementById('responseField').innerHTML = 'Response will appear here...';
document.getElementById('textInput').value = '';
}
</script>
<script src="dark-mode.js"></script>
</body>
</html>