Skip to content

Commit 73cc1f1

Browse files
committed
enhancement: add user feedback on success/error
1 parent de6e43c commit 73cc1f1

File tree

3 files changed

+61
-15
lines changed

3 files changed

+61
-15
lines changed

src/options/options.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,8 @@ footer p a {
9898

9999
footer p a:hover {
100100
color: red;
101+
}
102+
103+
#status {
104+
margin-top: 1rem;
101105
}

src/options/options.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ <h1 class="nav-title">
2828
</form>
2929
<button id="update">Update</button>
3030
<button id="reset">Reset</button>
31+
<div id="status"></div>
3132
</main>
3233

3334
<footer>

src/options/options.js

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,72 @@ const sidebarToggle = "_execute_sidebar_action";
22

33
// Update UI and set value of textbox
44
async function updateUI() {
5-
let commands = await browser.commands.getAll();
6-
for (command of commands) {
7-
if (command.name === sidebarToggle) {
8-
document.querySelector("#shortcut").value = command.shortcut;
5+
try {
6+
const commands = await browser.commands.getAll();
7+
for (const command of commands) {
8+
if (command.name === sidebarToggle) {
9+
document.querySelector("#shortcut").value = command.shortcut;
10+
}
911
}
12+
} catch (error) {
13+
console.error("Error updating UI:", error);
1014
}
1115
}
1216

1317
// Update shortcut to value of textbox
1418
async function updateShortcut() {
15-
await browser.commands.update({
16-
name: sidebarToggle,
17-
shortcut: document.querySelector("#shortcut").value,
18-
});
19+
try {
20+
await browser.commands.update({
21+
name: sidebarToggle,
22+
shortcut: document.querySelector("#shortcut").value,
23+
});
24+
// Provide visual feedback
25+
const statusElement = document.querySelector("#status");
26+
if (statusElement) {
27+
statusElement.textContent = "Shortcut updated successfully!";
28+
setTimeout(() => {
29+
statusElement.textContent = "";
30+
}, 2000);
31+
}
32+
} catch (error) {
33+
console.error("Error updating shortcut:", error);
34+
// Show error message
35+
const statusElement = document.querySelector("#status");
36+
if (statusElement) {
37+
statusElement.textContent = "Error updating shortcut. Please try again.";
38+
setTimeout(() => {
39+
statusElement.textContent = "";
40+
}, 2000);
41+
}
42+
}
1943
}
2044

2145
// Reset shortcut and update textbox
2246
async function resetShortcut() {
23-
await browser.commands.reset(sidebarToggle);
24-
updateUI();
47+
try {
48+
await browser.commands.reset(sidebarToggle);
49+
await updateUI();
50+
// Provide visual feedback
51+
const statusElement = document.querySelector("#status");
52+
if (statusElement) {
53+
statusElement.textContent = "Shortcut reset successfully!";
54+
setTimeout(() => {
55+
statusElement.textContent = "";
56+
}, 2000);
57+
}
58+
} catch (error) {
59+
console.error("Error resetting shortcut:", error);
60+
}
2561
}
2662

27-
// Update UI on page load
28-
document.addEventListener("DOMContentLoaded", updateUI);
63+
// Initialize event listeners
64+
function initEventListeners() {
65+
document.querySelector("#update").addEventListener("click", updateShortcut);
66+
document.querySelector("#reset").addEventListener("click", resetShortcut);
67+
}
2968

30-
// Act on update and reset buttons
31-
document.querySelector("#update").addEventListener("click", updateShortcut);
32-
document.querySelector("#reset").addEventListener("click", resetShortcut);
69+
// Update UI and set up event listeners on page load
70+
document.addEventListener("DOMContentLoaded", () => {
71+
updateUI();
72+
initEventListeners();
73+
});

0 commit comments

Comments
 (0)