Skip to content

Commit 14216dd

Browse files
author
Maxim Fomin
committed
Floating panel now does not spawns in settings pages after successfull traditional injection: allows to open settings fine
1 parent f638d8c commit 14216dd

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

buttons-injection.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ function buttonBoxCheckingAndInjection(enableResiliency = true, activeWebsite) {
7878
// Insert custom elements (custom send buttons and toggles) into the target container.
7979
window.MaxExtensionButtonsInit.createAndInsertCustomElements(targetDiv);
8080

81+
// Mark this tab as "inline healthy" — once we have ever injected successfully,
82+
// we never auto-summon the fallback panel again in this tab.
83+
try {
84+
window.__OCP_inlineHealthy = true;
85+
} catch (_) {}
86+
8187
// Ensure the inline selector inside does not close due to bubbling site handlers
8288
try {
8389
const selector = targetDiv.querySelector('select');

floating-panel-ui-creation.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ window.MaxExtensionFloatingPanel.createFloatingPanel = async function () {
6363
this.updatePanelFromSettings();
6464

6565
// Attach event listeners
66-
closeButton.addEventListener('click', () => this.togglePanel());
66+
closeButton.addEventListener('click', () => {
67+
// If the user closes the panel, don’t auto-reopen it for this tab.
68+
try {
69+
window.__OCP_userDisabledFallback = true;
70+
} catch (_) {}
71+
this.togglePanel();
72+
});
6773

6874
this.makeDraggable(panel, panelHeader);
6975
this.makeDraggable(panel, profileSwitcherContainer);

init.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ async function commenceExtensionInitialization(configurationObject) {
223223
} else {
224224
logConCgp('[init] Decide-first: Panel is hidden. Using standard inline injection.');
225225
buttonBoxCheckingAndInjection(true);
226-
226+
// Initialize per-tab flags if absent
227+
if (typeof window.__OCP_inlineHealthy === 'undefined') window.__OCP_inlineHealthy = false;
227228
/**
228229
* When inline injection fails (e.g., because the target container cannot be found),
229230
* there is no user click event to supply a mouse position for the floating panel.
@@ -234,18 +235,16 @@ async function commenceExtensionInitialization(configurationObject) {
234235
setTimeout(() => {
235236
try {
236237
// Check if inline buttons were injected by looking for the container and its children.
237-
let modsExist = false;
238-
try {
238+
let modsExist = (() => {
239239
const containerId = window?.InjectionTargetsOnWebsite?.selectors?.buttonsContainerId;
240-
if (containerId) {
240+
if (!containerId) return false;
241241
const el = document.getElementById(containerId);
242-
modsExist = !!(el && el.children && el.children.length > 0);
243-
}
244-
} catch (_) {
245-
modsExist = false;
246-
}
242+
return !!(el && el.children && el.children.length > 0);
243+
})();
247244
// Only trigger fallback if no mods exist and the panel isn’t already visible.
248-
if (!modsExist && window.MaxExtensionFloatingPanel && !window.MaxExtensionFloatingPanel.isPanelVisible) {
245+
const userDisabled = !!window.__OCP_userDisabledFallback;
246+
if (!modsExist && !window.__OCP_inlineHealthy && !userDisabled &&
247+
window.MaxExtensionFloatingPanel && !window.MaxExtensionFloatingPanel.isPanelVisible) {
249248
logConCgp("[init] We haven't found the place to inject buttons, so we will fall back to a floating panel instead.");
250249
window.MaxExtensionFloatingPanel.createFloatingPanel().then(() => {
251250
const panelElement = window.MaxExtensionFloatingPanel.panelElement;
@@ -267,6 +266,7 @@ async function commenceExtensionInitialization(configurationObject) {
267266
panelElement.style.display = 'flex';
268267
window.MaxExtensionFloatingPanel.isPanelVisible = true;
269268
if (window.MaxExtensionFloatingPanel.currentPanelSettings) {
269+
// note: do not set inlineHealthy here — we are in fallback mode
270270
window.MaxExtensionFloatingPanel.currentPanelSettings.isVisible = true;
271271
window.MaxExtensionFloatingPanel.debouncedSavePanelSettings?.();
272272
}

0 commit comments

Comments
 (0)