-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathsidebar.js
More file actions
45 lines (36 loc) · 1.65 KB
/
sidebar.js
File metadata and controls
45 lines (36 loc) · 1.65 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
// Common Sidebar JavaScript for DevDunia
document.addEventListener('DOMContentLoaded', function() {
// Track tool usage
function trackToolUsage(toolName, toolUrl) {
let recentTools = JSON.parse(localStorage.getItem('recentTools') || '[]');
// Remove if already exists
recentTools = recentTools.filter(tool => tool.url !== toolUrl);
// Add to beginning
recentTools.unshift({ name: toolName, url: toolUrl });
// Keep only last 5
recentTools = recentTools.slice(0, 5);
localStorage.setItem('recentTools', JSON.stringify(recentTools));
}
// Add click tracking to all tool links
document.querySelectorAll('.sidebar-item[href$=".html"]').forEach(link => {
link.addEventListener('click', function() {
const toolName = this.querySelector('.sidebar-text')?.textContent.trim() || 'Unknown Tool';
const toolUrl = this.getAttribute('href');
trackToolUsage(toolName, toolUrl);
});
});
// Set active sidebar item based on current page
function setActiveSidebarItem() {
const currentPage = window.location.pathname.split('/').pop();
const sidebarItems = document.querySelectorAll('.sidebar-item[href$=".html"]');
sidebarItems.forEach(item => {
item.classList.remove('active');
const itemHref = item.getAttribute('href');
if (itemHref === currentPage || (currentPage === '' && itemHref === 'index.html')) {
item.classList.add('active');
}
});
}
// Initialize active item
setActiveSidebarItem();
});