Skip to content

Commit c76168c

Browse files
committed
Floating pangel now has HTML and CSS files, not injected by JS.
1 parent b5bc42d commit c76168c

11 files changed

+432
-382
lines changed

code-notes.md

Lines changed: 52 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// code-notes.md
12
# OneClickPrompts Chrome Extension - Codebase Overview
23

34
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".
@@ -11,7 +12,7 @@ The OneClickPrompts extension enhances AI chat platforms like ChatGPT, Claude, C
1112
### `manifest.json`
1213

1314
- **Purpose:** Defines the extension's metadata, permissions, background service worker, and content scripts.
14-
- **Role:** This is the central configuration file that tells Chrome how to load and run the extension. It specifies which JavaScript files to inject into which websites.
15+
- **Role:** This is the central configuration file that tells Chrome how to load and run the extension. It specifies which JavaScript and CSS files to inject into which websites and makes resources like HTML templates (`floating-panel.html`) accessible to the content scripts.
1516

1617
### `config.js`
1718

@@ -49,95 +50,81 @@ The OneClickPrompts extension enhances AI chat platforms like ChatGPT, Claude, C
4950

5051
### `floating-panel.js`
5152

52-
- **Purpose:** Implements a floating, customizable button panel for the extension.
53-
- **Role:** Creates a draggable, resizable panel that can be toggled as an alternative to the inline injected buttons. Features include:
54-
- Dark, semi-transparent appearance (rgba(50, 50, 50, 0.7))
55-
- Positioning with the panel's bottom-left corner at the cursor location
56-
- Persistent state and position saved per website using Chrome's extension storage via the service worker
57-
- Draggable header and resizable body
58-
- Toggle button in the original injected button container
59-
- Closing via an "x" button to return to the injected buttons
60-
- Debounced saving (150ms delay) for efficient storage operations
61-
- **Dependencies:**
62-
- **config.js (Service Worker):** Directly communicates with the service worker using `chrome.runtime.sendMessage` to save and load panel settings per website hostname. Sends messages with types 'getFloatingPanelSettings' and 'saveFloatingPanelSettings'.
63-
- **utils.js:** Uses utility functions for logging.
53+
- **Purpose:** Implements the entry point for the OneClickPrompts floating panel.
54+
- **Role:** Defines the `window.MaxExtensionFloatingPanel` namespace, which acts as a global object containing all shared properties and functions for the floating panel. This includes references to the panel element, its visibility state, current settings, and profile information.
55+
56+
### `floating-panel.html`
57+
58+
- **Purpose:** Provides the static HTML structure for the floating panel.
59+
- **Role:** This file defines the panel's complete DOM structure, including the header, content area, queue section, and footer. It is fetched asynchronously by `floating-panel-ui-creation.js` and injected into the page, cleanly separating the panel's structure from its behavior.
60+
61+
### `floating-panel.css`
62+
63+
- **Purpose:** Provides all the styling for the floating panel.
64+
- **Role:** This file contains all CSS rules that define the visual appearance of the floating panel, including its layout, colors, fonts, and opacity. It is injected directly into the web page by the extension's manifest.
6465

6566
### `floating-panel-ui-creation.js`
6667

67-
- **Purpose:** Contains UI creation and basic behavior methods for the floating panel.
68-
- **Role:** Handles creation of the panel DOM structure, profile switcher, drag functionality, positioning at the cursor, and the creation of the toggle button. Key functions:
69-
- `createFloatingPanel()`: Creates the panel element with header, content container, and footer
70-
- `createProfileSwitcher()`: Builds the profile dropdown in the panel footer
71-
- `makeDraggable()`: Enables drag functionality on an element via a handle
72-
- `positionPanelAtCursor()`: Positions the panel relative to the mouse cursor
73-
- `createPanelToggleButton()`: Creates the toggle button for summoning the floating panel
74-
- **Dependencies:**
75-
- **floating-panel.js:** Uses the namespace and properties defined here
76-
- **utils.js:** Uses logging utilities
68+
- **Purpose:** Handles fetching the panel's HTML template, injecting it into the DOM, and setting up its core interactive behaviors.
69+
- **Role:** This script is responsible for loading the visual structure of the panel from `floating-panel.html`. Key functions:
70+
- `createFloatingPanel()`: Fetches `floating-panel.html` asynchronously, appends it to the document body, and attaches initial event listeners (e.g., for the close button). It then calls `initializeQueueSection` to wire up the queue controls.
71+
- `createProfileSwitcher()`: Builds the profile dropdown in the panel footer.
72+
- `makeDraggable()`: Enables drag functionality on the panel's header and footer.
73+
- `positionPanelAtCursor()`: Positions the panel relative to the mouse cursor.
74+
- `createPanelToggleButton()`: Creates the toggle button used to summon the floating panel.
75+
- **Dependencies:** `floating-panel.html`, `floating-panel-ui-queue.js`.
7776

7877
### `floating-panel-ui-interaction.js`
7978

8079
- **Purpose:** Contains UI interaction and state management methods for the floating panel.
8180
- **Role:** Handles toggling panel visibility, moving buttons between containers, updating the panel appearance from settings, restoring state, and refreshing buttons. Key functions:
82-
- `togglePanel()`: Toggles the floating panel's visibility and manages button movement
83-
- `moveButtonsToPanel()`: Moves buttons from the original container to the panel
84-
- `updatePanelFromSettings()`: Updates the panel's appearance and position
85-
- `restorePanelState()`: Restores the panel visibility based on saved settings
86-
- `refreshButtonsInPanel()`: Refreshes the buttons displayed in the panel after a profile switch
87-
- **Dependencies:**
88-
- **floating-panel.js:** Uses the namespace and properties defined here
89-
- **utils.js:** Uses logging utilities
90-
- **floating-panel-ui-creation.js:** Calls methods from here during panel initialization
81+
- `togglePanel()`: An `async` function that toggles the floating panel's visibility. It handles the initial asynchronous creation of the panel via `createFloatingPanel` on the first click.
82+
- `moveButtonsToPanel()`: Moves buttons from the original container to the panel.
83+
- `updatePanelFromSettings()`: Updates the panel’s dynamic styles (like position, size, and opacity).
84+
- `restorePanelState()`: Restores the panel visibility based on saved settings.
85+
- `refreshButtonsInPanel()`: Refreshes the buttons displayed in the panel after a profile switch.
86+
- **Dependencies:** `floating-panel.js`, `floating-panel-ui-creation.js`.
9187

9288
### `floating-panel-ui-queue.js`
9389

94-
- **Purpose:** Contains UI creation logic for the prompt queue section within the floating panel.
95-
- **Role:** Creates the controls (toggle, delay input, play/reset buttons) and the display area for queued items. This function extends the `window.MaxExtensionFloatingPanel` namespace. Key functions:
96-
- `createQueueSection()`: Creates the DOM structure for the queue UI.
97-
- **Dependencies:**
98-
- **floating-panel.js:** Uses the namespace and properties defined here
99-
- **interface.js:** Provides UI creation helpers like `createToggle`
100-
- **config.js:** Provides configuration values like `enableQueueMode`
90+
- **Purpose:** Initializes the interactive elements within the floating panel's queue section.
91+
- **Role:** This script finds the pre-existing queue elements loaded from `floating-panel.html` and attaches the necessary JavaScript logic and event handlers. It no longer creates the DOM elements itself. Key functions:
92+
- `initializeQueueSection()`: Finds the queue toggle, delay input, and control buttons in the DOM and wires up their functionality.
93+
- **Dependencies:** `floating-panel.html` (relies on its structure), `interface.js` (uses `createToggle`).
10194

10295
### `floating-panel-settings.js`
10396

10497
- **Purpose:** Handles settings persistence and profile management for the floating panel.
10598
- **Role:** Includes methods for loading/saving panel settings, debouncing saves, and profile switching. Key functions:
106-
- `loadPanelSettings()`: Retrieves settings from the service worker for the current hostname
107-
- `savePanelSettings()`: Sends updated settings to the service worker for storage
108-
- `debouncedSavePanelSettings()`: Waits 150ms before saving to reduce storage operations
109-
- `loadAvailableProfiles()`: Gets list of profiles from the service worker
110-
- `switchToProfile()`: Changes the current profile and refreshes floating panel content
111-
- **Dependencies:**
112-
- **floating-panel.js:** Uses the namespace and properties defined here
113-
- **floating-panel-ui-creation.js:** Calls the profile switcher creation method
114-
- **floating-panel-ui-interaction.js:** Calls methods to update the UI and refresh buttons
115-
- **config.js (Service Worker):** Communicates with the service worker for settings persistence
99+
- `initialize()`: The main entry point for the floating panel system. It asynchronously calls `createFloatingPanel` and then loads settings and profiles once the panel is in the DOM.
100+
- `loadPanelSettings()`: Retrieves settings from the service worker for the current hostname.
101+
- `savePanelSettings()`: Sends updated settings to the service worker for storage.
102+
- `debouncedSavePanelSettings()`: Waits 150ms before saving to reduce storage operations.
103+
- `loadAvailableProfiles()`: Gets a list of profiles from the service worker.
104+
- `switchToProfile()`: Changes the current profile and refreshes floating panel content.
105+
- **Dependencies:** `floating-panel-ui-creation.js`, `floating-panel-ui-interaction.js`, `config.js`.
116106

117107
### Code File Dependencies for Floating Panel:
118108

119109
- **Initialization Flow:**
120110

121-
1. `floating-panel.js`: Defines the namespace and shared properties
122-
2. `floating-panel-ui-queue.js`: Adds queue creation methods to the namespace
123-
3. `floating-panel-ui-creation.js`: Adds panel creation methods to the namespace
124-
4. `floating-panel-ui-interaction.js`: Adds interaction methods to the namespace
125-
5. `floating-panel-settings.js`: Adds settings methods to the namespace
126-
6. `buttons-init.js`: Calls `initialize()` and creates the toggle button
111+
1. `buttons-init.js`: Calls `MaxExtensionFloatingPanel.initialize()` and creates the toggle button (🔼).
112+
2. `initialize()` in `floating-panel-settings.js` starts the process by calling the `async` function `createFloatingPanel()`.
113+
3. `createFloatingPanel()` in `floating-panel-ui-creation.js` fetches `floating-panel.html`, injects it into the page, attaches core event listeners, and then calls `initializeQueueSection()`.
114+
4. `initializeQueueSection()` in `floating-panel-ui-queue.js` finds the queue elements within the injected HTML and attaches their specific logic.
115+
5. Once `createFloatingPanel()` completes, the `.then()` block in `initialize()` executes, which calls `loadPanelSettings()` and `loadAvailableProfiles()` to populate the now-existing panel with data and restore its state.
127116

128117
- **Panel Summoning Process:**
129118

130-
1. Toggle button calls `togglePanel(event)`
131-
2. First call creates panel without loading settings to avoid race conditions
132-
3. Panel is positioned and displayed immediately
133-
4. Settings are saved asynchronously
119+
1. The toggle button calls the `async` function `togglePanel(event)`.
120+
2. On the first call, `togglePanel` awaits the completion of `createFloatingPanel` to ensure the panel is fully built and initialized.
121+
3. The panel is then positioned, displayed, and buttons are moved into it.
134122

135123
- **Implementation Notes:**
136-
- The floating panel UI was split into creation and interaction files to better separate concerns
137-
- Creation methods handle the DOM structure and initial behavior setup
138-
- Interaction methods manage state transitions and dynamic behavior
139-
- All methods share the same namespace (`window.MaxExtensionFloatingPanel`) defined in `floating-panel.js`
140-
- This modular approach makes the code more maintainable while preserving functionality
124+
- The floating panel's UI has been refactored to use an HTML template (`floating-panel.html`) and an external stylesheet (`floating-panel.css`).
125+
- This approach separates concerns: structure (HTML), presentation (CSS), and behavior (JavaScript), leading to more maintainable code.
126+
- JavaScript files that previously created DOM elements now fetch the template or find elements within it and attach functionality.
127+
- The initialization process is now asynchronous to handle the fetching of the HTML file.
141128

142129
### `init.js`
143130

@@ -274,4 +261,4 @@ The extension operates as follows:
274261
- The `InjectionTargetsOnWebsite` class in `utils.js` centralizes the CSS selectors for different websites, making it easier to support new platforms.
275262
- The floating panel provides an alternative UI that can be positioned anywhere on the screen, offering flexibility for different workflows.
276263
- Button configurations are consistently applied between the inline injection and floating panel modes.
277-
- The extension uses debounced saving to prevent excessive storage writes when the user is dragging or resizing the floating panel.
264+
- The extension uses debounced saving to prevent excessive storage writes when the user is dragging or resizing the floating panel.

floating-panel-queue.css

Whitespace-only changes.

floating-panel-queue.html

Whitespace-only changes.

0 commit comments

Comments
 (0)