-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
673 lines (623 loc) · 30.9 KB
/
Copy pathindex.html
File metadata and controls
673 lines (623 loc) · 30.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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<meta name="description" content="Tài liệu ôn tập phỏng vấn Java Core, Spring Boot, Kafka, Redis, Microservice, Database, Cloud, System Design với 234 câu hỏi kèm đáp án chi tiết.">
<meta name="theme-color" content="#0d0f14">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<title>Java & Spring Boot Interview Q&A — 234 câu hỏi</title>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Sora:wght@300;400;600;700&display=swap" rel="stylesheet">
<link rel="icon" type="image/png" href="favicon.png">
<link rel="apple-touch-icon" href="favicon.png">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="floating-header" id="floatingHeader">
<div class="floating-header-inner">
<div class="floating-left">
<input type="text" id="floatingSearchBox" class="floating-search" placeholder="Tìm kiếm câu hỏi...">
</div>
<div class="floating-center">
<span class="floating-label">✓ <strong id="floatDone">0</strong></span>
<span class="floating-label skip">⏭ <strong id="floatSkip">0</strong></span>
<span class="floating-divider">│</span>
<span class="floating-label total">📋 <strong id="floatCompleted">0</strong>/<strong id="floatTotal">234</strong></span>
<div class="floating-progress"><div class="floating-progress-fill" id="floatProgressFill"></div></div>
</div>
<div class="floating-right">
<button class="floating-btn" onclick="exportProgress()" data-tooltip="Export">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
</button>
<button class="floating-btn" onclick="document.getElementById('importFile').click()" data-tooltip="Import">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
</button>
<button class="floating-btn" onclick="toggleSettings(event)" data-tooltip="Settings">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
</button>
</div>
</div>
</div>
<div class="header">
<h1>☕ <span class="java">Java Core</span> & <span class="spring">Spring Boot</span> Interview</h1>
<p>Câu hỏi phỏng vấn đầy đủ · Kafka · Redis · Microservice · Database · Cloud · DevOps · System Design · ELK Stack</p>
<div class="badge-row">
<span class="badge java">Java Core</span>
<span class="badge spring">Spring Boot</span>
<span class="badge" style="background:rgba(249,115,22,0.15);color:#f97316;border:1px solid rgba(249,115,22,0.3)">🟠 Kafka</span>
<span class="badge" style="background:rgba(239,68,68,0.15);color:#ef4444;border:1px solid rgba(239,68,68,0.3)">🔴 Redis</span>
<span class="badge" style="background:rgba(56,189,248,0.15);color:#38bdf8;border:1px solid rgba(56,189,248,0.3)">🔷 Microservice</span>
<span class="badge" style="background:rgba(167,139,250,0.15);color:#a78bfa;border:1px solid rgba(167,139,250,0.3)">🗄️ Database</span>
<span class="badge" style="background:rgba(96,165,250,0.15);color:#60a5fa;border:1px solid rgba(96,165,250,0.3)">☁️ Cloud</span>
<span class="badge" style="background:rgba(168,85,247,0.15);color:#a855f7;border:1px solid rgba(168,85,247,0.3)">📊 ELK Stack</span>
<span class="badge" style="background:rgba(234,179,8,0.15);color:#eab308;border:1px solid rgba(234,179,8,0.3)">🚀 DevOps</span>
<span class="badge" style="background:rgba(251,146,60,0.15);color:#fb923c;border:1px solid rgba(251,146,60,0.3)">🔥 System Design</span>
<span class="badge count" id="totalBadge">234 câu hỏi</span>
</div>
<div class="completion-stats" id="completionStats">
<div class="stats-summary">
<span class="stats-item done-stat" id="statDone">✓ Done: <strong>0</strong></span>
<span class="stats-item skip-stat" id="statSkip">⏭ Skip: <strong>0</strong></span>
<span class="stats-divider">│</span>
<span class="stats-item total-stat" id="statTotal">📋 Tổng hoàn thành: <strong>0</strong> / <strong>234</strong></span>
</div>
<div class="stats-levels" id="statsLevels">
<button class="level-stat-btn lv-intern" id="levelBtnIntern" onclick="toggleLevelDetail('intern')">🔘 Intern: <strong>0/0</strong></button>
<button class="level-stat-btn lv-junior" id="levelBtnJunior" onclick="toggleLevelDetail('junior')">🟢 Junior: <strong>0/0</strong></button>
<button class="level-stat-btn lv-middle" id="levelBtnMiddle" onclick="toggleLevelDetail('middle')">🔵 Middle: <strong>0/0</strong></button>
<button class="level-stat-btn lv-senior" id="levelBtnSenior" onclick="toggleLevelDetail('senior')">🟠 Senior: <strong>0/0</strong></button>
<button class="level-stat-btn lv-expert" id="levelBtnExpert" onclick="toggleLevelDetail('expert')">🟣 Expert: <strong>0/0</strong></button>
</div>
</div>
<div class="progress-actions">
<button class="progress-btn" id="btnExport" onclick="exportProgress()" data-tooltip="Export tiến trình ra file JSON">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
Export
</button>
<button class="progress-btn" id="btnImport" onclick="document.getElementById('importFile').click()" data-tooltip="Import tiến trình từ file JSON">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
Import
</button>
<input type="file" id="importFile" accept=".json" style="display:none" onchange="importProgress(event)">
<button class="progress-btn" id="btnSettings" onclick="toggleSettings(event)" data-tooltip="Cài đặt hiển thị">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
Settings
</button>
</div>
</div>
<!-- Settings Modal (fixed, works from both header and floating header) -->
<div class="settings-backdrop" id="settingsBackdrop" onclick="closeSettings()"></div>
<div class="settings-modal" id="settingsPopover">
<div class="settings-header">
<span>⚙️ Cài đặt hiển thị</span>
<button class="settings-close" onclick="closeSettings()">×</button>
</div>
<div class="settings-group">
<label class="settings-label">Cỡ chữ câu hỏi</label>
<div class="settings-row">
<div class="settings-presets">
<button class="preset-btn" onclick="setFontSize('question', 14)">S</button>
<button class="preset-btn" onclick="setFontSize('question', 17)">M</button>
<button class="preset-btn" onclick="setFontSize('question', 20)">L</button>
</div>
<input type="range" id="fontSizeQuestion" class="settings-slider" min="12" max="24" value="17" oninput="setFontSize('question', this.value)">
<span class="settings-value" id="fontSizeQuestionVal">17px</span>
</div>
</div>
<div class="settings-group">
<label class="settings-label">Cỡ chữ câu trả lời</label>
<div class="settings-row">
<div class="settings-presets">
<button class="preset-btn" onclick="setFontSize('answer', 14)">S</button>
<button class="preset-btn" onclick="setFontSize('answer', 16)">M</button>
<button class="preset-btn" onclick="setFontSize('answer', 19)">L</button>
</div>
<input type="range" id="fontSizeAnswer" class="settings-slider" min="12" max="24" value="16" oninput="setFontSize('answer', this.value)">
<span class="settings-value" id="fontSizeAnswerVal">16px</span>
</div>
</div>
<button class="settings-reset-btn" onclick="resetFontSettings()">Reset mặc định</button>
</div>
<div class="container">
<div class="search-wrap">
<input type="text" id="searchBox" placeholder="Tìm kiếm câu hỏi... (vd: HashMap, JWT, Kafka, Docker)">
<div class="filter-tabs" id="topicTabs">
<span class="filter-tab active" data-filter="all">Tất cả</span>
<span class="filter-tab" data-filter="java">☕ Java Core</span>
<span class="filter-tab spring-tab" data-filter="spring">🌱 Spring Boot</span>
<span class="filter-tab" data-filter="oop">OOP</span>
<span class="filter-tab" data-filter="collections">Collections</span>
<span class="filter-tab" data-filter="thread">Threading</span>
<span class="filter-tab" data-filter="java8">Java 8+</span>
<span class="filter-tab" data-filter="jvm">JVM</span>
<span class="filter-tab" data-filter="jpa">JPA</span>
<span class="filter-tab" data-filter="security">Security</span>
<span class="filter-tab" data-filter="test">🧪 Testing</span>
<span class="filter-tab" data-filter="kafka">🟠 Kafka</span>
<span class="filter-tab" data-filter="redis">🔴 Redis</span>
<span class="filter-tab" data-filter="microservice">🔷 Microservice</span>
<span class="filter-tab" data-filter="database">🗄️ Database</span>
<span class="filter-tab" data-filter="cloud">☁️ Cloud</span>
<span class="filter-tab" data-filter="devops">🚀 DevOps</span>
<span class="filter-tab" data-filter="architecture">🧱 Architecture</span>
<span class="filter-tab" data-filter="systemdesign">🔥 System Design</span>
<span class="filter-tab" data-filter="elk">📊 ELK Stack</span>
</div>
<div class="filter-tabs" style="margin-top:6px">
<span style="font-size:10px;color:var(--muted);font-weight:600;letter-spacing:0.5px;align-self:center;margin-right:4px">LEVEL:</span>
<span class="filter-tab lv-intern" data-level="intern">🔘 Intern</span>
<span class="filter-tab lv-junior" data-level="junior">🟢 Junior</span>
<span class="filter-tab lv-middle" data-level="middle">🔵 Middle</span>
<span class="filter-tab lv-senior" data-level="senior">🟠 Senior</span>
<span class="filter-tab lv-expert" data-level="expert">🟣 Expert</span>
</div>
</div>
<div id="qa-content">
<div style="text-align:center;padding:60px 20px;color:var(--muted)">
<div style="font-size:32px;margin-bottom:12px">⏳</div>
<div>Đang tải câu hỏi...</div>
</div>
</div>
<div id="noResult" style="display:none;text-align:center;padding:60px 20px;color:var(--muted)">
<div style="font-size:40px;margin-bottom:12px">🔍</div>
<div>Không tìm thấy câu hỏi nào phù hợp</div>
</div>
</div>
<script>
const LEVEL_LABELS = {
intern: '🔘 Intern', junior: '🟢 Junior', middle: '🔵 Middle',
senior: '🟠 Senior', expert: '🟣 Expert'
};
let allQuestions = []; // Store globally for stats computation
const CLASS_COLORS = { 'java-color': '#f97316', 'spring-color': '#34d399' };
// ── Settings (localStorage) ─────────────────────────────
const SETTINGS_KEY = 'java_qa_settings';
const DEFAULT_SETTINGS = { questionFontSize: 17, answerFontSize: 16 };
function loadSettings() {
try { return { ...DEFAULT_SETTINGS, ...JSON.parse(localStorage.getItem(SETTINGS_KEY)) }; } catch { return { ...DEFAULT_SETTINGS }; }
}
function saveSettings(settings) {
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
}
function applyFontSettings() {
const s = loadSettings();
document.documentElement.style.setProperty('--q-font-size', s.questionFontSize + 'px');
document.documentElement.style.setProperty('--a-font-size', s.answerFontSize + 'px');
// Sync sliders & values
const qSlider = document.getElementById('fontSizeQuestion');
const aSlider = document.getElementById('fontSizeAnswer');
if (qSlider) { qSlider.value = s.questionFontSize; }
if (aSlider) { aSlider.value = s.answerFontSize; }
const qVal = document.getElementById('fontSizeQuestionVal');
const aVal = document.getElementById('fontSizeAnswerVal');
if (qVal) qVal.textContent = s.questionFontSize + 'px';
if (aVal) aVal.textContent = s.answerFontSize + 'px';
updatePresetBtns();
}
function setFontSize(type, value) {
const size = parseInt(value);
const s = loadSettings();
if (type === 'question') s.questionFontSize = size;
else s.answerFontSize = size;
saveSettings(s);
applyFontSettings();
}
function resetFontSettings() {
saveSettings(DEFAULT_SETTINGS);
applyFontSettings();
showToast('✅ Đã reset về mặc định!');
}
function updatePresetBtns() {
const s = loadSettings();
document.querySelectorAll('.settings-group').forEach((group, i) => {
const size = i === 0 ? s.questionFontSize : s.answerFontSize;
group.querySelectorAll('.preset-btn').forEach(btn => {
const btnSize = parseInt(btn.getAttribute('onclick').match(/\d+/g).pop());
btn.classList.toggle('active', btnSize === size);
});
});
}
function toggleSettings(event) {
event.stopPropagation();
const modal = document.getElementById('settingsPopover');
const backdrop = document.getElementById('settingsBackdrop');
const isOpen = modal.classList.contains('open');
if (isOpen) {
modal.classList.remove('open');
backdrop.classList.remove('open');
} else {
modal.classList.add('open');
backdrop.classList.add('open');
}
}
function closeSettings() {
document.getElementById('settingsPopover').classList.remove('open');
document.getElementById('settingsBackdrop').classList.remove('open');
}
// Apply on load immediately
applyFontSettings();
// ── View Count (localStorage) ───────────────────────────
const VC_KEY = 'java_qa_views';
function loadCounts() {
try { return JSON.parse(localStorage.getItem(VC_KEY)) || {}; } catch { return {}; }
}
function saveCount(num, counts) {
counts[num] = (counts[num] || 0) + 1;
localStorage.setItem(VC_KEY, JSON.stringify(counts));
return counts[num];
}
// ── Question Status (done/skipped) ──────────────────────
const STATUS_KEY = 'java_qa_status';
function loadStatus() {
try { return JSON.parse(localStorage.getItem(STATUS_KEY)) || {}; } catch { return {}; }
}
function saveStatus(statuses) {
localStorage.setItem(STATUS_KEY, JSON.stringify(statuses));
}
function markDone(num, event) {
event.stopPropagation();
const statuses = loadStatus();
const card = document.getElementById('q' + num);
if (statuses[num] === 'done') {
delete statuses[num];
card.classList.remove('done');
} else {
statuses[num] = 'done';
card.classList.remove('skipped');
card.classList.add('done');
}
saveStatus(statuses);
updateCompletionStats();
}
function markSkip(num, event) {
event.stopPropagation();
const statuses = loadStatus();
const card = document.getElementById('q' + num);
if (statuses[num] === 'skipped') {
delete statuses[num];
card.classList.remove('skipped');
} else {
statuses[num] = 'skipped';
card.classList.remove('done');
card.classList.add('skipped');
// Close the card if open
card.classList.remove('open');
}
saveStatus(statuses);
updateCompletionStats();
}
function resetViews(num, event) {
event.stopPropagation();
const counts = loadCounts();
delete counts[num];
localStorage.setItem(VC_KEY, JSON.stringify(counts));
// Update DOM
const card = document.getElementById('q' + num);
const badge = card.querySelector('.view-count');
if (badge) {
badge.textContent = '';
badge.style.display = 'none';
}
// Hide reset button
const resetBtn = card.querySelector('.btn-reset');
if (resetBtn) resetBtn.classList.remove('has-views');
}
// ── Import / Export Progress ────────────────────────────
function exportProgress() {
const data = {
exportedAt: new Date().toISOString(),
version: 1,
views: loadCounts(),
statuses: loadStatus(),
settings: loadSettings()
};
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `java-qa-progress_${new Date().toISOString().slice(0,10)}.json`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
showToast('✅ Đã export tiến trình thành công!');
}
function importProgress(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = (e) => {
try {
const data = JSON.parse(e.target.result);
if (!data.views && !data.statuses && !data.settings) {
showToast('❌ File JSON không hợp lệ!', true);
return;
}
// Merge imported data
if (data.views) {
const currentViews = loadCounts();
Object.assign(currentViews, data.views);
localStorage.setItem(VC_KEY, JSON.stringify(currentViews));
}
if (data.statuses) {
const currentStatuses = loadStatus();
Object.assign(currentStatuses, data.statuses);
localStorage.setItem(STATUS_KEY, JSON.stringify(currentStatuses));
}
if (data.settings) {
saveSettings({ ...DEFAULT_SETTINGS, ...data.settings });
}
showToast('✅ Import tiến trình thành công! Đang tải lại...');
setTimeout(() => location.reload(), 800);
} catch (err) {
showToast('❌ Lỗi đọc file: ' + err.message, true);
}
};
reader.readAsText(file);
// Reset input so the same file can be re-imported
event.target.value = '';
}
function showToast(message, isError = false) {
// Remove existing toast
const existing = document.querySelector('.progress-toast');
if (existing) existing.remove();
const toast = document.createElement('div');
toast.className = 'progress-toast' + (isError ? ' error' : '');
toast.textContent = message;
document.body.appendChild(toast);
// Trigger animation
requestAnimationFrame(() => toast.classList.add('show'));
setTimeout(() => {
toast.classList.remove('show');
setTimeout(() => toast.remove(), 300);
}, 2500);
}
function toggle(el) {
// Don't toggle if clicking action buttons
if (el.closest('.qa-actions')) return;
const card = el.closest('.qa-card');
const isOpen = card.classList.contains('open');
// Close all open cards
document.querySelectorAll('.qa-card.open').forEach(c => c.classList.remove('open'));
// If it was closed, open it and increment view count
if (!isOpen) {
card.classList.add('open');
const num = card.id.replace('q', '');
const counts = loadCounts();
const newCount = saveCount(num, counts);
// Live-update the badge in DOM
const badge = card.querySelector('.view-count');
if (badge) {
badge.textContent = `👁 ${newCount}`;
badge.style.display = 'inline-flex';
}
// Show reset button since we now have views
const resetBtn = card.querySelector('.btn-reset');
if (resetBtn) resetBtn.classList.add('has-views');
}
}
// ── Render ──────────────────────────────────────────────
function renderQuestions(questions) {
const counts = loadCounts();
const statuses = loadStatus();
// Group: section → subsection → questions (preserve order)
const secMap = new Map();
const secOrder = [];
questions.forEach(q => {
if (!secMap.has(q.section)) {
secMap.set(q.section, { meta: q, subs: new Map(), subOrder: [] });
secOrder.push(q.section);
}
const sec = secMap.get(q.section);
const sub = q.subsection || '__none__';
if (!sec.subs.has(sub)) { sec.subs.set(sub, []); sec.subOrder.push(sub); }
sec.subs.get(sub).push(q);
});
let html = '';
for (const secTitle of secOrder) {
const sec = secMap.get(secTitle);
const m = sec.meta;
let count = 0; sec.subs.forEach(qs => count += qs.length);
const titleAttr = m.sectionColorClass
? `class="section-title ${m.sectionColorClass}"`
: `class="section-title" style="color:${m.sectionColor}"`;
html += `<div class="section-header">
<span class="section-icon">${m.sectionIcon}</span>
<span ${titleAttr}>${secTitle}</span>
<span class="section-count">${count} câu</span>
</div>`;
for (const sub of sec.subOrder) {
if (sub !== '__none__') html += `<div class="subsection-label">${sub}</div>`;
for (const q of sec.subs.get(sub)) {
const num = String(q.num).padStart(2, '0');
const viewCount = counts[q.num] || 0;
const status = statuses[q.num] || '';
const statusClass = status ? ` ${status}` : '';
const viewBadge = viewCount > 0
? `<span class="view-count" style="display:inline-flex">👁 ${viewCount}</span>`
: `<span class="view-count" style="display:none"></span>`;
const hasViews = viewCount > 0 ? ' has-views' : '';
html += `<div class="qa-card${statusClass}" data-tags="${q.tags}" data-level="${q.level}" id="q${q.num}">
<div class="qa-question" onclick="toggle(this)">
<span class="qa-num">${num}</span>
<span class="qa-q-text">${q.question}</span>
${viewBadge}
<span class="qa-actions">
<button class="qa-action-btn btn-done" data-tooltip="Done" onclick="markDone(${q.num}, event)">✓</button>
<button class="qa-action-btn btn-skip" data-tooltip="Skip" onclick="markSkip(${q.num}, event)">⏭</button>
<button class="qa-action-btn btn-reset${hasViews}" data-tooltip="Reset views" onclick="resetViews(${q.num}, event)">↺</button>
</span>
<span class="level-badge ${q.level}">${LEVEL_LABELS[q.level]}</span>
<span class="qa-toggle">▾</span>
</div>
<div class="qa-answer"><div class="qa-answer-inner">${q.answerHtml}</div></div>
</div>`;
}
}
}
document.getElementById('qa-content').innerHTML = html;
}
// ── Search & Filter ──────────────────────────────────────
let activeFilter = 'all';
let activeLevel = 'all';
function filterCards() {
const query = document.getElementById('searchBox').value.toLowerCase().trim();
const cards = document.querySelectorAll('.qa-card');
let visible = 0;
cards.forEach(card => {
const matchSearch = !query || card.innerText.toLowerCase().includes(query);
const matchTopic = activeFilter === 'all' || (card.dataset.tags || '').includes(activeFilter);
const matchLevel = activeLevel === 'all' || card.dataset.level === activeLevel;
if (matchSearch && matchTopic && matchLevel) {
card.classList.remove('hidden'); visible++;
} else {
card.classList.add('hidden');
}
});
document.getElementById('noResult').style.display = visible === 0 ? 'block' : 'none';
}
function initFilter() {
document.getElementById('searchBox').addEventListener('input', filterCards);
document.querySelectorAll('.filter-tab[data-filter]').forEach(tab => {
tab.addEventListener('click', () => {
document.querySelectorAll('.filter-tab[data-filter]').forEach(t => t.classList.remove('active'));
tab.classList.add('active');
activeFilter = tab.dataset.filter;
filterCards();
});
});
document.querySelectorAll('.filter-tab[data-level]').forEach(tab => {
tab.addEventListener('click', () => {
if (tab.classList.contains('active')) {
tab.classList.remove('active'); activeLevel = 'all';
} else {
document.querySelectorAll('.filter-tab[data-level]').forEach(t => t.classList.remove('active'));
tab.classList.add('active'); activeLevel = tab.dataset.level;
}
filterCards();
});
});
document.addEventListener('keydown', e => {
if (e.key === 'Escape') {
document.getElementById('searchBox').value = '';
activeFilter = 'all'; activeLevel = 'all';
document.querySelectorAll('.filter-tab[data-filter]').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.filter-tab[data-level]').forEach(t => t.classList.remove('active'));
document.querySelector('.filter-tab[data-filter="all"]').classList.add('active');
filterCards();
}
});
}
// ── Completion Stats ────────────────────────────────────
function updateCompletionStats() {
const statuses = loadStatus();
let doneCount = 0, skipCount = 0;
const levelTotals = { intern: 0, junior: 0, middle: 0, senior: 0, expert: 0 };
const levelDone = { intern: 0, junior: 0, middle: 0, senior: 0, expert: 0 };
allQuestions.forEach(q => {
const lv = q.level;
if (levelTotals[lv] !== undefined) levelTotals[lv]++;
const st = statuses[q.num];
if (st === 'done') {
doneCount++;
if (levelDone[lv] !== undefined) levelDone[lv]++;
} else if (st === 'skipped') {
skipCount++;
}
});
const total = allQuestions.length;
const completed = doneCount + skipCount;
document.getElementById('statDone').innerHTML = `✓ Done: <strong>${doneCount}</strong>`;
document.getElementById('statSkip').innerHTML = `⏭ Skip: <strong>${skipCount}</strong>`;
document.getElementById('statTotal').innerHTML = `📋 Tổng hoàn thành: <strong>${completed}</strong> / <strong>${total}</strong>`;
// Update level buttons
const levelEmojis = { intern: '🔘', junior: '🟢', middle: '🔵', senior: '🟠', expert: '🟣' };
const levelNames = { intern: 'Intern', junior: 'Junior', middle: 'Middle', senior: 'Senior', expert: 'Expert' };
for (const lv of Object.keys(levelTotals)) {
const btn = document.getElementById('levelBtn' + lv.charAt(0).toUpperCase() + lv.slice(1));
if (btn) {
const done = levelDone[lv];
const tot = levelTotals[lv];
const pct = tot > 0 ? Math.round((done / tot) * 100) : 0;
btn.innerHTML = `${levelEmojis[lv]} ${levelNames[lv]}: <strong>${done}/${tot}</strong> <span class="level-pct">(${pct}%)</span>`;
// Update progress fill
btn.style.setProperty('--progress', pct + '%');
if (done === tot && tot > 0) btn.classList.add('completed');
else btn.classList.remove('completed');
}
}
// Update progress bar
const progressPct = total > 0 ? Math.round((completed / total) * 100) : 0;
const statsEl = document.getElementById('completionStats');
if (statsEl) {
statsEl.style.setProperty('--total-progress', progressPct + '%');
}
// Update floating stats bar
document.getElementById('floatDone').textContent = doneCount;
document.getElementById('floatSkip').textContent = skipCount;
document.getElementById('floatCompleted').textContent = completed;
document.getElementById('floatTotal').textContent = total;
document.getElementById('floatProgressFill').style.width = progressPct + '%';
}
function toggleLevelDetail(level) {
// Filter to show only that level
const tabs = document.querySelectorAll('.filter-tab[data-level]');
const targetTab = document.querySelector(`.filter-tab[data-level="${level}"]`);
if (targetTab) {
if (targetTab.classList.contains('active')) {
targetTab.classList.remove('active');
activeLevel = 'all';
} else {
tabs.forEach(t => t.classList.remove('active'));
targetTab.classList.add('active');
activeLevel = level;
}
filterCards();
// Scroll to content
document.getElementById('qa-content').scrollIntoView({ behavior: 'smooth', block: 'start' });
}
}
// ── Boot ────────────────────────────────────────────────
(async () => {
try {
const res = await fetch('questions.json');
if (!res.ok) throw new Error('Cannot load questions.json');
const data = await res.json();
allQuestions = data;
document.getElementById('totalBadge').textContent = data.length + ' câu hỏi';
renderQuestions(data);
initFilter();
updateCompletionStats();
applyFontSettings();
// Show/hide floating header on scroll
const headerEl = document.querySelector('.header');
const floatingHeader = document.getElementById('floatingHeader');
const mainSearch = document.getElementById('searchBox');
const floatingSearch = document.getElementById('floatingSearchBox');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
floatingHeader.classList.remove('visible');
} else {
floatingHeader.classList.add('visible');
}
});
}, { threshold: 0, rootMargin: '0px 0px 0px 0px' });
observer.observe(headerEl);
// Sync floating search with main search
floatingSearch.addEventListener('input', () => {
mainSearch.value = floatingSearch.value;
mainSearch.dispatchEvent(new Event('input'));
});
mainSearch.addEventListener('input', () => {
floatingSearch.value = mainSearch.value;
});
} catch (err) {
document.getElementById('qa-content').innerHTML =
'<div style="text-align:center;padding:60px;color:#ef4444">❌ Không load được questions.json.<br><small>' + err.message + '</small></div>';
}
})();
</script>
</body>
</html>