-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.js
More file actions
65 lines (57 loc) · 1.98 KB
/
Copy pathsettings.js
File metadata and controls
65 lines (57 loc) · 1.98 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
// Check authentication
// if (!api.isAuthenticated()) {
// window.location.href = 'login.html';
// }
// Add logout functionality
document.addEventListener('DOMContentLoaded', function() {
const dataSection = document.querySelector('.settings-section:last-child');
const logoutBtn = document.createElement('button');
logoutBtn.textContent = 'Logout';
logoutBtn.className = 'danger-btn';
logoutBtn.onclick = () => {
if (confirm('Are you sure you want to logout?')) {
api.logout();
}
};
dataSection.appendChild(logoutBtn);
});
// Settings functionality
function exportData() {
const data = {
tasks: JSON.parse(localStorage.getItem('tasks') || '[]'),
completedTasks: JSON.parse(localStorage.getItem('completedTasks') || '[]'),
walletAmount: localStorage.getItem('walletAmount') || '0'
};
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'quickbucks-data.json';
a.click();
URL.revokeObjectURL(url);
}
function clearData() {
if (confirm('Are you sure you want to clear all data? This cannot be undone.')) {
localStorage.clear();
alert('All data has been cleared.');
}
}
// Theme functionality
document.addEventListener('DOMContentLoaded', function() {
const themeSelect = document.getElementById('theme');
const savedTheme = localStorage.getItem('theme') || 'default';
themeSelect.value = savedTheme;
applyTheme(savedTheme);
themeSelect.addEventListener('change', function() {
const selectedTheme = this.value;
localStorage.setItem('theme', selectedTheme);
applyTheme(selectedTheme);
});
});
function applyTheme(theme) {
if (theme === 'dark') {
document.body.classList.add('dark-theme');
} else {
document.body.classList.remove('dark-theme');
}
}