You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document provides a high-level overview of the OneClickPrompts Chrome Extension codebase. It describes the purpose of each file and its role within the extension. Extension was previously called "ChatGPT Quick Buttons for your text".
@@ -8,6 +6,16 @@ This document provides a high-level overview of the OneClickPrompts Chrome Exten
8
6
9
7
The OneClickPrompts extension enhances AI chat platforms like ChatGPT, Claude, Copilot, DeepSeek, AI Studio, Gemini, and Grok by adding customizable buttons that inject pre-defined prompts into the chat input area. It also includes features for managing profiles, enabling keyboard shortcuts, and customizing the user interface.
10
8
9
+
## Core Reliability Pattern: Crash-Only / Self-Healing DOM Injection
10
+
11
+
A foundational architectural decision in this extension is the use of a **"Crash-only"** (or **"Self-healing"**) reliability pattern for managing the UI in the dynamic, and often hostile, DOM of the target Single-Page Applications (SPAs).
12
+
13
+
-**The Problem:** The DOM on sites like ChatGPT is unpredictable. Elements are frequently destroyed and re-created, making simple, "surgical" DOM manipulations fragile. An attempt to insert a button can fail if the target container disappears at the wrong millisecond.
14
+
-**The Solution:** Instead of writing complex recovery code for every possible failure, the extension embraces a "let-it-crash" philosophy. Any time the UI's integrity is in question (e.g., after an SPA navigation or when closing the floating panel), the extension triggers a full, **idempotent re-initialization** of its UI components.
15
+
-**Why It Works:** This approach delegates UI creation to the robust resiliency engine in `buttons-injection.js`, which is designed to patiently wait for injection targets and handle dynamic changes. This trades a small amount of computational efficiency for a massive gain in reliability, ensuring the extension's UI is always present and functional. This pattern is analogous to forcing a re-mount in frameworks like React by changing a component's `key`.
16
+
17
+
This "Crash-only" principle informs the design of `init.js`, `buttons-injection.js`, and `floating-panel-ui-interaction.js`.
18
+
11
19
## File Descriptions
12
20
13
21
### `manifest.json`
@@ -80,7 +88,7 @@ The OneClickPrompts extension enhances AI chat platforms like ChatGPT, Claude, C
80
88
-**Purpose:** Contains UI interaction and state management methods for the floating panel.
81
89
-**Role:** Handles toggling panel visibility and updating the panel appearance from settings. The old "hide and clone" mechanism has been completely replaced.
82
90
-**Key functions:**
83
-
-`togglePanel()`: An `async` function that toggles the floating panel's visibility using a **"destroy and re-create"** mechanism. When toggled ON, it destroys the inline buttons and re-creates them inside the panel. When toggled OFF, it does the reverse.
91
+
-`togglePanel()`: An `async` function that toggles the floating panel's visibility. When closed, it intentionally triggers the extension's main `publicStaticVoidMain()` initializer, delegating the button re-creation to the robust **"Crash-only"** resiliency engine.
84
92
-`updatePanelFromSettings()`: Updates the panel’s dynamic styles (like position, size, and opacity).
85
93
86
94
### `floating-panel-ui-queue.js`
@@ -137,8 +145,8 @@ The OneClickPrompts extension enhances AI chat platforms like ChatGPT, Claude, C
137
145
138
146
### `init.js`
139
147
140
-
-**Purpose:** Main initialization script for the content script. It acts as the **Director** of the initial UI setup.
141
-
-**Role:** Implements a **"decide first, then create"** architecture to prevent UI flicker. It asynchronously checks if the floating panel should be visible for the current site *before* rendering any buttons. Based on this setting, it either injects the buttons into the traditional inline location (via `buttons-injection.js`) or directly into the floating panel, which it creates on demand. It also orchestrates the initialization of the full floating panel system in a controlled sequence to prevent race conditions.
148
+
-**Purpose:** Main initialization script for the content script. It acts as the **Director** of the initial UI setup and embodies the **Crash-only** philosophy.
149
+
-**Role:** Implements a **"decide first, then create"** architecture to prevent UI flicker. It asynchronously checks if the floating panel should be visible for the current site _before_ rendering any buttons. Based on this setting, it either injects the buttons into the traditional inline location (via `buttons-injection.js`) or directly into the floating panel. Its main initialization function (`publicStaticVoidMain`) is designed to be **idempotent** and is called on page load, SPA navigation, and panel closing to ensure a consistent and reliable UI state.
142
150
143
151
### `interface.js`
144
152
@@ -157,8 +165,8 @@ The OneClickPrompts extension enhances AI chat platforms like ChatGPT, Claude, C
157
165
158
166
### `buttons-injection.js`
159
167
160
-
-**Purpose:** Handles the injection of custom buttons into the webpage for the **inline mode**.
161
-
-**Role:** This script is now primarily used when `init.js` decides that the floating panel should be hidden on initial load. It finds the correct injection point on the page and implements a resiliency mechanism to re-inject the elements if they disappear due to dynamic page updates.
168
+
-**Purpose:** Handles the injection of custom buttons into the webpage for the **inline mode** and provides the core resiliency mechanism.
169
+
-**Role:** This script is now primarily used when `init.js` decides that the floating panel should be hidden on initial load. It finds the correct injection point on the page and implements a **self-healing**resiliency mechanism (using `MutationObserver` and timeouts) to re-inject the elements if they disappear due to dynamic page updates.
@@ -258,11 +266,10 @@ The extension operates as follows:
258
266
259
267
1. The user configures the extension through the popup interface (`popup.html` and `popup-page-scripts/*`).
260
268
2. The configuration is stored in Chrome's storage by the service worker (`config.js`).
261
-
3. When the user visits a supported website, the content scripts are injected into the page.
262
-
4. The main content script (`init.js`) first checks if the floating panel should be visible. It then creates the custom buttons directly in the correct location (either inline or inside the newly created floating panel) to prevent any visual flicker.
263
-
5. When the user toggles the panel's visibility, the buttons are destroyed from their current location and re-created in the new one.
264
-
6. The floating panel's position, size, and visibility state are saved per website and restored when revisiting.
265
-
7. When the user clicks a custom button:
269
+
3. When the user visits a supported website, the content scripts are injected. The main initializer (`init.js`) then decides whether to create the UI inline or in the floating panel, based on saved settings, preventing any visual flicker.
270
+
4. If the UI disappears due to SPA updates, the **self-healing** resiliency engine in `buttons-injection.js` detects the change and triggers a full, idempotent re-initialization.
271
+
5. When the user closes the floating panel, this also triggers the same idempotent re-initialization, reliably moving the buttons back to their inline location.
272
+
6. When the user clicks a custom button:
266
273
- If the floating panel is active and Queue Mode is on, the prompt is added to a queue. The queue sends prompts sequentially with a configurable delay.
267
274
- Otherwise, the appropriate site-specific function is called to insert the text and trigger the send button.
268
275
@@ -272,4 +279,4 @@ The extension operates as follows:
272
279
- The `InjectionTargetsOnWebsite` class in `utils.js` centralizes the CSS selectors for different websites, making it easier to support new platforms.
273
280
- The floating panel provides an alternative UI that can be positioned anywhere on the screen, offering flexibility for different workflows.
274
281
- Button configurations are consistently applied between the inline injection and floating panel modes.
275
-
- The extension uses debounced saving to prevent excessive storage writes when the user is dragging or resizing the floating panel.
282
+
- The extension uses debounced saving to prevent excessive storage writes when the user is dragging or resizing the floating panel.
0 commit comments