-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
278 lines (244 loc) · 10.1 KB
/
script.js
File metadata and controls
278 lines (244 loc) · 10.1 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
document.addEventListener('DOMContentLoaded', function() {
// Enhanced data simulation with real-time updates
const data = {
networkHealth: { status: "healthy", lastScan: "2025-07-18 16:00", detectedThreats: 0 },
alerts: [
{ level: "warning", message: "Unusual DNS query behavior detected.", time: "2025-07-18 15:59" },
{ level: "error", message: "Potential data exfiltration detected.", time: "2025-07-18 16:02" }
],
llmSummary: "Network activity is normal. No data exfiltration or known attack vectors detected. Recent increase in DNS traffic observed, but within expected range.",
stats: { threats: 2, devices: 5, connections: 22 }
};
// Fancy loading animation for stats
function animateCounter(element, target, duration = 2000) {
const start = 0;
const increment = target / (duration / 16);
let current = start;
const timer = setInterval(() => {
current += increment;
if (current >= target) {
current = target;
clearInterval(timer);
}
element.textContent = Math.floor(current);
}, 16);
}
// Typewriter effect for AI summary
function typeWriter(element, text, speed = 50) {
element.textContent = '';
let i = 0;
const timer = setInterval(() => {
if (i < text.length) {
element.textContent += text.charAt(i);
i++;
} else {
clearInterval(timer);
}
}, speed);
}
// Pulse animation for threat icons
function pulseThreats() {
const threatIcons = document.querySelectorAll('.threat-icon');
threatIcons.forEach(icon => {
icon.style.animation = 'pulse 2s infinite';
});
}
// Rotate pie chart animation
function animatePieChart() {
const pieChart = document.querySelector('.pie-chart');
if (pieChart) {
pieChart.style.animation = 'rotate 10s linear infinite';
}
}
// Loading states
function showLoading(elementId) {
const element = document.getElementById(elementId);
if (element) {
element.innerHTML = '<div class="loading-spinner"></div>';
}
}
function hideLoading(elementId, content) {
const element = document.getElementById(elementId);
if (element) {
setTimeout(() => {
element.innerHTML = content;
}, 1000);
}
}
// Enhanced snackbar with different types
function showSnackbar(message, type = 'info', duration = 4000) {
const snackbar = document.getElementById('snackbar') || createSnackbar();
snackbar.textContent = message;
snackbar.className = `snackbar show ${type}`;
setTimeout(() => {
snackbar.className = snackbar.className.replace('show', '');
}, duration);
}
function createSnackbar() {
const snackbar = document.createElement('div');
snackbar.id = 'snackbar';
snackbar.className = 'snackbar';
document.body.appendChild(snackbar);
return snackbar;
}
// Initialize loading states
showLoading('health-status');
showLoading('last-scan');
showLoading('detected-threats');
showLoading('alerts-list');
showLoading('llm-summary');
// Simulate data loading with delays
setTimeout(() => {
// Update Network Health with animation
hideLoading('health-status', data.networkHealth.status);
hideLoading('last-scan', data.networkHealth.lastScan);
hideLoading('detected-threats', data.networkHealth.detectedThreats);
// Animate stat counters
const statsElements = document.querySelectorAll('.stat .value');
statsElements.forEach((el, index) => {
const values = [data.stats.threats, data.stats.devices, data.stats.connections];
if (values[index]) {
animateCounter(el, values[index]);
}
});
// Update Alerts with fancy animation
const alertsList = document.getElementById('alerts-list');
if (data.alerts.length === 0) {
hideLoading('alerts-list', '<p>No alerts.</p>');
} else {
let alertsHTML = '';
data.alerts.forEach((alert, index) => {
alertsHTML += `<div class="alert alert-${alert.level}" style="animation-delay: ${index * 0.2}s">[${alert.time}] ${alert.message}</div>`;
});
hideLoading('alerts-list', alertsHTML);
// Show notification
setTimeout(() => {
showSnackbar(`${data.alerts.length} network alerts detected!`, 'warning');
}, 1500);
}
// Typewriter effect for AI summary
setTimeout(() => {
const summaryElement = document.getElementById('llm-summary');
if (summaryElement) {
typeWriter(summaryElement, data.llmSummary, 30);
}
}, 2000);
// Start fancy animations
setTimeout(() => {
pulseThreats();
animatePieChart();
}, 3000);
}, 500);
// Enhanced click handlers with visual feedback
function addClickHandler(elementId, url, message) {
const element = document.getElementById(elementId);
if (element) {
element.addEventListener('click', function(e) {
// Visual feedback
this.style.transform = 'scale(0.95)';
setTimeout(() => {
this.style.transform = 'translateY(-3px)';
}, 150);
// Show loading message
showSnackbar(`Loading ${message}...`, 'info', 2000);
// Navigate after delay
setTimeout(() => {
window.location.href = url;
}, 1000);
});
// Hover effects
element.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-5px) scale(1.02)';
this.style.boxShadow = '0 8px 25px rgba(0,123,255,0.15)';
});
element.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(-3px) scale(1)';
this.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.08)';
});
}
}
// Add enhanced click handlers
addClickHandler('threats-stat', 'threats.html', 'Threats Dashboard');
addClickHandler('devices-stat', 'devices.html', 'Devices Dashboard');
addClickHandler('connections-stat', 'connections.html', 'Connections Dashboard');
addClickHandler('threats-box', 'threats-details.html', 'Threat Details');
addClickHandler('devices-box', 'devices-details.html', 'Device Details');
// Auto-refresh functionality
function autoRefresh() {
// Simulate new data
const newThreatCount = Math.floor(Math.random() * 5) + 1;
const newDeviceCount = Math.floor(Math.random() * 10) + 3;
const newConnectionCount = Math.floor(Math.random() * 50) + 10;
// Update counters with animation
setTimeout(() => {
const statsElements = document.querySelectorAll('.stat .value');
if (statsElements[0]) animateCounter(statsElements[0], newThreatCount, 1000);
if (statsElements[1]) animateCounter(statsElements[1], newDeviceCount, 1000);
if (statsElements[2]) animateCounter(statsElements[2], newConnectionCount, 1000);
}, 1000);
// Random new alert
if (Math.random() > 0.7) {
setTimeout(() => {
showSnackbar('New security event detected!', 'warning');
}, 2000);
}
}
// Start auto-refresh every 30 seconds
setInterval(autoRefresh, 30000);
// Add keyboard shortcuts
document.addEventListener('keydown', function(e) {
if (e.ctrlKey || e.metaKey) {
switch(e.key) {
case 'r':
e.preventDefault();
showSnackbar('Refreshing dashboard...', 'info');
setTimeout(() => location.reload(), 1000);
break;
case '1':
e.preventDefault();
document.getElementById('threats-stat')?.click();
break;
case '2':
e.preventDefault();
document.getElementById('devices-stat')?.click();
break;
case '3':
e.preventDefault();
document.getElementById('connections-stat')?.click();
break;
}
}
});
// Add floating particles effect
function createParticles() {
const particlesContainer = document.createElement('div');
particlesContainer.className = 'particles-container';
document.body.appendChild(particlesContainer);
for (let i = 0; i < 50; i++) {
setTimeout(() => {
const particle = document.createElement('div');
particle.className = 'particle';
particle.style.left = Math.random() * 100 + '%';
particle.style.animationDuration = (Math.random() * 3 + 2) + 's';
particle.style.animationDelay = Math.random() * 2 + 's';
particlesContainer.appendChild(particle);
// Remove particle after animation
setTimeout(() => {
if (particle.parentNode) {
particle.parentNode.removeChild(particle);
}
}, 5000);
}, i * 100);
}
}
// Easter egg - double click logo for particles
const logo = document.querySelector('.logo');
if (logo) {
logo.addEventListener('dblclick', function() {
createParticles();
showSnackbar('✨ Easter egg activated! ✨', 'success');
});
}
console.log('🚀 Enhanced NAR Dashboard loaded with fancy animations!');
showSnackbar('Dashboard loaded successfully!', 'success', 3000);
});