-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsettings.js
More file actions
94 lines (80 loc) · 3.58 KB
/
Copy pathsettings.js
File metadata and controls
94 lines (80 loc) · 3.58 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
// Load stored data into fields
window.onload = function() {
const email = localStorage.getItem('userEmail');
const password = localStorage.getItem('userPassword');
// Display stored data or default to "N/A"
const usernameDisplay = document.getElementById('username-display');
const passwordDisplay = document.getElementById('password-display');
usernameDisplay.value = email || '';
usernameDisplay.placeholder = email ? '' : 'N/A';
passwordDisplay.value = password || '';
passwordDisplay.placeholder = password ? '' : 'N/A';
// Set notification switch state
const isNotificationEnabled = localStorage.getItem('sendDailyNotifications') === 'true';
document.getElementById('notification-toggle').checked = isNotificationEnabled;
// Set social switch state
const isSocialEnabled = localStorage.getItem('shareWithFriends') === 'true';
document.getElementById('social-toggle').checked = isSocialEnabled;
// Initially set fields to read-only
usernameDisplay.readOnly = true;
passwordDisplay.readOnly = true;
};
// Toggle editing for username and password
function toggleEdit() {
const usernameInput = document.getElementById('username-display');
const passwordInput = document.getElementById('password-display');
const changeButton = document.getElementById('change-btn');
// Toggle the readonly state for username and password
if (usernameInput.readOnly && passwordInput.readOnly) {
// Enable editing
usernameInput.readOnly = false;
passwordInput.readOnly = false;
usernameInput.focus();
changeButton.textContent = 'Save'; // Change text to "Save"
} else {
// Save changes and disable editing
const newUsername = usernameInput.value;
const newPassword = passwordInput.value;
// Store the new username and password in localStorage
localStorage.setItem('userEmail', newUsername);
localStorage.setItem('userPassword', newPassword);
// Set the fields back to read-only
usernameInput.readOnly = true;
passwordInput.readOnly = true;
changeButton.textContent = 'Change'; // Change text back to "Change"
}
}
// Toggle password visibility
function togglePassword() {
const passwordInput = document.getElementById('password-display');
const passwordToggleBtn = document.getElementById('toggle-password');
if (passwordInput.type === 'password') {
passwordInput.type = 'text'; // Show password
passwordToggleBtn.textContent = '🙈'; // Change icon to "🙈"
} else {
passwordInput.type = 'password'; // Hide password
passwordToggleBtn.textContent = '👁️'; // Change icon back to "👁️"
}
}
// Toggle the setting for daily notifications
function toggleNotification() {
const isChecked = document.getElementById('notification-toggle').checked;
if (isChecked) {
console.log("Daily notifications enabled.");
localStorage.setItem('sendDailyNotifications', 'true');
} else {
console.log("Daily notifications disabled.");
localStorage.setItem('sendDailyNotifications', 'false');
}
}
// Toggle the setting for sharing habits with friends
function toggleSocial() {
const isChecked = document.getElementById('social-toggle').checked;
if (isChecked) {
console.log("Sharing habits with friends enabled.");
localStorage.setItem('shareWithFriends', 'true');
} else {
console.log("Sharing habits with friends disabled.");
localStorage.setItem('shareWithFriends', 'false');
}
}