1- // init.js
21// Version: 1.5
32//
43// Documentation:
@@ -69,7 +68,7 @@ function publicStaticVoidMain() {
6968async function commenceExtensionInitialization ( configurationObject ) {
7069 logConCgp ( '[init] Async initialization started.' ) ;
7170 // Configs are now set in publicStaticVoidMain before this is called.
72- window . globalMaxExtensionConfig = configurationObject ;
71+ window . globalMaxExtensionConfig = configurationObject ;
7372
7473 /**
7574 * Helper to get panel visibility setting from storage, wrapped in a Promise.
@@ -130,9 +129,10 @@ async function commenceExtensionInitialization(configurationObject) {
130129 // or when navigating away from the relevant site.
131130 window . removeEventListener ( 'keydown' , manageKeyboardShortcutEvents ) ;
132131
133- if ( activeWebsite === 'ChatGPT' && window . globalMaxExtensionConfig . enableShortcuts ) {
132+ // Activate shortcuts on ANY supported site, not just ChatGPT.
133+ if ( activeWebsite !== 'Unknown' && window . globalMaxExtensionConfig . enableShortcuts ) {
134134 window . addEventListener ( 'keydown' , manageKeyboardShortcutEvents ) ;
135- logConCgp ( ' [init] Keyboard shortcut listener is active for ChatGPT.' ) ;
135+ logConCgp ( ` [init] Keyboard shortcut listener is active for ${ activeWebsite } .` ) ;
136136 }
137137
138138 resilientStartAndRetryOnSPANavigation ( ( ) => {
@@ -152,12 +152,21 @@ async function commenceExtensionInitialization(configurationObject) {
152152 */
153153function manageKeyboardShortcutEvents ( event ) {
154154 if ( ! globalMaxExtensionConfig . enableShortcuts ) return ;
155+
156+ // We check for Alt key, but not Ctrl or Meta (Cmd/Win). The 'code' property is layout-independent.
155157 if ( event . altKey && ! event . ctrlKey && ! event . metaKey && event . code . startsWith ( 'Digit' ) ) {
156- let pressedKey = event . code . replace ( 'Digit' , '' ) ;
157- if ( pressedKey === '0' ) pressedKey = '10' ;
158+ let pressedKey = parseInt ( event . code . replace ( 'Digit' , '' ) , 10 ) ;
159+ // Map Alt+0 to shortcut key 10.
160+ if ( pressedKey === 0 ) {
161+ pressedKey = 10 ;
162+ }
163+
164+ // Find the button with the corresponding data-shortcut-key attribute.
158165 const targetButton = document . querySelector ( `button[data-shortcut-key="${ pressedKey } "]` ) ;
166+
159167 if ( targetButton ) {
160168 event . preventDefault ( ) ;
169+ // Simulate a click event. Pass the shiftKey status so users can override autosend.
161170 const clickEvent = new MouseEvent ( 'click' , { bubbles : true , cancelable : true , view : window , shiftKey : event . shiftKey } ) ;
162171 targetButton . dispatchEvent ( clickEvent ) ;
163172 } else {
0 commit comments