Skip to content

Commit 0281dc8

Browse files
committed
Shift now inverts autosend behavior if used wiht alt + number shortcut
1 parent ea763f0 commit 0281dc8

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

init.js

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,44 @@ function commenceExtensionInitialization(configurationObject) {
8787
}
8888

8989

90-
// TODO: Shift key inverts autoSend for custom send buttons
91-
/**
92-
* Manages keyboard shortcut events to trigger custom send buttons on the webpage.
93-
* Listens for Alt+[1-10] key presses and simulates button clicks.
94-
* @param {KeyboardEvent} event - The keyboard event object.
95-
*/
96-
function manageKeyboardShortcutEvents(event) {
97-
if (!globalMaxExtensionConfig.enableShortcuts) return;
98-
99-
if (event.altKey && !event.shiftKey && !event.ctrlKey && !event.metaKey) {
100-
const pressedKey = event.key === '0' ? '10' : event.key;
101-
const targetButton = document.querySelector(`button[data-shortcut-key="${pressedKey}"]`);
102-
if (targetButton) {
103-
event.preventDefault();
104-
targetButton.click();
105-
} else {
106-
logConCgp('[init] No button found for the pressed shortcut key:', pressedKey);
107-
}
90+
/**
91+
* Manages keyboard shortcut events to trigger custom send buttons on the webpage.
92+
* Listens for Alt+[1-10] key presses and simulates button clicks.
93+
* If Shift is also pressed, it inverts the autoSend flag for this press only.
94+
* @param {KeyboardEvent} event - The keyboard event object.
95+
*/
96+
function manageKeyboardShortcutEvents(event) {
97+
if (!globalMaxExtensionConfig.enableShortcuts) return;
98+
99+
// Only handle events where Alt is pressed and the key is a digit [1-10]
100+
if (
101+
event.altKey &&
102+
!event.ctrlKey &&
103+
!event.metaKey &&
104+
event.code.startsWith('Digit')
105+
) {
106+
let pressedKey = event.code.replace('Digit', '');
107+
if (pressedKey === '0') pressedKey = '10';
108+
109+
const targetButton = document.querySelector(`button[data-shortcut-key="${pressedKey}"]`);
110+
if (targetButton) {
111+
event.preventDefault();
112+
// Create a new MouseEvent with shiftKey set based on the current event
113+
const clickEvent = new MouseEvent('click', {
114+
bubbles: true,
115+
cancelable: true,
116+
view: window,
117+
shiftKey: event.shiftKey
118+
});
119+
targetButton.dispatchEvent(clickEvent);
120+
} else {
121+
logConCgp('[init] No button found for the pressed shortcut key:', pressedKey);
108122
}
109123
}
124+
}
125+
126+
127+
110128

111129
/**
112130
*

0 commit comments

Comments
 (0)