Repository navigation
Expand file tree
/
Copy pathonboarding.js
More file actions
255 lines (224 loc) · 7.84 KB
/
Copy pathonboarding.js
File metadata and controls
255 lines (224 loc) · 7.84 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
/**
* Tab Suspender Pro - Onboarding JavaScript
*/
let currentStep = 1;
const totalSteps = 5;
// DOM Elements - initialized after DOMContentLoaded
let stepsContainer, progressFill, stepDots, backBtn, nextBtn, skipLink;
let setupTimeout, setupTimeoutValue;
let demoBtn, demoTab1, demoTab2, demoResult;
// Initialize
document.addEventListener('DOMContentLoaded', () => {
// Query DOM elements after DOM is ready
stepsContainer = document.getElementById('stepsContainer');
progressFill = document.getElementById('progressFill');
stepDots = document.getElementById('stepDots');
backBtn = document.getElementById('backBtn');
nextBtn = document.getElementById('nextBtn');
skipLink = document.getElementById('skipLink');
setupTimeout = document.getElementById('setupTimeout');
setupTimeoutValue = document.getElementById('setupTimeoutValue');
demoBtn = document.getElementById('demoBtn');
demoTab1 = document.getElementById('demoTab1');
demoTab2 = document.getElementById('demoTab2');
demoResult = document.getElementById('demoResult');
// Now initialize
updateUI();
setupEventListeners();
createParticles();
});
// Setup Event Listeners
function setupEventListeners() {
if (nextBtn) nextBtn.addEventListener('click', nextStep);
if (backBtn) backBtn.addEventListener('click', prevStep);
if (skipLink) skipLink.addEventListener('click', skipOnboarding);
// Timeout slider
if (setupTimeout) {
setupTimeout.addEventListener('input', updateTimeoutDisplay);
}
// Demo button
if (demoBtn) {
demoBtn.addEventListener('click', runDemo);
}
// Clickable dots navigation
document.querySelectorAll('.dot').forEach(dot => {
dot.addEventListener('click', () => {
const targetStep = parseInt(dot.dataset.step);
if (targetStep && targetStep !== currentStep) {
currentStep = targetStep;
updateUI();
}
});
});
}
// Navigate to next step
function nextStep() {
if (currentStep < totalSteps) {
currentStep++;
updateUI();
if (currentStep === totalSteps && nextBtn) {
// Last step - save settings and mark onboarding complete
saveSettings();
nextBtn.textContent = 'Get Started';
nextBtn.onclick = finishOnboarding;
}
}
}
// Navigate to previous step
function prevStep() {
if (currentStep > 1) {
currentStep--;
updateUI();
}
}
// Update UI based on current step
function updateUI() {
// Update steps visibility
document.querySelectorAll('.step').forEach((step, index) => {
step.classList.toggle('active', index + 1 === currentStep);
});
// Update progress bar
if (progressFill) {
progressFill.style.width = `${(currentStep / totalSteps) * 100}%`;
}
// Update dots
document.querySelectorAll('.dot').forEach((dot, index) => {
const stepNum = index + 1;
dot.classList.remove('active', 'completed');
if (stepNum === currentStep) {
dot.classList.add('active');
} else if (stepNum < currentStep) {
dot.classList.add('completed');
}
});
// Update step counter
const stepCounter = document.getElementById('stepCounter');
if (stepCounter) {
stepCounter.textContent = `Step ${currentStep} of ${totalSteps}`;
}
// Update back button visibility
if (backBtn) {
backBtn.classList.toggle('hidden', currentStep === 1);
}
// Update next button text
if (nextBtn) {
if (currentStep === totalSteps) {
nextBtn.innerHTML = `Get Started <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"></polyline></svg>`;
nextBtn.onclick = finishOnboarding;
} else {
nextBtn.innerHTML = `Next <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>`;
nextBtn.onclick = nextStep;
}
}
}
// Update timeout display
function updateTimeoutDisplay() {
const value = parseInt(setupTimeout.value);
if (value < 60) {
setupTimeoutValue.textContent = `${value} min`;
} else {
setupTimeoutValue.textContent = `${Math.floor(value / 60)} hr`;
}
}
// Run demo animation
async function runDemo() {
if (!demoBtn) return;
demoBtn.disabled = true;
// Animate tabs being suspended
setTimeout(() => {
if (demoTab1) {
demoTab1.classList.add('suspended');
const status = demoTab1.querySelector('.demo-status');
if (status) {
status.textContent = 'Suspended';
status.className = 'demo-status suspended';
}
}
}, 300);
setTimeout(() => {
if (demoTab2) {
demoTab2.classList.add('suspended');
const status = demoTab2.querySelector('.demo-status');
if (status) {
status.textContent = 'Suspended';
status.className = 'demo-status suspended';
}
}
}, 600);
setTimeout(() => {
if (demoBtn) demoBtn.style.display = 'none';
if (demoResult) demoResult.classList.remove('hidden');
}, 1000);
}
// Save settings from onboarding
async function saveSettings() {
try {
const settings = {
suspensionTimeout: parseInt(setupTimeout?.value) || 30,
neverSuspendAudio: document.getElementById('setupAudio')?.checked ?? true,
neverSuspendUnsavedForms: document.getElementById('setupForms')?.checked ?? true,
suspendPinnedTabs: !(document.getElementById('setupPinned')?.checked ?? true),
whitelistedDomains: []
};
// Collect whitelisted domains
document.querySelectorAll('.whitelist-chips input:checked').forEach(input => {
const domain = input.dataset.domain;
if (domain) {
settings.whitelistedDomains.push(domain);
}
});
await chrome.runtime.sendMessage({ type: 'SAVE_SETTINGS', settings });
} catch (error) {
console.error('Failed to save settings:', error);
}
}
// Skip onboarding
async function skipOnboarding(e) {
e.preventDefault();
await markOnboardingComplete();
window.close();
}
// Finish onboarding
async function finishOnboarding() {
await saveSettings();
await markOnboardingComplete();
window.close();
}
// Mark onboarding as complete
async function markOnboardingComplete() {
try {
await chrome.storage.local.set({ onboardingComplete: true });
} catch (error) {
console.error('Failed to mark onboarding complete:', error);
}
}
// Create floating particles
function createParticles() {
const container = document.getElementById('particles');
if (!container) return;
for (let i = 0; i < 20; i++) {
const particle = document.createElement('div');
particle.style.cssText = `
position: absolute;
width: ${Math.random() * 4 + 2}px;
height: ${Math.random() * 4 + 2}px;
background: rgba(124, 58, 237, ${Math.random() * 0.3 + 0.1});
border-radius: 50%;
left: ${Math.random() * 100}%;
top: ${Math.random() * 100}%;
animation: float ${Math.random() * 10 + 10}s linear infinite;
`;
container.appendChild(particle);
}
// Add float animation
const style = document.createElement('style');
style.textContent = `
@keyframes float {
0%, 100% { transform: translateY(0) translateX(0); opacity: 0; }
10% { opacity: 1; }
90% { opacity: 1; }
100% { transform: translateY(-100vh) translateX(${Math.random() * 100 - 50}px); opacity: 0; }
}
`;
document.head.appendChild(style);
}