forked from bongodev/vanilla-javascript-fall-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
253 lines (239 loc) · 5.86 KB
/
script.js
File metadata and controls
253 lines (239 loc) · 5.86 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
const projects = [
{
name: 'Counter App',
dirPath: '001-counter-app',
},
{
name: 'Number Comparator',
dirPath: '002-number-comparator',
},
{
name: 'Grade Calculator',
dirPath: '003-grade-calculator',
},
{
name: 'Number Table',
dirPath: '004-number-table',
},
{
name: 'Number Table of 1-10',
dirPath: '005-number-table-1-10',
},
{
name: 'Employee Management',
dirPath: '006-employee-table',
},
{
name: 'Simple E-commerce',
dirPath: '007-e-commerce',
},
{
name: 'Render Products (Promise, async-await)',
dirPath: '008-render-products',
},
];
const contributors = [
{
name: 'BongoDev',
dirPath: 'bongodev',
email: 'support@bongodev.com',
},
{
name: 'Nazma',
dirPath: 'nazma98',
email: 'nazma.sarker1398@gmail.com',
},
{
name: 'Talha',
dirPath: 'Talha',
email: 'ameertalha22@gmail.com',
},
{
name: 'Md. Al Amin',
dirPath: 'Alamin',
email: 'aaalaamin7@gmail.com',
},
{
name: 'Sumiya Yasmin',
dirPath: 'sumiya-yasmin',
email: 'sumiyayasmin665@gmail.com',
},
{
name: 'Than Win',
dirPath: 'thanwin',
email: 'thanwinhline84@gmail.com',
},
{
name: 'Tamjid',
dirPath: 'Tamjid',
email: 'tamjidtj6@gmail.com',
},
{
name: 'Dipu',
dirPath: 'Dipu',
email: 'mojumderdipu66@gmail.com',
},
{
name: 'Sakib',
dirPath: 'Sakib',
email: 'nazmussakib06927@gmail.com',
},
{
name: 'Kamrul',
dirPath: 'Kamrul',
email: 'nijumkamrul447@gmail.com',
},
{
name: 'Promi',
dirPath: 'promi',
email: 'farihapromi2611@gmail.com',
},
{
name: 'Shifat',
dirPath: 'Shifat',
email: 'shifatbinreza2@gmail.com',
},
{
name: 'MSI.Dipu',
dirPath: 'MSI-DIPU',
email: 'msidipu2@gmail.com',
},
{
name: 'Mohyminul-Islam',
dirPath: 'Mohyminul-Islam',
email: 'mohyminulislam2001@gmail.com',
},
{
name: 'Arman',
dirPath: 'armaanepiic',
email: 'armaanepiicfb17@gmail.com',
},
{
name: 'Asha',
dirPath: 'Asha',
email: 'afsanaasha502@gmail.com',
},
{
name: 'Parisa Reza',
dirPath: 'Parisa-Reza',
email: 'rezaparisa5@gmail.com',
},
{
name: 'Tasin',
dirPath: 'Tasin',
email: 'ahmedtasin207@gmail.com',
},
{
name: 'foysal',
dirPath: 'foysal1680',
email: 'foysalkhanrial1680@gmail.com',
},
{
name: 'Mohammad Fahim Hossain',
dirPath: 'md-fahim-hossain',
email: 'mdfahimhossain2@gmail.com',
},
{
name: 'Irfan',
dirPath: 'irfan-mahbub',
email: 'talha.mahbub.irfan@gmail.com',
},
{
name: 'Jubayar Ahamad',
dirPath: 'yet-yuvi',
email: 'eng.jubayar@gmail.com',
},
{
name: 'Md. Ali Imam',
dirPath: 'EmperorAlii',
email: 'asvhon832@gmail.com',
},
{
name:'Adil Siam',
dirPath:'Adil',
email:'adilsiam.dev@gmail.com',
},
];
const projectsContainer = document.getElementById('projects-container');
async function checkDirectoryExists(projectPath, dirPath) {
const filePath = `./${projectPath}/${dirPath}/index.html`;
try {
const response = await fetch(filePath, { method: 'HEAD' });
return response.ok;
} catch (error) {
console.error(`Error checking file: ${filePath}`, error);
return false;
}
}
async function getContributors(projectPath) {
const contributorsList = document.createElement('ul');
contributorsList.className = 'list-disc list-inside hidden ml-2';
contributors.forEach(async (contributor) => {
const directoryExists = await checkDirectoryExists(
projectPath,
contributor.dirPath
);
if (directoryExists) {
const listItem = document.createElement('li');
const projectLink = document.createElement('a');
projectLink.className =
'text-blue-600 visited:text-purple-600 hover:underline';
projectLink.innerText = contributor.name;
projectLink.target = '_blank';
projectLink.href = `./${projectPath}/${contributor.dirPath}/index.html`;
listItem.appendChild(projectLink);
contributorsList.appendChild(listItem);
}
});
return contributorsList;
}
function getProjectTitle(projectName) {
const projectTitle = document.createElement('h1');
projectTitle.className = 'text-xl font-bold text-gray-800 mb-4';
projectTitle.innerText = projectName;
return projectTitle;
}
async function renderProjectsAndContributors() {
const projectsContainer = document.getElementById('projects-container');
projects.forEach(async (project) => {
const projectSection = document.createElement('div');
projectSection.classList.add(
'mx-auto',
'px-4',
'py-2',
'bg-gray-200',
'mb-2',
'project-sections',
'cursor-pointer',
'rounded-md'
);
const projectHeader = document.createElement('div');
projectHeader.classList.add('flex', 'justify-between');
const projectTitle = getProjectTitle(project.name);
projectHeader.appendChild(projectTitle);
const icon = document.createElement('i');
icon.classList.add('fa', 'fa-angle-down', 'my-auto', 'text-gray-600');
projectHeader.append(icon);
const contributors = await getContributors(project.dirPath);
projectSection.appendChild(projectHeader);
projectSection.appendChild(contributors);
projectsContainer.append(projectSection);
});
}
function handleDropdown() {
const projectSections = document.querySelectorAll('.project-sections');
projectSections.forEach((container) => {
container.addEventListener('click', (e) => {
container.children[1].classList.toggle('hidden');
const icon = container.children[0].lastChild;
if (icon.classList.contains('fa-angle-down')) {
icon.classList.replace('fa-angle-down', 'fa-angle-up');
} else {
icon.classList.replace('fa-angle-up', 'fa-angle-down');
}
});
});
}
renderProjectsAndContributors().then((res) => {
handleDropdown();
});