Spaces:
Running
Running
manually add the snippets to the code, to make it work in my Visual Studio Code
Browse files
script.js
CHANGED
|
@@ -5,97 +5,133 @@ const codeSnippets = {
|
|
| 5 |
`<!DOCTYPE html>
|
| 6 |
<html lang="en">
|
| 7 |
<head>
|
| 8 |
-
<
|
| 9 |
-
<
|
| 10 |
-
<title>My Portfolio</title>
|
| 11 |
-
<link rel="stylesheet" href="styles.css">
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
<nav>
|
| 16 |
-
<ul>
|
| 17 |
-
<li><a href="
|
| 18 |
-
<li><a href="
|
| 19 |
-
<li><a href="#contact">Contact</a></li>
|
| 20 |
</ul>
|
| 21 |
</nav>
|
| 22 |
</header>
|
| 23 |
-
<main>
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
<
|
| 29 |
-
|
| 30 |
-
<
|
| 31 |
-
</
|
| 32 |
-
<
|
| 33 |
-
</
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
javascript: [
|
| 36 |
-
`
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
}
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
| 51 |
}
|
| 52 |
|
| 53 |
-
|
| 54 |
-
this.
|
| 55 |
-
console.log(this.name, 'score is now', this.score);
|
| 56 |
-
return this;
|
| 57 |
}
|
| 58 |
}
|
| 59 |
|
| 60 |
-
const
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
css: [
|
| 64 |
-
`.
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
padding: 2rem;
|
| 69 |
}
|
| 70 |
|
| 71 |
-
.
|
| 72 |
-
background:
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
transition: transform 0.3s ease;
|
| 76 |
}
|
| 77 |
|
| 78 |
-
.
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
}
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
object-fit: cover;
|
| 86 |
-
border-radius: 8px 8px 0 0;
|
| 87 |
}
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
}
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
}`
|
| 98 |
-
]
|
| 99 |
};
|
| 100 |
// Get all snippets as one array for "all languages" option
|
| 101 |
function getAllSnippets() {
|
|
@@ -255,45 +291,24 @@ function endGame(isCompleted = false) {
|
|
| 255 |
saveResults(language, wpm, accuracy, timeTaken);
|
| 256 |
}
|
| 257 |
}
|
| 258 |
-
|
| 259 |
-
// Save results to database
|
| 260 |
async function saveResults(language, wpm, accuracy, timeTaken) {
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
language,
|
| 269 |
-
wpm,
|
| 270 |
-
accuracy,
|
| 271 |
-
time: timeTaken
|
| 272 |
-
})
|
| 273 |
-
});
|
| 274 |
-
|
| 275 |
-
const data = await response.json();
|
| 276 |
-
if (!data.success) {
|
| 277 |
-
console.error('Failed to save results:', data.error);
|
| 278 |
-
}
|
| 279 |
-
} catch (error) {
|
| 280 |
-
console.error('Error saving results:', error);
|
| 281 |
-
}
|
| 282 |
}
|
| 283 |
|
| 284 |
-
//
|
| 285 |
async function fetchLeaderboard() {
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
}
|
| 292 |
-
return [];
|
| 293 |
-
} catch (error) {
|
| 294 |
-
console.error('Error fetching leaderboard:', error);
|
| 295 |
-
return [];
|
| 296 |
-
}
|
| 297 |
}
|
| 298 |
// Event listeners
|
| 299 |
inputField.addEventListener('input', updateDisplay);
|
|
|
|
| 5 |
`<!DOCTYPE html>
|
| 6 |
<html lang="en">
|
| 7 |
<head>
|
| 8 |
+
<title>Document</title>
|
| 9 |
+
<link rel="stylesheet" href="style.css">
|
|
|
|
|
|
|
| 10 |
</head>
|
| 11 |
<body>
|
| 12 |
+
<h1>Hello World</h1>
|
| 13 |
+
<script src="script.js"></script>
|
| 14 |
+
</body>
|
| 15 |
+
</html>`,
|
| 16 |
+
|
| 17 |
+
`<div class="container">
|
| 18 |
+
<header class="header">
|
| 19 |
<nav>
|
| 20 |
+
<ul class="nav-list">
|
| 21 |
+
<li><a href="/">Home</a></li>
|
| 22 |
+
<li><a href="/about">About</a></li>
|
|
|
|
| 23 |
</ul>
|
| 24 |
</nav>
|
| 25 |
</header>
|
| 26 |
+
<main id="main-content"></main>
|
| 27 |
+
<footer>© ${new Date().getFullYear()}</footer>
|
| 28 |
+
</div>`,
|
| 29 |
+
|
| 30 |
+
`<form id="login-form">
|
| 31 |
+
<div class="form-group">
|
| 32 |
+
<label for="email">Email</label>
|
| 33 |
+
<input type="email" id="email" required>
|
| 34 |
+
</div>
|
| 35 |
+
<div class="form-group">
|
| 36 |
+
<label for="password">Password</label>
|
| 37 |
+
<input type="password" id="password" required>
|
| 38 |
+
</div>
|
| 39 |
+
<button type="submit">Login</button>
|
| 40 |
+
</form>`
|
| 41 |
+
],
|
| 42 |
javascript: [
|
| 43 |
+
`function calculateTotal(items) {
|
| 44 |
+
return items.reduce((total, item) => {
|
| 45 |
+
return total + (item.price * item.quantity);
|
| 46 |
+
}, 0);
|
| 47 |
+
}
|
|
|
|
| 48 |
|
| 49 |
+
const cart = [
|
| 50 |
+
{ name: 'Shirt', price: 25, quantity: 2 },
|
| 51 |
+
{ name: 'Pants', price: 40, quantity: 1 }
|
| 52 |
+
];
|
| 53 |
+
|
| 54 |
+
const total = calculateTotal(cart);
|
| 55 |
+
console.log('Total:', total);`,
|
| 56 |
|
| 57 |
+
`class Person {
|
| 58 |
+
constructor(name, age) {
|
| 59 |
+
this.name = name;
|
| 60 |
+
this.age = age;
|
| 61 |
}
|
| 62 |
|
| 63 |
+
greet() {
|
| 64 |
+
console.log(\`Hello, my name is \${this.name}\`);
|
|
|
|
|
|
|
| 65 |
}
|
| 66 |
}
|
| 67 |
|
| 68 |
+
const person1 = new Person('Alice', 30);
|
| 69 |
+
person1.greet();`,
|
| 70 |
+
|
| 71 |
+
`const fetchData = async () => {
|
| 72 |
+
try {
|
| 73 |
+
const response = await fetch('api/data');
|
| 74 |
+
const data = await response.json();
|
| 75 |
+
return data;
|
| 76 |
+
} catch (error) {
|
| 77 |
+
console.error('Error:', error);
|
| 78 |
+
return null;
|
| 79 |
+
}
|
| 80 |
+
};`
|
| 81 |
+
],
|
| 82 |
css: [
|
| 83 |
+
`.container {
|
| 84 |
+
max-width: 1200px;
|
| 85 |
+
margin: 0 auto;
|
| 86 |
+
padding: 0 20px;
|
|
|
|
| 87 |
}
|
| 88 |
|
| 89 |
+
.header {
|
| 90 |
+
background: #333;
|
| 91 |
+
color: white;
|
| 92 |
+
padding: 1rem;
|
|
|
|
| 93 |
}
|
| 94 |
|
| 95 |
+
.nav-list {
|
| 96 |
+
display: flex;
|
| 97 |
+
gap: 1rem;
|
| 98 |
+
list-style: none;
|
| 99 |
+
}`,
|
| 100 |
+
|
| 101 |
+
`body {
|
| 102 |
+
font-family: 'Arial', sans-serif;
|
| 103 |
+
line-height: 1.6;
|
| 104 |
+
color: #333;
|
| 105 |
}
|
| 106 |
|
| 107 |
+
h1, h2, h3 {
|
| 108 |
+
color: #222;
|
| 109 |
+
margin-bottom: 1rem;
|
|
|
|
|
|
|
| 110 |
}
|
| 111 |
|
| 112 |
+
a {
|
| 113 |
+
color: #0066cc;
|
| 114 |
+
text-decoration: none;
|
| 115 |
+
}`,
|
| 116 |
+
|
| 117 |
+
`@keyframes fadeIn {
|
| 118 |
+
from { opacity: 0; }
|
| 119 |
+
to { opacity: 1; }
|
| 120 |
}
|
| 121 |
|
| 122 |
+
.modal {
|
| 123 |
+
position: fixed;
|
| 124 |
+
top: 0;
|
| 125 |
+
left: 0;
|
| 126 |
+
width: 100%;
|
| 127 |
+
height: 100%;
|
| 128 |
+
background: rgba(0,0,0,0.5);
|
| 129 |
+
display: flex;
|
| 130 |
+
justify-content: center;
|
| 131 |
+
align-items: center;
|
| 132 |
+
animation: fadeIn 0.3s ease;
|
| 133 |
}`
|
| 134 |
+
]
|
| 135 |
};
|
| 136 |
// Get all snippets as one array for "all languages" option
|
| 137 |
function getAllSnippets() {
|
|
|
|
| 291 |
saveResults(language, wpm, accuracy, timeTaken);
|
| 292 |
}
|
| 293 |
}
|
| 294 |
+
// Mock save results function for local testing
|
|
|
|
| 295 |
async function saveResults(language, wpm, accuracy, timeTaken) {
|
| 296 |
+
console.log('Results would be saved:', {
|
| 297 |
+
language,
|
| 298 |
+
wpm,
|
| 299 |
+
accuracy,
|
| 300 |
+
time: timeTaken
|
| 301 |
+
});
|
| 302 |
+
return { success: true };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
}
|
| 304 |
|
| 305 |
+
// Mock leaderboard data for local testing
|
| 306 |
async function fetchLeaderboard() {
|
| 307 |
+
return [
|
| 308 |
+
{ language: 'javascript', wpm: 85, accuracy: 98, time_taken: 120, created_at: new Date() },
|
| 309 |
+
{ language: 'html', wpm: 75, accuracy: 95, time_taken: 180, created_at: new Date() },
|
| 310 |
+
{ language: 'css', wpm: 65, accuracy: 92, time_taken: 150, created_at: new Date() }
|
| 311 |
+
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
}
|
| 313 |
// Event listeners
|
| 314 |
inputField.addEventListener('input', updateDisplay);
|