-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
85 lines (75 loc) · 2.54 KB
/
script.js
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
// Database initialization with complete structure
const defaultDatabase = {
// Change admin credentials here as needed
admin: { id: 'admin', password: 'admin1' },
faculty: {},
students: {},
notices: [],
accounts: {
faculty: {},
students: {}
}
};
function initializeDatabase() {
if (!localStorage.getItem('database')) {
localStorage.setItem('database', JSON.stringify(defaultDatabase));
} else {
// Ensure all required properties exist in existing database
const currentDb = JSON.parse(localStorage.getItem('database'));
// Update admin credentials if they've changed in defaultDatabase
currentDb.admin = defaultDatabase.admin;
const updatedDb = {
...defaultDatabase,
...currentDb,
admin: defaultDatabase.admin, // Ensure admin credentials are always updated
faculty: currentDb.faculty || {},
students: currentDb.students || {},
notices: currentDb.notices || [],
accounts: {
faculty: currentDb.accounts?.faculty || {},
students: currentDb.accounts?.students || {}
}
};
localStorage.setItem('database', JSON.stringify(updatedDb));
}
}
// Initialize database on script load
initializeDatabase();
// Eye animation
document.addEventListener('DOMContentLoaded', () => {
const eyes = document.querySelectorAll('.eye');
const pupils = document.querySelectorAll('.pupil');
// Eye following cursor
document.addEventListener('mousemove', (e) => {
eyes.forEach(eye => {
const rect = eye.getBoundingClientRect();
const eyeCenterX = rect.left + rect.width / 2;
const eyeCenterY = rect.top + rect.height / 2;
const angle = Math.atan2(e.clientY - eyeCenterY, e.clientX - eyeCenterX);
const distance = Math.min(eye.offsetWidth / 4, Math.hypot(e.clientX - eyeCenterX, e.clientY - eyeCenterY) / 15);
const pupil = eye.querySelector('.pupil');
const x = Math.cos(angle) * distance;
const y = Math.sin(angle) * distance;
pupil.style.transform = `translate(calc(-50% + ${x}px), calc(-50% + ${y}px))`;
});
});
// Blinking animation
function blink() {
eyes.forEach(eye => {
eye.style.height = '2px';
eye.style.transition = 'height 0.15s ease';
setTimeout(() => {
eye.style.height = '';
eye.style.transition = 'height 0.15s ease';
}, 150);
});
}
function scheduleBlink() {
const randomTime = Math.random() * (7000 - 3000) + 3000;
setTimeout(() => {
blink();
scheduleBlink();
}, randomTime);
}
scheduleBlink();
});