@@ -2,31 +2,72 @@ const sidebarToggle = "_execute_sidebar_action";
22
33// Update UI and set value of textbox
44async 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
1418async 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
2246async 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