-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
268 lines (219 loc) Β· 8.71 KB
/
Copy pathscript.js
File metadata and controls
268 lines (219 loc) Β· 8.71 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
class PregnancyStatus {
constructor() {
this.statusData = null;
this.init();
}
async init() {
try {
await this.loadStatus();
this.updateUI();
} catch (error) {
console.error('Error loading status:', error);
this.showError();
}
}
async loadStatus() {
try {
const response = await fetch(`status.json?t=${Date.now()}`);
if (!response.ok) {
throw new Error('Status file not found');
}
this.statusData = await response.json();
} catch (error) {
this.statusData = {
currentStatus: 1,
lastUpdated: new Date().toISOString(),
statuses: {
1: "Nothing new - All is well! π",
2: "In Labor - It's starting! π€±",
3: "In the delivery room - Almost there! πΆ",
4: "Gave birth - Welcome to the world! π"
}
};
console.warn('Using default status data');
}
}
updateUI() {
const currentStatus = this.statusData.currentStatus;
const statusInfo = this.statusData.statuses[currentStatus];
this.updateStatusDisplay(currentStatus, statusInfo);
this.updateProgressBar(currentStatus);
this.updateLastUpdated();
// Show page load celebration for current status
this.showPageLoadCelebration(currentStatus);
if (currentStatus === 4) {
this.showCelebration();
}
}
updateStatusDisplay(currentStatus, statusInfo) {
const titleElement = document.getElementById('status-title');
const messageElement = document.getElementById('status-message');
const titles = {
1: "Nothing new",
2: "In Labor!",
3: "In the delivery room!",
4: "Baby is here!"
};
titleElement.textContent = titles[currentStatus];
messageElement.textContent = statusInfo;
titleElement.className = `status-${currentStatus}`;
}
updateProgressBar(currentStatus) {
const steps = document.querySelectorAll('.progress-step');
const progressFill = document.getElementById('progress-fill');
steps.forEach((step, index) => {
const stepNumber = index + 1;
const circle = step.querySelector('.step-circle');
circle.classList.remove('active', 'completed');
if (stepNumber < currentStatus) {
circle.classList.add('completed');
} else if (stepNumber === currentStatus) {
circle.classList.add('active');
}
});
const progressPercentage = ((currentStatus - 1) / 3) * 100;
progressFill.style.width = `${progressPercentage}%`;
}
updateLastUpdated() {
const lastUpdatedElement = document.getElementById('last-updated');
const lastUpdated = new Date(this.statusData.lastUpdated);
const options = {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
timeZone: 'Asia/Jerusalem'
};
lastUpdatedElement.textContent = lastUpdated.toLocaleDateString('en-US', options);
}
showCelebration() {
const celebration = document.getElementById('celebration');
celebration.style.display = 'flex';
this.createConfetti();
celebration.addEventListener('click', () => {
celebration.style.display = 'none';
});
setTimeout(() => {
celebration.style.display = 'none';
}, 10000);
}
createConfetti() {
const celebration = document.getElementById('celebration');
const confettiEmojis = ['π', 'π', 'πΆ', 'π', 'π', 'β¨'];
for (let i = 0; i < 20; i++) {
const confetti = document.createElement('div');
confetti.className = 'confetti';
confetti.textContent = confettiEmojis[Math.floor(Math.random() * confettiEmojis.length)];
confetti.style.left = Math.random() * 100 + '%';
confetti.style.animationDelay = Math.random() * 2 + 's';
confetti.style.animationDuration = (Math.random() * 2 + 2) + 's';
celebration.appendChild(confetti);
setTimeout(() => {
confetti.remove();
}, 4000);
}
}
showPageLoadCelebration(currentStatus) {
const statusEmojis = {
1: ['π ', 'π', 'π', 'β¨', 'π'],
2: ['β°', 'π€±', 'πͺ', 'π', 'β¨'],
3: ['π₯', 'πΆ', 'π', 'π', 'β¨'],
4: ['π', 'π', 'πΆ', 'π', 'π', 'β¨', 'π', 'πΌ']
};
const emojis = statusEmojis[currentStatus] || statusEmojis[1];
// Create explosion effect around the current status circle
const activeStep = document.querySelector(`.progress-step[data-step="${currentStatus}"]`);
if (!activeStep) return;
const stepRect = activeStep.getBoundingClientRect();
const centerX = stepRect.left + stepRect.width / 2;
const centerY = stepRect.top + stepRect.height / 2;
for (let i = 0; i < 15; i++) {
const emoji = document.createElement('div');
emoji.textContent = emojis[Math.floor(Math.random() * emojis.length)];
// Random direction and distance for explosion
const angle = (Math.PI * 2 * i) / 15 + (Math.random() - 0.5) * 0.5;
const distance = 80 + Math.random() * 120;
const endX = Math.cos(angle) * distance;
const endY = Math.sin(angle) * distance;
emoji.style.cssText = `
position: fixed;
font-size: 24px;
pointer-events: none;
z-index: 1000;
left: ${centerX - 12}px;
top: ${centerY - 12}px;
transform: translate(0, 0);
animation: explode-${i} 3s ease-out forwards;
`;
// Create unique animation for each emoji
const keyframes = `
@keyframes explode-${i} {
0% {
transform: translate(0, 0) scale(0.5) rotate(0deg);
opacity: 1;
}
50% {
transform: translate(${endX * 0.7}px, ${endY * 0.7}px) scale(1.2) rotate(${Math.random() * 360}deg);
opacity: 0.9;
}
100% {
transform: translate(${endX}px, ${endY}px) scale(0.3) rotate(${Math.random() * 720}deg);
opacity: 0;
}
}
`;
// Add the keyframes to a style element
const style = document.createElement('style');
style.textContent = keyframes;
document.head.appendChild(style);
document.body.appendChild(emoji);
setTimeout(() => {
emoji.remove();
style.remove();
}, 3000);
}
}
showError() {
const titleElement = document.getElementById('status-title');
const messageElement = document.getElementById('status-message');
const lastUpdatedElement = document.getElementById('last-updated');
titleElement.textContent = "Unable to load status";
messageElement.textContent = "Please check back later π";
lastUpdatedElement.textContent = "Error loading data";
}
async refresh() {
await this.loadStatus();
this.updateUI();
}
}
document.addEventListener('DOMContentLoaded', () => {
const pregnancyStatus = new PregnancyStatus();
// Add click event listener for emoji explosion
document.addEventListener('click', () => {
if (pregnancyStatus.statusData) {
pregnancyStatus.showPageLoadCelebration(pregnancyStatus.statusData.currentStatus);
}
});
setInterval(() => {
pregnancyStatus.refresh();
}, 30000);
});
let touchStartY = 0;
let touchEndY = 0;
document.addEventListener('touchstart', (e) => {
touchStartY = e.changedTouches[0].screenY;
});
document.addEventListener('touchend', (e) => {
touchEndY = e.changedTouches[0].screenY;
handleSwipe();
});
function handleSwipe() {
const swipeThreshold = 50;
const diff = touchStartY - touchEndY;
if (Math.abs(diff) > swipeThreshold) {
if (diff > 0) {
window.location.reload();
}
}
}