-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
602 lines (517 loc) · 19.9 KB
/
main.js
File metadata and controls
602 lines (517 loc) · 19.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
// GitMaster - Interactive Git Tutorial
// Main JavaScript file
// Global variables
let terminalHistory = [];
let commandsCount = 0;
let correctCommands = 0;
let errorCount = 0;
let currentQuizQuestion = 0;
let quizScore = 0;
let quizAnswered = false;
// Quiz questions data
const quizQuestions = [
{
question: "Jaką komendę używasz do sprawdzenia statusu repozytorium Git?",
options: ["git status", "git check", "git state", "git info"],
correct: 0,
explanation: "git status pokazuje aktualny stan repozytorium - zmodyfikowane, staged i nieśledzone pliki."
},
{
question: "Która komenda służy do dodania wszystkich zmian do staging area?",
options: ["git add all", "git add .", "git stage", "git prepare"],
correct: 1,
explanation: "git add . dodaje wszystkie zmienione pliki z aktualnego katalogu do staging area."
},
{
question: "Jak poprawnie zatwierdzić zmiany z komunikatem?",
options: ["git commit 'message'", "git commit -m 'message'", "git save 'message'", "git push 'message'"],
correct: 1,
explanation: "git commit -m 'message' zatwierdza zmiany z podanym komunikatem."
},
{
question: "Która komenda pobiera zmiany z zdalnego repozytorium?",
options: ["git download", "git get", "git pull", "git fetch"],
correct: 2,
explanation: "git pull pobiera i scala zmiany z zdalnego repozytorium z aktualnym branch-em."
},
{
question: "Jak poprawnie wysłać zmiany do zdalnego repozytorium?",
options: ["git push main origin", "git send origin main", "git push origin main", "git upload origin main"],
correct: 2,
explanation: "git push origin main - poprawna składnia to: git push [remote] [branch]"
}
];
// Git commands simulation
const gitCommands = {
'git status': {
output: `On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: index.html
modified: main.js
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: style.css
Untracked files:
(use "git add <file>..." to include in what will be committed)
tutorial.html
generator.html`,
correct: true,
help: "Sprawdź status repozytorium"
},
'git add .': {
output: `Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: index.html
modified: main.js
modified: style.css
new file: tutorial.html
new file: generator.html`,
correct: true,
help: "Dodaj wszystkie zmiany do stage"
},
'git commit -m "test commit"': {
output: `[main 7a8b9c2] test commit
5 files changed, 234 insertions(+), 45 deletions(-)
create mode 100644 tutorial.html
create mode 100644 generator.html`,
correct: true,
help: "Zatwierdź zmiany z komentarzem"
},
'git log --oneline': {
output: `7a8b9c2 (HEAD -> main) test commit
3f4e5d6 Fix navigation bug
2a1b3c4 Add interactive terminal
1d2e3f4 Initial commit`,
correct: true,
help: "Pokaż skróconą historię commitów"
},
'git push origin main': {
output: `Enumerating objects: 15, done.
Counting objects: 100% (15/15), done.
Delta compression using up to 8 threads
Compressing objects: 100% (12/12), done.
Writing objects: 100% (15/15), 3.45 KiB | 1.15 MiB/s, done.
Total 15 (delta 8), reused 0 (delta 0)
To github.com:user/repo.git
3f4e5d6..7a8b9c2 main -> main`,
correct: true,
help: "Wyślij zmiany do zdalnego repozytorium"
},
'git push main origin': {
output: `error: src refspec main does not match any
error: failed to push some refs to 'origin'`,
correct: false,
error: true,
help: "Zła kolejność parametrów. Poprawnie: git push origin main"
}
};
// Initialize the application
document.addEventListener('DOMContentLoaded', function() {
initializeApp();
});
function initializeApp() {
// Initialize animated background
initAnimatedBackground();
// Initialize terminal
initTerminal();
// Initialize quiz
initQuiz();
// Initialize progress tracking
updateProgress();
// Initialize animations
initAnimations();
}
// Animated background using p5.js
function initAnimatedBackground() {
new p5(function(p) {
let particles = [];
p.setup = function() {
let canvas = p.createCanvas(p.windowWidth, p.windowHeight);
canvas.parent('animatedBackground');
// Create particles
for (let i = 0; i < 50; i++) {
particles.push({
x: p.random(p.width),
y: p.random(p.height),
vx: p.random(-0.5, 0.5),
vy: p.random(-0.5, 0.5),
size: p.random(1, 3)
});
}
};
p.draw = function() {
p.clear();
// Update and draw particles
for (let particle of particles) {
particle.x += particle.vx;
particle.y += particle.vy;
// Wrap around edges
if (particle.x < 0) particle.x = p.width;
if (particle.x > p.width) particle.x = 0;
if (particle.y < 0) particle.y = p.height;
if (particle.y > p.height) particle.y = 0;
// Draw particle
p.fill(0, 255, 136, 100);
p.noStroke();
p.circle(particle.x, particle.y, particle.size);
}
// Draw connections
for (let i = 0; i < particles.length; i++) {
for (let j = i + 1; j < particles.length; j++) {
let dist = p.dist(particles[i].x, particles[i].y, particles[j].x, particles[j].y);
if (dist < 100) {
p.stroke(0, 255, 136, 50);
p.strokeWeight(0.5);
p.line(particles[i].x, particles[i].y, particles[j].x, particles[j].y);
}
}
}
};
p.windowResized = function() {
p.resizeCanvas(p.windowWidth, p.windowHeight);
};
});
}
// Terminal functionality
function initTerminal() {
const terminalInput = document.getElementById('terminalInput');
if (terminalInput) {
terminalInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
const command = terminalInput.textContent.trim();
executeCommand(command);
terminalInput.textContent = '';
}
});
terminalInput.addEventListener('input', function() {
// Prevent multiple lines
this.textContent = this.textContent.replace(/\n/g, '');
});
}
}
function executeCommand(command) {
if (!command) return;
commandsCount++;
const terminalOutput = document.getElementById('terminalOutput');
const commandData = gitCommands[command];
// Add command to history
terminalHistory.push({
command: command,
timestamp: new Date(),
correct: commandData ? commandData.correct : false
});
// Create output HTML
let outputHTML = `
<div class="mb-2">
<div class="text-neon-primary">$ ${command}</div>
`;
if (commandData) {
if (commandData.error) {
outputHTML += `<div class="text-red-400">${commandData.output}</div>`;
errorCount++;
} else {
outputHTML += `<div class="text-text-primary">${commandData.output}</div>`;
correctCommands++;
}
} else {
outputHTML += `<div class="text-yellow-400">Command not found: ${command}</div>`;
outputHTML += `<div class="text-text-muted">Type 'help' for available commands</div>`;
errorCount++;
}
outputHTML += '</div>';
outputHTML += '<div class="mt-2">$ <span id="terminalInput" contenteditable="true" class="outline-none"></span><span class="terminal-cursor">█</span></div>';
// Update terminal output
terminalOutput.innerHTML = outputHTML + terminalOutput.innerHTML;
// Re-initialize terminal input
initTerminal();
// Update statistics
updateTerminalStats();
// Update command help
updateCommandHelp(command);
// Update progress
updateProgress();
}
function updateTerminalStats() {
const commandsCountEl = document.getElementById('commandsCount');
const correctCommandsEl = document.getElementById('correctCommands');
const errorCountEl = document.getElementById('errorCount');
if (commandsCountEl) commandsCountEl.textContent = commandsCount;
if (correctCommandsEl) correctCommandsEl.textContent = correctCommands;
if (errorCountEl) errorCountEl.textContent = errorCount;
}
function updateCommandHelp(command) {
const commandHelp = document.getElementById('commandHelp');
if (!commandHelp) return;
const commandData = gitCommands[command];
if (commandData && commandData.help) {
const helpHTML = `
<div class="p-3 bg-surface rounded">
<div class="font-mono text-neon-primary">${command}</div>
<div class="text-text-muted mt-1">${commandData.help}</div>
</div>
`;
commandHelp.innerHTML = helpHTML + commandHelp.innerHTML;
// Keep only last 3 helps
const helps = commandHelp.children;
if (helps.length > 3) {
commandHelp.removeChild(helps[helps.length - 1]);
}
}
}
// Quiz functionality
function initQuiz() {
currentQuizQuestion = 0;
quizScore = 0;
quizAnswered = false;
loadQuizQuestion();
}
function loadQuizQuestion() {
if (currentQuizQuestion >= quizQuestions.length) {
showQuizResults();
return;
}
const question = quizQuestions[currentQuizQuestion];
const questionText = document.getElementById('questionText');
const quizOptions = document.getElementById('quizOptions');
const currentQuestionEl = document.getElementById('currentQuestion');
const totalQuestionsEl = document.getElementById('totalQuestions');
const quizProgress = document.getElementById('quizProgress');
if (questionText) questionText.textContent = question.question;
if (currentQuestionEl) currentQuestionEl.textContent = currentQuizQuestion + 1;
if (totalQuestionsEl) totalQuestionsEl.textContent = quizQuestions.length;
// Update progress
const progress = ((currentQuizQuestion + 1) / quizQuestions.length) * 100;
if (quizProgress) quizProgress.style.width = progress + '%';
// Load options
if (quizOptions) {
quizOptions.innerHTML = '';
question.options.forEach((option, index) => {
const optionEl = document.createElement('div');
optionEl.className = 'quiz-option p-4 border border-border rounded-lg';
optionEl.onclick = () => selectAnswer(index);
optionEl.innerHTML = `<span class="font-mono">${option}</span>`;
quizOptions.appendChild(optionEl);
});
}
// Reset next button
const nextBtn = document.getElementById('nextQuestionBtn');
if (nextBtn) {
nextBtn.disabled = true;
nextBtn.className = 'bg-neon-primary text-bg-dark px-6 py-3 rounded-lg font-semibold opacity-50 cursor-not-allowed';
}
quizAnswered = false;
}
function selectAnswer(answerIndex) {
if (quizAnswered) return;
const question = quizQuestions[currentQuizQuestion];
const options = document.querySelectorAll('.quiz-option');
const nextBtn = document.getElementById('nextQuestionBtn');
// Mark all options
options.forEach((option, index) => {
option.onclick = null;
if (index === question.correct) {
option.classList.add('correct');
} else if (index === answerIndex && index !== question.correct) {
option.classList.add('incorrect');
}
});
// Update score
if (answerIndex === question.correct) {
quizScore++;
const scoreEl = document.getElementById('quizScore');
if (scoreEl) scoreEl.textContent = quizScore;
}
// Enable next button
if (nextBtn) {
nextBtn.disabled = false;
nextBtn.className = 'bg-neon-primary text-bg-dark px-6 py-3 rounded-lg font-semibold hover-lift';
}
quizAnswered = true;
}
function nextQuestion() {
currentQuizQuestion++;
loadQuizQuestion();
}
function showQuizResults() {
const quizContent = document.getElementById('quizContent');
const quizResults = document.getElementById('quizResults');
const finalScore = document.getElementById('finalScore');
if (quizContent) quizContent.classList.add('hidden');
if (quizResults) quizResults.classList.remove('hidden');
if (finalScore) finalScore.textContent = quizScore;
// Update progress
updateProgress();
}
function restartQuiz() {
const quizContent = document.getElementById('quizContent');
const quizResults = document.getElementById('quizResults');
if (quizContent) quizContent.classList.remove('hidden');
if (quizResults) quizResults.classList.add('hidden');
initQuiz();
}
// Progress tracking
function updateProgress() {
const overallProgress = document.getElementById('overallProgress');
if (!overallProgress) return;
// Calculate progress based on various factors
let progress = 0;
// Terminal usage (max 40%)
if (commandsCount > 0) progress += Math.min(commandsCount * 2, 40);
// Quiz completion (max 30%)
if (quizQuestions.length > 0) {
progress += (quizScore / quizQuestions.length) * 30;
}
// Tutorial progress (max 30%)
// This would be updated when tutorials are completed
overallProgress.style.width = progress + '%';
// Save progress to localStorage
const progressData = {
commandsCount,
correctCommands,
errorCount,
quizScore,
currentQuizQuestion,
lastVisit: new Date().toISOString()
};
localStorage.setItem('gitmaster-progress', JSON.stringify(progressData));
}
// Load progress from localStorage
function loadProgress() {
const saved = localStorage.getItem('gitmaster-progress');
if (saved) {
const data = JSON.parse(saved);
commandsCount = data.commandsCount || 0;
correctCommands = data.correctCommands || 0;
errorCount = data.errorCount || 0;
quizScore = data.quizScore || 0;
currentQuizQuestion = data.currentQuizQuestion || 0;
updateTerminalStats();
updateProgress();
}
}
// Animations
function initAnimations() {
// Animate elements on scroll
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe elements for animation
document.querySelectorAll('.hover-lift').forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
// Typewriter effect for hero title with single-line replacement to prevent layout shift
if (typeof Typed !== 'undefined') {
const demo = document.getElementById('terminalDemo');
if (demo) {
const sequence = [
'<span class="text-text-primary">$</span> git push main origin',
'<span class="text-red-400">error: src refspec main does not match any</span>',
'<span class="text-red-400">error: failed to push some refs to \"origin\"</span>',
'<span class="text-yellow-400"># Poprawna składnia:</span>',
'<span class="text-text-primary">$</span> <span class="text-green-400">git push origin main</span>',
'<span class="text-green-400">✓ Successfully pushed to origin/main</span>'
];
// Prepare container: one line span + cursor, so text always stays in the same place
demo.innerHTML = '<span id="terminalDemoLine"></span><span class="terminal-cursor">█</span>';
const lineEl = document.getElementById('terminalDemoLine');
// Measure tallest line to set min-height and avoid any twitching
function measureTallest() {
const probe = document.createElement('div');
probe.className = 'terminal-output text-left text-neon-primary';
probe.style.position = 'absolute';
probe.style.visibility = 'hidden';
probe.style.pointerEvents = 'none';
probe.style.whiteSpace = 'pre-wrap';
probe.style.width = (demo.clientWidth || 600) + 'px';
let maxH = 0;
sequence.forEach(html => {
probe.innerHTML = html;
document.body.appendChild(probe);
maxH = Math.max(maxH, probe.offsetHeight);
document.body.removeChild(probe);
});
demo.style.minHeight = maxH + 'px';
}
measureTallest();
window.addEventListener('resize', measureTallest);
let typedInstance = null;
function typeAt(index) {
if (!lineEl) return;
if (typedInstance) {
try { typedInstance.destroy(); } catch (e) {}
}
lineEl.innerHTML = '';
typedInstance = new Typed('#terminalDemoLine', {
strings: [sequence[index]],
typeSpeed: 50,
backSpeed: 0,
showCursor: false,
smartBackspace: false,
loop: false,
onComplete: function() {
setTimeout(() => {
const next = index + 1;
if (next < sequence.length) {
typeAt(next);
}
}, 650);
}
});
}
typeAt(0);
}
}
}
// Utility functions
function scrollToSection(sectionId) {
const section = document.getElementById(sectionId);
if (section) {
section.scrollIntoView({ behavior: 'smooth' });
}
}
function toggleMobileMenu() {
// Mobile menu toggle functionality
console.log('Mobile menu toggled');
}
// Keyboard shortcuts
document.addEventListener('keydown', function(e) {
// Ctrl/Cmd + K to focus terminal
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
e.preventDefault();
const terminalInput = document.getElementById('terminalInput');
if (terminalInput) {
terminalInput.focus();
}
}
// Escape to blur terminal
if (e.key === 'Escape') {
const terminalInput = document.getElementById('terminalInput');
if (terminalInput && document.activeElement === terminalInput) {
terminalInput.blur();
}
}
});
// Load progress on page load
window.addEventListener('load', loadProgress);
// Export functions for global access
window.executeCommand = executeCommand;
window.selectAnswer = selectAnswer;
window.nextQuestion = nextQuestion;
window.restartQuiz = restartQuiz;
window.scrollToSection = scrollToSection;
window.toggleMobileMenu = toggleMobileMenu;