-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
133 lines (110 loc) · 3.89 KB
/
Copy pathscript.js
File metadata and controls
133 lines (110 loc) · 3.89 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
const items = document.querySelectorAll('.nav-item');
const sections = document.querySelectorAll('.chapter, .hero');
const sidebarToggle = document.getElementById('sidebarToggle');
const sidebar = document.getElementById('sidebarNav');
const clockTime = document.getElementById('clockTime');
const clockDate = document.getElementById('clockDate');
const calendarMonth = document.getElementById('calendarMonth');
const calendarGrid = document.getElementById('calendarGrid');
const quoteText = document.getElementById('quoteText');
const quoteAuthor = document.getElementById('quoteAuthor');
const SIDEBAR_STATE_KEY = 'cp-sidebar-collapsed';
const setSidebarState = (isCollapsed) => {
document.body.classList.toggle('sidebar-collapsed', isCollapsed);
if (sidebarToggle) {
sidebarToggle.setAttribute('aria-expanded', String(!isCollapsed));
sidebarToggle.setAttribute('aria-label', isCollapsed ? 'Expand sidebar' : 'Collapse sidebar');
}
};
const savedSidebarState = localStorage.getItem(SIDEBAR_STATE_KEY);
if (savedSidebarState !== null) {
setSidebarState(savedSidebarState === 'true');
}
if (sidebarToggle && sidebar) {
sidebarToggle.addEventListener('click', () => {
const isCollapsed = !document.body.classList.contains('sidebar-collapsed');
setSidebarState(isCollapsed);
localStorage.setItem(SIDEBAR_STATE_KEY, String(isCollapsed));
});
}
window.addEventListener('scroll', () => {
let current = '';
sections.forEach((section) => {
if (window.scrollY >= section.offsetTop - 100) {
current = section.id;
}
});
items.forEach((item) => {
item.classList.toggle('active', item.getAttribute('href') === `#${current}`);
});
});
const updateClock = () => {
if (!clockTime || !clockDate) {
return;
}
const now = new Date();
clockTime.textContent = now.toLocaleTimeString('en-US', {
hour12: false,
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
clockDate.textContent = now.toLocaleDateString('en-US', {
weekday: 'long',
month: 'long',
day: 'numeric',
year: 'numeric'
});
};
const renderCalendar = () => {
if (!calendarMonth || !calendarGrid) {
return;
}
const today = new Date();
const year = today.getFullYear();
const month = today.getMonth();
const monthStart = new Date(year, month, 1);
const daysInMonth = new Date(year, month + 1, 0).getDate();
const startOffset = (monthStart.getDay() + 6) % 7;
calendarMonth.textContent = today.toLocaleDateString('en-US', {
month: 'long',
year: 'numeric'
});
calendarGrid.innerHTML = '';
for (let i = 0; i < startOffset; i += 1) {
const emptyCell = document.createElement('span');
emptyCell.className = 'calendar-cell empty';
calendarGrid.appendChild(emptyCell);
}
for (let day = 1; day <= daysInMonth; day += 1) {
const dayCell = document.createElement('span');
dayCell.className = 'calendar-cell';
dayCell.textContent = String(day);
if (day === today.getDate()) {
dayCell.classList.add('today');
}
calendarGrid.appendChild(dayCell);
}
};
const quotes = [
{ text: 'Discipline beats motivation when the contest starts.', author: 'CP Wisdom' },
{ text: 'First make it correct, then make it fast.', author: 'Programming Principle' },
{ text: 'Every wrong answer teaches the next accepted solution.', author: 'Contest Mindset' },
{ text: 'Patterns appear only after enough solved problems.', author: 'Daily Practice Rule' },
{ text: 'Think in constraints, code in clarity.', author: 'Problem Solving Rule' }
];
let quoteIndex = 0;
const updateQuote = () => {
if (!quoteText || !quoteAuthor) {
return;
}
const currentQuote = quotes[quoteIndex % quotes.length];
quoteText.textContent = `"${currentQuote.text}"`;
quoteAuthor.textContent = `- ${currentQuote.author}`;
quoteIndex += 1;
};
updateClock();
renderCalendar();
updateQuote();
setInterval(updateClock, 1000);
setInterval(updateQuote, 10000);