55// as cards in <div id="buttonCardsList" ...> </div>
66// This file creates elements that represent custom buttons (card like elements)
77// Button cards contain: emoji input, text input, auto-send toggle, delete button, that are
8- // used to create custom buttons for the extension.
8+ // used to create custom buttons for the extension.
99// and separators for mostly visual funciton (separatprs behave like button cards with less stuff)
10- // separator cards contain: visuals, delete button.
11- // version: 1.0
10+ // separator cards contain: visuals, delete button.
11+ // version: 1.1
1212
1313// -------------------------
1414// Special constants
1515// -------------------------
1616const SETTINGS_BUTTON_MAGIC_TEXT = '%OCP_APP_SETTINGS_SYSTEM_BUTTON%' ;
1717
18+ /**
19+ * Gets the Cross-Chat module settings.
20+ * @returns {Promise<Object> } - The Cross-Chat module settings.
21+ */
22+ async function getCrossChatSettings ( ) {
23+ try {
24+ const response = await chrome . runtime . sendMessage ( { type : 'getCrossChatModuleSettings' } ) ;
25+ return response && response . settings ? response . settings : { enabled : false , placement : 'after' } ;
26+ } catch ( error ) {
27+ console . error ( 'Error fetching Cross-Chat settings:' , error ) ;
28+ return { enabled : false , placement : 'after' } ; // Default fallback
29+ }
30+ }
31+
1832// -------------------------
1933// Create Button Element - this is start of everything, there can be zero to infinite buttons
2034// -------------------------
@@ -25,7 +39,7 @@ const SETTINGS_BUTTON_MAGIC_TEXT = '%OCP_APP_SETTINGS_SYSTEM_BUTTON%';
2539 * @param {number } index - The index of the button in the customButtons array.
2640 * @returns {HTMLElement } - The button item element.
2741 */
28- function createButtonCardElement ( button , index ) {
42+ function createButtonCardElement ( button , index , crossChatSettings = null ) {
2943 const buttonItem = document . createElement ( 'div' ) ;
3044 buttonItem . className = 'button-item' ;
3145 buttonItem . dataset . index = index ;
@@ -50,9 +64,27 @@ function createButtonCardElement(button, index) {
5064 ? `<div class="autosend-line"><label class="checkbox-row"><input type="checkbox" class="autosend-toggle" ${ button . autoSend ? 'checked' : '' } ><span>Auto-send</span></label></div>`
5165 : '' ;
5266
53- const hotkeyHintHTML = index < 10
54- ? `<div class="shortcut-line"><span class="shortcut-indicator">[Alt+${ index === 9 ? 0 : index + 1 } ]</span></div>`
55- : '' ;
67+ // Calculate hotkey with consideration for CrossChat buttons and separators
68+ let hotkeyHintHTML = '' ;
69+ if ( ! button . separator ) {
70+ // Calculate how many non-separator buttons are before this one
71+ let nonSeparatorButtonsCount = 0 ;
72+ for ( let i = 0 ; i < index ; i ++ ) {
73+ if ( ! currentProfile . customButtons [ i ] . separator ) {
74+ nonSeparatorButtonsCount ++ ;
75+ }
76+ }
77+
78+ // Apply the shift if CrossChat buttons are placed before
79+ const shift = ( crossChatSettings && crossChatSettings . enabled && crossChatSettings . placement === 'before' ) ? 2 : 0 ;
80+ const hotkeyIndex = nonSeparatorButtonsCount + shift ;
81+
82+ // Only show hotkey if it's within the 1-0 range (Alt+1 to Alt+0)
83+ if ( hotkeyIndex < 10 ) {
84+ const displayKey = hotkeyIndex === 9 ? 0 : hotkeyIndex + 1 ;
85+ hotkeyHintHTML = `<div class="shortcut-line"><span class="shortcut-indicator">[Alt+${ displayKey } ]</span></div>` ;
86+ }
87+ }
5688
5789 buttonItem . innerHTML = `
5890 <div class="drag-handle">☰</div>
@@ -78,11 +110,14 @@ function createButtonCardElement(button, index) {
78110/**
79111 * Updates the list of custom button cards in the buttonCardsList.
80112 */
81- function updatebuttonCardsList ( ) {
113+ async function updatebuttonCardsList ( ) {
114+ // Get Cross-Chat module settings
115+ const crossChatSettings = await getCrossChatSettings ( ) ;
116+
82117 buttonCardsList . innerHTML = '' ; // This already removes old listeners
83118 if ( currentProfile . customButtons && currentProfile . customButtons . length > 0 ) {
84119 currentProfile . customButtons . forEach ( ( button , index ) => {
85- const buttonElement = createButtonCardElement ( button , index ) ;
120+ const buttonElement = createButtonCardElement ( button , index , crossChatSettings ) ;
86121 buttonCardsList . appendChild ( buttonElement ) ;
87122 } ) ;
88123 } else {
0 commit comments