-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetting.js
More file actions
98 lines (84 loc) · 3.65 KB
/
Copy pathsetting.js
File metadata and controls
98 lines (84 loc) · 3.65 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
document.addEventListener('DOMContentLoaded', function() {
const loginForm = document.getElementById('login-form');
const settingsContent = document.getElementById('settings-content');
const passwordInput = document.getElementById('password-input');
const loginBtn = document.getElementById('login-btn');
const logoutBtn = document.getElementById('logout-btn');
const saveBtn = document.getElementById('save-btn');
const errorMessage = document.getElementById('error-message');
// Check authentication state
chrome.storage.local.get(['isAuthenticated', 'settings', 'passwordHash'], function(data) {
if (data.isAuthenticated) {
showSettings();
loadSettings(data.settings || {});
}
});
// Login handler
loginBtn.addEventListener('click', authenticate);
// Password input - allow Enter key to submit
passwordInput.addEventListener('keyup', function(e) {
if (e.key === 'Enter') authenticate();
});
// Logout handler
logoutBtn.addEventListener('click', function() {
chrome.storage.local.set({ isAuthenticated: false });
showLogin();
passwordInput.value = '';
});
// Save settings handler
saveBtn.addEventListener('click', function() {
const newPassword = document.getElementById('new-password').value;
const confirmPassword = document.getElementById('confirm-password').value;
// Get current settings
const settings = {
blockImages: document.getElementById('block-images').checked,
blockWords: document.getElementById('block-words').checked
};
// Update password if new one provided
if (newPassword && confirmPassword) {
if (newPassword !== confirmPassword) {
alert("Passwords don't match!");
return;
}
// In production, you should hash the password here
chrome.storage.local.set({ passwordHash: newPassword });
document.getElementById('new-password').value = '';
document.getElementById('confirm-password').value = '';
}
// Save all settings
chrome.storage.local.set({
settings: settings,
isAuthenticated: true // Keep logged in after save
}, function() {
alert('Settings saved successfully!');
});
});
function authenticate() {
const enteredPassword = passwordInput.value;
chrome.storage.local.get(['passwordHash'], function(data) {
// In production, you would hash the entered password and compare
const storedPassword = data.passwordHash || 'admin123'; // Default password
if (enteredPassword === storedPassword) {
chrome.storage.local.set({ isAuthenticated: true });
showSettings();
loadSettings();
} else {
errorMessage.textContent = "Incorrect password!";
passwordInput.value = '';
}
});
}
function showSettings() {
loginForm.style.display = 'none';
settingsContent.style.display = 'block';
}
function showLogin() {
loginForm.style.display = 'block';
settingsContent.style.display = 'none';
errorMessage.textContent = '';
}
function loadSettings(settings) {
document.getElementById('block-images').checked = settings.blockImages !== false;
document.getElementById('block-words').checked = settings.blockWords !== false;
}
});