Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
1683 lines (1508 loc) · 52 KB
/
Copy pathscript.js
File metadata and controls
1683 lines (1508 loc) · 52 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
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
let allCategories = [];
let currentFilter = "all";
let searchTerm = ""; // current text search filter
let showAllCategories = {}; // per category expansion state
let allContributors = [];
// --- Security helpers -------------------------------------------------
// Escape untrusted strings (community-contributed JSON) before injecting
// them into innerHTML to prevent XSS.
function escapeHtml(value) {
if (value == null) return "";
return String(value)
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
// Escape a value for use inside a single-quoted JS string (inline handlers).
function escapeJsString(value) {
if (value == null) return "";
return String(value)
.replace(/\\/g, "\\\\")
.replace(/'/g, "\\'")
.replace(/"/g, '\\"')
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r");
}
// Safely derive the hostname from a URL; returns "" if it can't be parsed.
function safeHostname(url) {
try {
return new URL(url).hostname;
} catch (e) {
return "";
}
}
// Only allow http/https URLs; otherwise return "#" to block javascript: etc.
function safeUrl(url) {
try {
const u = new URL(url);
if (u.protocol === "http:" || u.protocol === "https:") return u.href;
} catch (e) {
/* fall through */
}
return "#";
}
// Favicon service for a given tool URL (used as a visual logo on cards).
function faviconUrl(url) {
const host = safeHostname(url);
if (!host) return "";
return `https://www.google.com/s2/favicons?domain=${encodeURIComponent(
host,
)}&sz=64`;
}
// Contributors pagination
let currentContributorPage = 1;
const contributorsPerPage = 16; // 12 contributors per page (4x3 grid)
let filteredContributors = [];
let searchContributorsText = "";
async function loadLinks() {
try {
const response = await fetch("data/links.json");
const data = await response.json();
allCategories = data.categories;
renderCategoryFilters(allCategories); // populate dropdown
applyFilters(); // initial render using combined filters
updateStats(allCategories);
} catch (error) {
console.error("Error loading links:", error);
document.getElementById("main-content").innerHTML =
"<p>Error loading links</p>";
}
}
async function loadContributors() {
try {
const response = await fetch("data/contributors.json");
const data = await response.json();
if (
data &&
Array.isArray(data.contributors) &&
data.contributors.length > 0
) {
allContributors = data.contributors;
renderContributors(allContributors);
updateContributorStats(data.contributors.length);
updateFooterContributorsCount(data.contributors.length);
} else {
throw new Error("No contributors data found");
}
} catch (error) {
console.error("Error loading contributors:", error);
// Fallback with dash
// add fallback contributor for only development
allContributors = [
{
name: "Testing Contributor",
github: "tester123",
avatar: "https://thispersondoesnotexist.com/",
linkedin: "testing123",
tagline:
"This is a fallback contributor added due to an error in loading the contributors data.",
contributions: ["Testing the contributors loading functionality."],
role: "Contributor",
featured: true,
},
{
name: "Testing Contributor",
github: "tester123",
avatar: "https://thispersondoesnotexist.com/",
linkedin: "testing123",
tagline:
"This is a fallback contributor added due to an error in loading the contributors data.",
contributions: ["Testing the contributors loading functionality."],
role: "Contributor",
featured: false,
},
];
renderContributors(allContributors);
updateFooterContributorsCount("-");
}
}
function renderCategoryFilters(categories) {
const select = document.getElementById("category-select");
if (!select) return;
const total = categories.reduce((sum, cat) => sum + cat.links.length, 0);
select.innerHTML =
`<option value="all">🎯 All Categories (${total})</option>` +
categories
.map(
(category) =>
`<option value="${escapeHtml(category.name)}">${escapeHtml(
category.icon,
)} ${escapeHtml(category.name)} (${category.links.length})</option>`,
)
.join("");
renderCategoryChips(categories, total);
}
// Quick-filter chip row mirroring the category dropdown.
function renderCategoryChips(categories, total) {
const container = document.getElementById("category-chips");
if (!container) return;
const chip = (value, label, icon, count) => `
<button type="button" class="category-chip ${
currentFilter === value ? "active" : ""
}" data-category="${escapeHtml(value)}"
onclick="filterToCategory('${escapeJsString(value)}')">
<span>${icon ? escapeHtml(icon) + " " : ""}${escapeHtml(label)}</span>
<span class="chip-count">${count}</span>
</button>`;
container.innerHTML =
chip("all", "All", "🎯", total) +
categories
.map((c) => chip(c.name, c.name, c.icon, c.links.length))
.join("");
}
// Central handler used by chips (keeps dropdown + chips + filters in sync).
function filterToCategory(categoryName) {
currentFilter = categoryName;
const select = document.getElementById("category-select");
if (select) select.value = categoryName;
syncChipActiveState();
applyFilters();
trackCategoryFilter(categoryName);
}
function syncChipActiveState() {
document.querySelectorAll("#category-chips .category-chip").forEach((btn) => {
btn.classList.toggle("active", btn.dataset.category === currentFilter);
});
}
// New unified filtering applying category + search term
function applyFilters() {
let categoriesToUse = allCategories;
if (currentFilter !== "all") {
categoriesToUse = allCategories.filter((c) => c.name === currentFilter);
}
const term = searchTerm.trim().toLowerCase();
let filtered = categoriesToUse.map((cat) => {
if (!term) return cat; // no search filtering
const filteredLinks = cat.links.filter(
(link) =>
link.title.toLowerCase().includes(term) ||
(link.description && link.description.toLowerCase().includes(term)),
);
return { ...cat, links: filteredLinks };
});
// Remove categories that have zero links after search filtering
filtered = filtered.filter((cat) => cat.links && cat.links.length > 0);
// Keep the chip row in sync with the current filter
syncChipActiveState();
const mainContent = document.getElementById("main-content");
const resultsCount = document.getElementById("results-count");
mainContent.innerHTML = "";
if (filtered.length === 0) {
if (resultsCount) resultsCount.textContent = "";
mainContent.innerHTML = `
<div class="empty-state">
<i class="fas fa-magnifying-glass"></i>
<p>No tools found matching your criteria.</p>
<p class="empty-hint">Try a different search term or category.</p>
</div>`;
return;
}
// Update results count
if (resultsCount) {
const toolCount = filtered.reduce((sum, cat) => sum + cat.links.length, 0);
const catLabel = filtered.length === 1 ? "category" : "categories";
const toolLabel = toolCount === 1 ? "tool" : "tools";
resultsCount.textContent = `Showing ${toolCount} ${toolLabel} across ${filtered.length} ${catLabel}`;
}
renderLinks(filtered);
}
function filterByCategory(categoryName) {
currentFilter = categoryName;
// Update active button styles
document.querySelectorAll("#category-filters button").forEach((btn) => {
if (btn.dataset.category === categoryName) {
btn.className =
"bg-blue-600 text-white px-6 py-3 rounded-lg font-medium hover:bg-blue-700 transition-colors flex items-center space-x-2 active-filter";
// Update count styling for active button
const countSpan = btn.querySelector("span:last-child");
if (countSpan) {
countSpan.className =
"bg-blue-500 text-white px-2 py-1 rounded-full text-xs";
}
} else {
btn.className =
"px-6 py-3 rounded-lg font-medium transition-colors flex items-center space-x-2" +
" border-2" +
" hover:border-blue-300";
btn.style.cssText = `
background-color: var(--card-bg);
color: var(--text-secondary);
border-color: var(--border-color);
`;
btn.addEventListener("mouseover", () => {
btn.style.backgroundColor = "var(--bg-tertiary)";
});
btn.addEventListener("mouseout", () => {
btn.style.backgroundColor = "var(--card-bg)";
});
// Update count styling for inactive buttons
const countSpan = btn.querySelector("span:last-child");
if (countSpan) {
countSpan.className = "px-2 py-1 rounded-full text-xs";
countSpan.style.cssText = `
background-color: var(--bg-tertiary);
color: var(--text-secondary);
`;
}
}
});
// Filter and render categories
let filteredCategories;
if (categoryName === "all") {
filteredCategories = allCategories;
} else {
filteredCategories = allCategories.filter(
(category) => category.name === categoryName,
);
}
// Clear and re-render
const mainContent = document.getElementById("main-content");
mainContent.innerHTML = "";
renderLinks(filteredCategories);
// Track filter usage
trackCategoryFilter(categoryName);
}
function renderLinks(categories) {
const mainContent = document.getElementById("main-content");
categories.forEach((category) => {
const categoryDiv = document.createElement("div");
categoryDiv.className = "mb-16";
categoryDiv.setAttribute("data-category", category.name);
// Check if category is expanded
const isExpanded = showAllCategories[category.name] || false;
const linksToShow = isExpanded
? category.links
: category.links.slice(0, 6);
const safeCatName = escapeHtml(category.name);
const catJs = escapeJsString(category.name);
categoryDiv.innerHTML = `
<div class="flex items-center space-x-4 mb-8">
<span class="text-4xl">${escapeHtml(category.icon)}</span>
<h2 class="text-3xl font-bold" style="color: var(--text-primary);">${safeCatName}</h2>
<span class="category-count-pill">${category.links.length}</span>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
${linksToShow
.map((link) => {
const url = safeUrl(link.url);
const host = safeHostname(link.url);
const favicon = faviconUrl(link.url);
return `
<a href="${escapeHtml(url)}" target="_blank" rel="noopener noreferrer"
class="rounded-xl shadow-md hover:shadow-xl transition-all duration-300 p-6 border-2 hover:border-blue-300 card-hover group"
style="background-color: var(--card-bg); border-color: var(--card-border);"
onclick="trackToolClick('${escapeJsString(
link.title,
)}', '${catJs}')">
<div class="flex items-start justify-between mb-4">
<div class="flex items-center gap-3 min-w-0">
${
favicon
? `<img src="${escapeHtml(favicon)}" alt="" loading="lazy"
class="tool-favicon" width="32" height="32"
onerror="this.style.display='none'" />`
: ""
}
<h3 class="text-lg font-semibold group-hover:text-blue-600 transition-colors truncate" style="color: var(--text-primary);">${escapeHtml(
link.title,
)}</h3>
</div>
<i class="fas fa-external-link-alt group-hover:text-blue-500 transition-colors flex-shrink-0 ml-2" style="color: var(--text-tertiary);"></i>
</div>
<p class="mb-4 leading-relaxed" style="color: var(--text-secondary);">${escapeHtml(
link.description,
)}</p>
<div class="flex items-center justify-between">
<span class="text-sm text-blue-600 font-medium truncate">${escapeHtml(
host,
)}</span>
<span class="bg-green-100 text-green-800 text-xs px-2 py-1 rounded-full font-medium flex-shrink-0">Free</span>
</div>
</a>
`;
})
.join("")}
</div>
${
category.links.length > 6
? `
<div class="text-center mt-6">
<button class="show-more-btn" data-action="${
isExpanded ? "show-less" : "show-more"
}" onclick="toggleCategory('${catJs}')">
<span>${isExpanded ? "Show Less" : "Show More"}</span>
</button>
</div>
`
: ""
}
`;
mainContent.appendChild(categoryDiv);
});
}
// Shared builder for a contributor card (used by initial render + pagination).
// Escapes all community-provided fields and hardens external links.
function contributorCardHTML(contributor, index) {
const contributionCount = contributor.contributions
? contributor.contributions.length
: 0;
const modalIndex = allContributors.indexOf(contributor);
const name = escapeHtml(contributor.name);
const nameJs = escapeJsString(contributor.name);
const githubUrl = escapeHtml(
safeUrl("https://github.com/" + contributor.github),
);
return `
<div class="contributor-card-modern no-scroll ${
contributor.featured ? "featured" : ""
}"
style="animation-delay: ${index * 0.05}s"
onclick="openContributorModal(${modalIndex})">
${contributor.featured ? `<div class="floating-badge">Featured</div>` : ""}
<div>
<div class="flex space-x-3 mb-3 no-scroll">
<img src="${escapeHtml(contributor.avatar)}" alt="${name}" loading="lazy"
class="contributor-avatar-modern flex-shrink-0" />
<div class="contributor-info flex-1 min-w-0">
<h4 class="font-semibold text-base truncate" style="color: var(--text-primary);">${name}</h4>
${
contributor.role
? `<p class="text-blue-600 text-sm font-medium mb-1">${escapeHtml(
contributor.role,
)}</p>`
: ""
}
</div>
</div>
${
contributor.tagline
? `<p class="text-xs contributor-tagline truncate" style="color: var(--text-secondary);">"${escapeHtml(
contributor.tagline,
)}"</p>`
: ""
}
</div>
<div class="flex justify-between items-center mt-2 no-scroll">
<div class="contributor-stats">
${
contributionCount > 0
? `<span class="stat-item"><i class="fas fa-star" style="color: #f59e0b;"></i><span>${contributionCount}</span></span>`
: ""
}
</div>
<div class="contributor-social-modern">
<a href="${githubUrl}" target="_blank" rel="noopener noreferrer"
class="social-link-modern" title="GitHub"
onclick="event.stopPropagation(); trackContributorClick('${nameJs}')">
<i class="fab fa-github"></i>
</a>
${
contributor.linkedin
? `<a href="${escapeHtml(
safeUrl("https://linkedin.com/in/" + contributor.linkedin),
)}" target="_blank" rel="noopener noreferrer" class="social-link-modern" title="LinkedIn" onclick="event.stopPropagation()"><i class="fab fa-linkedin"></i></a>`
: ""
}
${
contributor.website
? `<a href="${escapeHtml(
safeUrl(contributor.website),
)}" target="_blank" rel="noopener noreferrer" class="social-link-modern" title="Website" onclick="event.stopPropagation()"><i class="fas fa-globe"></i></a>`
: ""
}
</div>
</div>
</div>
`;
}
function renderContributors(contributors) {
// Update total contributors count
const totalContributorsText = document.getElementById(
"total-contributors-text",
);
if (totalContributorsText) {
totalContributorsText.textContent = contributors.length;
}
// Filter contributors based on search text
if (searchContributorsText.trim()) {
const searchLower = searchContributorsText.toLowerCase();
filteredContributors = contributors.filter(
(c) =>
c.name.toLowerCase().includes(searchLower) ||
(c.tagline && c.tagline.toLowerCase().includes(searchLower)) ||
(c.role && c.role.toLowerCase().includes(searchLower)),
);
} else {
filteredContributors = contributors;
}
// Reset to page 1 when filtering
currentContributorPage = 1;
// Calculate pagination
const totalPages = Math.ceil(
filteredContributors.length / contributorsPerPage,
);
const startIndex = (currentContributorPage - 1) * contributorsPerPage;
const contributorsToShow = filteredContributors.slice(
startIndex,
startIndex + contributorsPerPage,
);
// Render Modern Grid
const modernGrid = document.getElementById("contributors-modern-grid");
if (modernGrid) {
if (filteredContributors.length === 0) {
modernGrid.innerHTML = `
<div class="col-span-full text-center py-12">
<i class="fas fa-search text-4xl" style="color: var(--text-tertiary); opacity: 0.5;"></i>
<p class="mt-4" style="color: var(--text-secondary);">No contributors found matching your search.</p>
</div>
`;
} else {
modernGrid.innerHTML = contributorsToShow
.map((contributor, index) => contributorCardHTML(contributor, index))
.join("");
}
}
// Render pagination controls
renderPaginationControls(totalPages);
}
function renderPaginationControls(totalPages) {
const paginationContainer = document.getElementById("pagination-container");
if (!paginationContainer) return;
if (totalPages <= 1) {
paginationContainer.innerHTML = "";
return;
}
let html = "";
// Previous button
html += `
<button class="pagination-button ${
currentContributorPage === 1 ? "disabled" : ""
}"
${
currentContributorPage === 1
? "disabled"
: "onclick='changeContributorPage(" +
(currentContributorPage - 1) +
")'"
}>
<i class="fas fa-chevron-left"></i>
</button>
`;
// Page numbers with ellipsis
for (let i = 1; i <= totalPages; i++) {
if (
i === 1 ||
i === totalPages ||
(i >= currentContributorPage - 1 && i <= currentContributorPage + 1)
) {
html += `
<button class="pagination-button ${
i === currentContributorPage ? "active" : ""
}"
onclick="changeContributorPage(${i})">
${i}
</button>
`;
} else if (i === 2 || i === totalPages - 1) {
html += `<span class="pagination-info">...</span>`;
}
}
// Next button
html += `
<button class="pagination-button ${
currentContributorPage === totalPages ? "disabled" : ""
}"
${
currentContributorPage === totalPages
? "disabled"
: "onclick='changeContributorPage(" +
(currentContributorPage + 1) +
")'"
}>
<i class="fas fa-chevron-right"></i>
</button>
`;
// Pagination info
const totalDisplayed = filteredContributors.length;
const startNum = Math.min(
(currentContributorPage - 1) * contributorsPerPage + 1,
totalDisplayed,
);
const endNum = Math.min(
currentContributorPage * contributorsPerPage,
totalDisplayed,
);
html += `<span class="pagination-info">Showing ${startNum}-${endNum} of ${totalDisplayed}</span>`;
paginationContainer.innerHTML = html;
}
function changeContributorPage(pageNumber) {
const totalPages = Math.ceil(
filteredContributors.length / contributorsPerPage,
);
if (pageNumber < 1 || pageNumber > totalPages) return;
currentContributorPage = pageNumber;
// Re-render with current filtered contributors
const totalContributorsText = document.getElementById(
"total-contributors-text",
);
if (totalContributorsText) {
totalContributorsText.textContent = filteredContributors.length;
}
// Calculate pagination
const startIndex = (currentContributorPage - 1) * contributorsPerPage;
const contributorsToShow = filteredContributors.slice(
startIndex,
startIndex + contributorsPerPage,
);
// Render Modern Grid
const modernGrid = document.getElementById("contributors-modern-grid");
if (modernGrid) {
modernGrid.innerHTML = contributorsToShow
.map((contributor, index) => contributorCardHTML(contributor, index))
.join("");
}
// Re-render pagination
renderPaginationControls(totalPages);
// Smooth scroll to contributors section
const contributorsSection = document.getElementById("contributors");
if (contributorsSection) {
contributorsSection.scrollIntoView({ behavior: "smooth", block: "start" });
}
}
function openContributorModal(contributorIndex) {
const contributor = allContributors[contributorIndex];
if (!contributor) return;
// Remove any existing modal
const existingModal = document.getElementById("contributor-modal-backdrop");
if (existingModal) {
existingModal.remove();
}
// Create modal HTML
const cName = escapeHtml(contributor.name);
const cWebsite = escapeHtml(safeUrl(contributor.website));
const cWebsiteHost = escapeHtml(safeHostname(contributor.website));
const cGithub = escapeHtml(
safeUrl("https://github.com/" + contributor.github),
);
const cLinkedin = escapeHtml(
safeUrl("https://linkedin.com/in/" + contributor.linkedin),
);
const modalHTML = `
<div id="contributor-modal-backdrop" class="contributor-modal-backdrop active no-scroll">
<div class="contributor-modal no-scroll">
<button class="modal-close-btn" onclick="closeContributorModal()" title="Close">
<i class="fas fa-times"></i>
</button>
<div class="modal-header">
<img src="${escapeHtml(contributor.avatar)}" alt="${cName}" class="modal-avatar" />
<div class="modal-title-section flex-1">
<h2>${cName}</h2>
${
contributor.website
? `<p><i class="fas fa-globe"></i> <a href="${cWebsite}" target="_blank" rel="noopener noreferrer" style="color: #3b82f6;">${cWebsiteHost}</a></p>`
: ""
}
${
contributor.role
? `<div class="modal-role-badge">${escapeHtml(
contributor.role,
)}</div>`
: ""
}
</div>
</div>
${
contributor.tagline
? `
<div class="modal-section">
<p style="color: var(--text-secondary); font-style: italic; border-left: 3px solid #3b82f6; padding-left: 12px;">
"${escapeHtml(contributor.tagline)}"
</p>
</div>
`
: ""
}
${
contributor.contributions && contributor.contributions.length > 0
? `
<div class="modal-section">
<div class="modal-section-title">
<i class="fas fa-star"></i>
<span>Contributions (${contributor.contributions.length})</span>
</div>
<ul class="contributions-list">
${contributor.contributions
.map((contrib) => `<li>${escapeHtml(contrib)}</li>`)
.join("")}
</ul>
</div>
`
: ""
}
<div class="modal-section no-scroll ">
<div class="modal-section-title">
<i class="fas fa-link"></i>
<span>Connect</span>
</div>
<div class="modal-social-links">
<a href="${cGithub}" target="_blank" rel="noopener noreferrer" class="modal-social-link">
<i class="fab fa-github"></i>
<span>GitHub</span>
</a>
${
contributor.linkedin
? `
<a href="${cLinkedin}" target="_blank" rel="noopener noreferrer" class="modal-social-link">
<i class="fab fa-linkedin"></i>
<span>LinkedIn</span>
</a>
`
: ""
}
${
contributor.website
? `
<a href="${cWebsite}" target="_blank" rel="noopener noreferrer" class="modal-social-link">
<i class="fas fa-globe"></i>
<span>Website</span>
</a>
`
: ""
}
</div>
</div>
</div>
</div>
`;
// Append to body
document.body.insertAdjacentHTML("beforeend", modalHTML);
// Close on backdrop click
document
.getElementById("contributor-modal-backdrop")
.addEventListener("click", (e) => {
if (e.target.id === "contributor-modal-backdrop") {
closeContributorModal();
}
});
// Close on Escape key
document.addEventListener("keydown", (e) => {
if (e.key === "Escape") {
closeContributorModal();
}
});
}
function closeContributorModal() {
const modal = document.getElementById("contributor-modal-backdrop");
if (modal) {
modal.classList.remove("active");
setTimeout(() => {
modal.remove();
}, 300);
}
}
function updateStats(categories) {
const totalTools = categories.reduce(
(sum, category) => sum + category.links.length,
0,
);
const totalToolsElement = document.getElementById("total-tools");
if (totalToolsElement) {
totalToolsElement.textContent = totalTools + "+";
}
// Update tools count in status widget
const toolsCountElement = document.getElementById("tools-count");
if (toolsCountElement) {
toolsCountElement.textContent = `${totalTools} tools`;
}
}
function updateContributorStats(count) {
const contributorsElement = document.getElementById("total-contributors");
if (contributorsElement) {
contributorsElement.textContent = count + "+";
}
}
function updateFooterContributorsCount(count) {
// Update ALL footer contributors count elements
const footerContributorsCounts = document.querySelectorAll(
'[id="footer-contributors-count"]',
);
footerContributorsCounts.forEach((element) => {
// Show count or dash if invalid
const displayCount = count && count > 0 ? count : "-";
element.textContent = displayCount;
if (displayCount !== "-") {
element.classList.add("animate-pulse");
setTimeout(() => {
element.classList.remove("animate-pulse");
}, 1000);
}
});
}
// Tooltip functionality
function showTooltip(element) {
const contributorName = element.dataset.contributorName;
const contributionCount = element.dataset.contributionCount;
const contributions = JSON.parse(element.dataset.contributions);
// Remove any existing tooltip
const existingTooltip = document.getElementById("contribution-tooltip-modal");
if (existingTooltip) {
existingTooltip.remove();
}
// Create tooltip HTML
const tooltipHTML = `
<div id="contribution-tooltip-modal" class="tooltip-modal">
<div class="tooltip-backdrop-modal" onclick="closeTooltip()"></div>
<div class="tooltip-content-modal">
<div class="flex justify-between items-center mb-3">
<div class="tooltip-header-modal">Contributions (${contributionCount})</div>
<button class="text-lg transition-colors" onclick="closeTooltip()" title="Close" style="color: var(--text-tertiary);" onmouseover="this.style.color='var(--text-secondary)'" onmouseout="this.style.color='var(--text-tertiary)'">
<i class="fas fa-times"></i>
</button>
</div>
<div class="mb-2 font-medium" style="color: var(--text-secondary);">${contributorName}</div>
<ul class="tooltip-list-modal">
${
contributions.length > 0
? contributions.map((contrib) => `<li>• ${contrib}</li>`).join("")
: "<li>No contributions listed</li>"
}
</ul>
</div>
</div>
`;
// Append to body
document.body.insertAdjacentHTML("beforeend", tooltipHTML);
}
function closeTooltip() {
const tooltip = document.getElementById("contribution-tooltip-modal");
if (tooltip) {
tooltip.remove();
}
}
// Analytics tracking functions
function trackToolClick(toolName, category) {
if (typeof gtag !== "undefined") {
gtag("event", "tool_click", {
tool_name: toolName,
category: category,
event_category: "engagement",
});
}
}
function trackContributorClick(contributorName) {
if (typeof gtag !== "undefined") {
gtag("event", "contributor_click", {
contributor_name: contributorName,
event_category: "engagement",
});
}
}
function trackCategoryFilter(categoryName) {
if (typeof gtag !== "undefined") {
gtag("event", "category_filter", {
category_name: categoryName,
event_category: "navigation",
});
}
}
// Simple mobile menu toggle
function toggleMobileMenu() {
const mobileMenu = document.getElementById("mobile-menu");
const menuIcon = document.getElementById("menu-icon");
if (mobileMenu.classList.contains("hidden")) {
// Show menu
mobileMenu.classList.remove("hidden");
menuIcon.classList.add("rotate");
menuIcon.classList.remove("fa-bars");
menuIcon.classList.add("fa-times");
} else {
// Hide menu
mobileMenu.classList.add("hidden");
menuIcon.classList.remove("rotate");
menuIcon.classList.remove("fa-times");
menuIcon.classList.add("fa-bars");
}
}
function toggleCategory(categoryName) {
showAllCategories[categoryName] = !showAllCategories[categoryName];
applyFilters(); // Re-render with current filters
}
// Initialize everything when DOM is loaded
document.addEventListener("DOMContentLoaded", () => {
// Add smooth scrolling to all anchor links
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute("href"));
if (target) {
target.scrollIntoView({
behavior: "smooth",
block: "start",
});
// Close mobile menu if open
const mobileMenu = document.getElementById("mobile-menu");
if (!mobileMenu.classList.contains("hidden")) {
toggleMobileMenu();
}
}
});
});
// Set up search + category listeners
const searchInput = document.getElementById("tool-search");
if (searchInput) {
const runToolSearch = debounce((value) => {
searchTerm = value;
applyFilters();
}, 180);
searchInput.addEventListener("input", (e) => runToolSearch(e.target.value));
}
// Contributors search listener
const contributorsSearchInput = document.getElementById(
"contributors-search",
);
if (contributorsSearchInput) {
const runContributorSearch = debounce((value) => {
searchContributorsText = value;
renderContributors(allContributors);
}, 180);
contributorsSearchInput.addEventListener("input", (e) =>
runContributorSearch(e.target.value),
);
}
const categorySelect = document.getElementById("category-select");
if (categorySelect) {
categorySelect.addEventListener("change", (e) => {
currentFilter = e.target.value;
syncChipActiveState();
applyFilters();
trackCategoryFilter(currentFilter);
});
}
// Show loading skeletons while data is being fetched
showToolsSkeleton();
// Load content
loadLinks();
loadContributors();
loadGitHubStars();
});
// Lightweight debounce used for search inputs.
function debounce(fn, wait) {
let timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => fn.apply(this, args), wait);
};
}
// Render shimmer placeholder cards while tools load.
function showToolsSkeleton(count = 6) {
const mainContent = document.getElementById("main-content");
if (!mainContent) return;
const card = `
<div class="skeleton-card">
<div class="skeleton-line title"></div>
<div class="skeleton-line"></div>