<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Code Display Page</title>
<style>
body {
margin: 0;
padding: 0;
font-family: 'Courier New', monospace;
background-color: #1e1e1e;
color: #d4d4d4;
}
.container {
max-width: 960px;
margin: 40px auto;
padding: 20px;
background-color: #2d2d2d;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}
h1 {
text-align: center;
margin-bottom: 20px;
color: #ffffff;
}
pre {
overflow-x: auto;
background-color: #1e1e1e;
padding: 20px;
border-radius: 6px;
border: 1px solid #444;
}
code {
font-family: 'Courier New', monospace;
font-size: 14px;
color: #c5c8c6;
}
.copy-btn {
display: block;
margin: 10px auto 0;
padding: 10px 20px;
font-size: 14px;
cursor: pointer;
background-color: #007acc;
color: white;
border: none;
border-radius: 5px;
}
.copy-btn:hover {
background-color: #005f99;
}
</style>
</head>
<body>
<div class="container">
<h1>My Code</h1>
<pre><code id="code-block">
// Paste your code here
function greet() {
console.log("Hello, world!");
}
greet();
</code></pre>
<button class="copy-btn" onclick="copyCode()">Copy Code</button>
</div>
<script>
function copyCode() {
const code = document.getElementById('code-block').innerText;
navigator.clipboard.writeText(code).then(() => {
alert('Code copied to clipboard!');
}).catch(err => {
alert('Failed to copy code: ' + err);
});
}
</script>
</body>
</html>