forked from ruchikakengal/WebDevIn100_Days
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
147 lines (127 loc) · 4.81 KB
/
Copy pathindex.js
File metadata and controls
147 lines (127 loc) · 4.81 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
function filterProjects() {
const input = document.getElementById('searchInput');
const filter = input.value.toLowerCase();
const rows = document.querySelector('tbody').querySelectorAll('tr'); // Choose all rows in the table body
let hasResults = false;
rows.forEach(row => {
const projectName = row.querySelector('.project-name')?.innerText.toLowerCase();
if (projectName && projectName.includes(filter)) {
row.style.display = '';
hasResults = true;
} else if (row.id !== 'table-subheader') {
row.style.display = 'none';
}
});
const subheader = document.querySelector('.subheader');
const noProjectsMessage = document.getElementById('no-projects');
if (hasResults) {
subheader.style.display = 'block';
noProjectsMessage.style.display = 'none';
} else {
document.getElementById('table-subheader').style.display = 'none';
subheader.style.display = 'none';
noProjectsMessage.style.display = 'block';
}
}
// Update Navbar for Login Status
const buttons = document.getElementsByClassName('buttons')[0]; // Refers to the section on NavBar where buttons will get appended based on login status
function updateNavbar() {
const username = localStorage.getItem('username');
if (username) {
buttons.innerHTML = `
<button class="button is-success is-dark has-text-weight-bold">
Welcome ${username}
</button>
<button class="button is-danger is-dark" id='logout'>
Logout
</button>
<a class="button is-primary is-dark" href="https://github.com/ruchikakengal">
<strong>GitHub</strong>
</a>
<a class="button is-primary is-dark" href="contributors/contributor.html">
<strong>Contributors</strong>
</a>`;
document.getElementById('logout').addEventListener('click', () => {
localStorage.removeItem('username');
updateNavbar();
});
} else {
buttons.innerHTML = `
<a class="button is-primary is-dark" href="contributors/contributor.html">
<strong>Contributors</strong>
</a>
<a class="button is-primary is-dark" href="https://github.com/ruchikakengal">
<strong>GitHub</strong>
</a>
<a class="button is-success is-light" href="/public/Login.html">
<strong>Log in</strong>
</a>`;
}
}
// Populate the table with project data
function fillTable() {
const data = [
["Day 1", "To-Do List", "./public/TO_DO_LIST/todolist.html"],
["Day 2", "Digital Clock", "./public/digital_clock/digitalclock.html"],
["Day 3", "ASCII Art Generator (by Amaan Syed)", "./public/AsciiArtGenerator/index.html",],
["Day 4", "Physics Simulation (by Vishisht Dwivedi)", "./public/physics_simulation/index.html"],
["Day 5", " ",],
["Day 6", " ",],
["Day 7", " ",],
["Day 8", " ",],
["Day 9", " ",],
["Day 10", " ",],
["Day 11", " ",],
["Day 12", " ",],
["Day 13", " ",],
["Day 14", " ",],
["Day 100", " ",],
];
const tbody = document.getElementById('tableBody');
data.forEach(e => {
const row = document.createElement('tr');
const days = document.createElement('td');
const nameP = document.createElement('td');
const link = document.createElement('td');
const a = document.createElement('a');
days.innerText = e[0];
nameP.innerText = e[1];
a.href = e[2];
a.innerText = 'Here';
a.target = '_blank'; // Open link in a new tab
nameP.classList.add('project-name');
link.appendChild(a);
row.appendChild(days);
row.appendChild(nameP);
row.appendChild(link);
tbody.appendChild(row);
});
}
document.addEventListener('DOMContentLoaded', () => {
updateNavbar();
fillTable();
});
const themeToggle = document.getElementById('theme-toggle');
const body = document.body;
// Check if the user has a saved theme preference
if (localStorage.getItem('theme') === 'dark') {
body.classList.add('dark-theme');
themeToggle.textContent = '☀️';
} else {
body.classList.add('light-theme'); // Explicitly set light theme
themeToggle.textContent = '🌙';
}
// Toggle theme on button click
themeToggle.addEventListener('click', () => {
if (body.classList.contains('dark-theme')) {
body.classList.remove('dark-theme');
body.classList.add('light-theme');
themeToggle.textContent = '🌙';
localStorage.setItem('theme', 'light');
} else {
body.classList.remove('light-theme');
body.classList.add('dark-theme');
themeToggle.textContent = '☀️';
localStorage.setItem('theme', 'dark');
}
});