Add codetest.html

This commit is contained in:
2025-11-26 19:06:22 +00:00
parent a79245a39c
commit a0a2f91c38

295
codetest.html Normal file
View File

@@ -0,0 +1,295 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Mini Web Playground</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
:root {
--bg: #050812;
--panel: #0c101c;
--accent: #ff9f43;
--border: #222a3b;
--text: #e6ecff;
--muted: #8f9bb8;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
height: 100vh;
display: flex;
flex-direction: column;
background: radial-gradient(circle at top, #10172a, #050812);
color: var(--text);
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
header {
padding: 0.75rem 1.25rem;
border-bottom: 1px solid var(--border);
display: flex;
align-items: center;
justify-content: space-between;
background: linear-gradient(90deg, #0b1020, #11172b);
}
header h1 {
margin: 0;
font-size: 1rem;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--muted);
}
header .actions {
display: flex;
gap: 0.5rem;
align-items: center;
}
button {
border: none;
border-radius: 999px;
padding: 0.4rem 0.9rem;
font-size: 0.85rem;
font-weight: 600;
letter-spacing: 0.05em;
text-transform: uppercase;
cursor: pointer;
background: var(--accent);
color: #1b1520;
box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 6px 18px rgba(0,0,0,0.45);
transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s ease;
}
button:hover {
transform: translateY(-1px);
box-shadow: 0 10px 24px rgba(0,0,0,0.6);
background: #ffb356;
}
button:active {
transform: translateY(0);
box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
main {
flex: 1;
display: flex;
min-height: 0;
}
.pane {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
border-left: 1px solid var(--border);
}
.pane:first-child {
border-left: none;
}
.pane-header {
padding: 0.5rem 0.75rem;
border-bottom: 1px solid var(--border);
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.1em;
color: var(--muted);
background: rgba(0,0,0,0.35);
display: flex;
align-items: center;
justify-content: space-between;
}
.editors {
display: grid;
grid-template-rows: auto auto auto;
gap: 0;
flex: 1;
min-height: 0;
background: radial-gradient(circle at top left, #161b31, #050812);
}
.editor-block {
display: flex;
flex-direction: column;
min-height: 0;
border-bottom: 1px solid var(--border);
}
.editor-block:last-child {
border-bottom: none;
}
.editor-label {
padding: 0.35rem 0.75rem;
font-size: 0.7rem;
text-transform: uppercase;
letter-spacing: 0.12em;
color: var(--muted);
background: rgba(5, 8, 18, 0.92);
border-bottom: 1px solid rgba(255,255,255,0.03);
}
textarea {
flex: 1;
min-height: 0;
width: 100%;
resize: none;
border: none;
padding: 0.5rem 0.75rem;
background: rgba(3, 6, 17, 0.9);
color: var(--text);
font-family: "JetBrains Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
font-size: 0.85rem;
line-height: 1.4;
border-radius: 0;
outline: none;
}
textarea:focus {
box-shadow: inset 0 0 0 1px rgba(255, 159, 67, 0.6);
background: rgba(7, 10, 24, 0.95);
}
iframe {
flex: 1;
border: none;
background: white;
}
.hint {
font-size: 0.75rem;
color: var(--muted);
}
@media (max-width: 900px) {
main {
flex-direction: column;
}
.pane {
height: 50%;
}
}
</style>
</head>
<body>
<header>
<h1>Web Code Playground</h1>
<div class="actions">
<span class="hint">Edit HTML, CSS, JS → click Run</span>
<button id="runBtn">Run ▶</button>
</div>
</header>
<main>
<!-- Left: editors -->
<section class="pane">
<div class="pane-header">
<span>Code</span>
</div>
<div class="editors">
<div class="editor-block">
<div class="editor-label">HTML</div>
<textarea id="htmlCode" spellcheck="false">
<h1>Hello, Web Playground!</h1>
<p>Edit the HTML, CSS, and JS, then hit <strong>Run</strong>.</p>
<button id="clickMe">Click me</button>
<div id="output"></div>
</textarea>
</div>
<div class="editor-block">
<div class="editor-label">CSS</div>
<textarea id="cssCode" spellcheck="false">
body {
font-family: system-ui, sans-serif;
padding: 2rem;
background: radial-gradient(circle at top, #1f2937, #020617);
color: #e5e7eb;
}
h1 {
color: #fbbf24;
}
button {
padding: 0.4rem 0.8rem;
border-radius: 6px;
border: none;
background: #22c55e;
color: #022c22;
font-weight: 600;
cursor: pointer;
}
button:hover {
background: #4ade80;
}
</textarea>
</div>
<div class="editor-block">
<div class="editor-label">JavaScript</div>
<textarea id="jsCode" spellcheck="false">
document.getElementById("clickMe").addEventListener("click", () => {
const out = document.getElementById("output");
out.textContent = "Button clicked at " + new Date().toLocaleTimeString();
});
</textarea>
</div>
</div>
</section>
<!-- Right: preview -->
<section class="pane">
<div class="pane-header">
<span>Preview</span>
</div>
<iframe id="preview"></iframe>
</section>
</main>
<script>
function runCode() {
const html = document.getElementById("htmlCode").value;
const css = document.getElementById("cssCode").value;
const js = document.getElementById("jsCode").value;
const iframe = document.getElementById("preview");
const doc = iframe.contentDocument || iframe.contentWindow.document;
const fullDoc = `
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
${css}
</style>
</head>
<body>
${html}
<script>
${js.replace(/<\/script>/gi, "<\\/script>")}
<\/script>
</body>
</html>`;
doc.open();
doc.write(fullDoc);
doc.close();
}
// Run once on load
window.addEventListener("load", runCode);
// Hook up button
document.getElementById("runBtn").addEventListener("click", runCode);
</script>
</body>
</html>