-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjavascriptCTF.js
More file actions
39 lines (37 loc) · 1.33 KB
/
Copy pathjavascriptCTF.js
File metadata and controls
39 lines (37 loc) · 1.33 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
//Category CTF
function searchByCategory(category) {
window.location.href = "./view.php?search=" + category;
}
class Category {
constructor(name, clickHandler) {
this.name = name;
this.element = document.createElement('p');
this.element.textContent = name;
this.element.addEventListener('click', clickHandler);
}
render(container) {
container.appendChild(this.element);
}
}
class CategoryBar {
constructor(containerId) {
this.container = document.getElementById(containerId);
this.categories = [];
}
addCategory(name, clickHandler) {
const category = new Category(name, clickHandler);
this.categories.push(category);
}
render() {
this.categories.forEach(category => category.render(this.container));
}
}
// Usage:
const categoryBar = new CategoryBar('ctf-navbar');
categoryBar.addCategory('All Challenges', () => searchByCategory(''));
categoryBar.addCategory('Reverse Engineering', () => searchByCategory('Reverse Engineering'));
categoryBar.addCategory('Web Exploitation', () => searchByCategory('Web Exploitation'));
categoryBar.addCategory('Binary Exploitation', () => searchByCategory('Binary Exploitation'));
categoryBar.addCategory('Forensics', () => searchByCategory('Forensics'));
categoryBar.addCategory('Cryptography', () => searchByCategory('Cryptography'));
categoryBar.render();