@@ -175,31 +175,49 @@ window.MaxExtensionButtonsInit = {
175175
176176 /**
177177 * Updates all buttons and toggles in response to a profile change.
178- * This refreshes both the floating panel and the original container.
178+ * Accepts an optional `origin` parameter:
179+ * - 'panel' => only update the floating panel UI
180+ * - 'inline' => only update the inline buttons UI
181+ * - null/undefined => update both (legacy behavior)
179182 */
180- updateButtonsForProfileChange : function ( ) {
181- // Update buttons in the original container
183+ updateButtonsForProfileChange : function ( origin = null ) {
184+ // If origin is 'panel', only update the floating panel
185+ if ( origin === 'panel' ) {
186+ if ( window . MaxExtensionFloatingPanel && window . MaxExtensionFloatingPanel . panelElement ) {
187+ const panelContent = document . getElementById ( 'max-extension-floating-panel-content' ) ;
188+ if ( panelContent ) {
189+ panelContent . innerHTML = '' ;
190+ this . generateAndAppendAllButtons ( panelContent , true ) ;
191+ logConCgp ( '[init] Updated buttons in floating panel for profile change (panel origin).' ) ;
192+ }
193+ }
194+ return ;
195+ }
196+
197+ // If origin is 'inline', only update the inline/original container
198+ if ( origin === 'inline' ) {
199+ const originalContainer = document . getElementById ( window . InjectionTargetsOnWebsite . selectors . buttonsContainerId ) ;
200+ if ( originalContainer ) {
201+ originalContainer . innerHTML = '' ;
202+ this . generateAndAppendAllButtons ( originalContainer , false ) ;
203+ logConCgp ( '[init] Updated buttons in original container for profile change (inline origin).' ) ;
204+ }
205+ return ;
206+ }
207+
208+ // Legacy/default: update both containers
182209 const originalContainer = document . getElementById ( window . InjectionTargetsOnWebsite . selectors . buttonsContainerId ) ;
183210 if ( originalContainer ) {
184- // Clear existing buttons and toggles
185211 originalContainer . innerHTML = '' ;
186-
187- // Note: toggles are now appended within generateAndAppendAllButtons() at the very end
188212 this . generateAndAppendAllButtons ( originalContainer , false ) ; // Not panel
189-
190213 logConCgp ( '[init] Updated buttons in original container for profile change.' ) ;
191214 }
192-
193- // Update buttons in the floating panel if it exists and is initialized
215+
194216 if ( window . MaxExtensionFloatingPanel && window . MaxExtensionFloatingPanel . panelElement ) {
195217 const panelContent = document . getElementById ( 'max-extension-floating-panel-content' ) ;
196218 if ( panelContent ) {
197- // Clear existing buttons and toggles
198219 panelContent . innerHTML = '' ;
199-
200- // Note: toggles are now appended within generateAndAppendAllButtons() at the very end
201220 this . generateAndAppendAllButtons ( panelContent , true ) ; // This is the panel
202-
203221 logConCgp ( '[init] Updated buttons in floating panel for profile change.' ) ;
204222 }
205223 }
@@ -275,17 +293,18 @@ window.MaxExtensionButtonsInit.createInlineProfileSelector = async function () {
275293 select . addEventListener ( 'change' , ( e ) => {
276294 const selected = e . target . value ;
277295 // Request switch and refresh immediately using service worker response for reliability.
278- chrome . runtime . sendMessage ( { type : 'switchProfile' , profileName : selected } , ( response ) => {
296+ // Include origin so receiver can limit refresh scope to inline UI only.
297+ chrome . runtime . sendMessage ( { type : 'switchProfile' , profileName : selected , origin : 'inline' } , ( response ) => {
279298 if ( response && response . config ) {
280299 // Immediate local refresh; SW also broadcasts to other tabs
281300 if ( typeof window . __OCP_partialRefreshUI === 'function' ) {
282- window . __OCP_partialRefreshUI ( response . config ) ;
301+ window . __OCP_partialRefreshUI ( response . config , 'inline' ) ;
283302 } else if ( typeof window . __OCP_nukeAndRefresh === 'function' ) {
284- window . __OCP_nukeAndRefresh ( response . config ) ;
303+ window . __OCP_nukeAndRefresh ( response . config , 'inline' ) ;
285304 } else if ( window . MaxExtensionButtonsInit && typeof window . MaxExtensionButtonsInit . updateButtonsForProfileChange === 'function' ) {
286305 // Fallback: partial refresh
287306 window . globalMaxExtensionConfig = response . config ;
288- window . MaxExtensionButtonsInit . updateButtonsForProfileChange ( ) ;
307+ window . MaxExtensionButtonsInit . updateButtonsForProfileChange ( 'inline' ) ;
289308 }
290309 }
291310 } ) ;
0 commit comments