Skip to content

Commit 13937c8

Browse files
committed
enhance keyboard shortcut functionality to support all active websites
1 parent 01e4ae1 commit 13937c8

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

init.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// init.js
21
// Version: 1.5
32
//
43
// Documentation:
@@ -69,7 +68,7 @@ function publicStaticVoidMain() {
6968
async 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
*/
153153
function 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

Comments
 (0)