Skip to content

Commit ca34f09

Browse files
committed
getDefaultSelectorsForSite now uses utils
1 parent e79f8d2 commit ca34f09

File tree

3 files changed

+21
-107
lines changed

3 files changed

+21
-107
lines changed

code-notes.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ These scripts are responsible for the user interface in the extension's popup wi
209209

210210
* **Purpose:** Handles the advanced selector configuration.
211211
* **Role:** Enables users to customize CSS selectors for different AI chat platforms.
212+
* **Implementation:**
213+
* Provides a user interface for viewing and editing selectors for each supported website
214+
* Retrieves default selectors directly from the `InjectionTargetsOnWebsite` class in `utils.js`
215+
* Maintains a single source of truth for selector definitions, eliminating duplication
216+
* Allows saving custom selectors which override the defaults on a per-site basis
217+
* **Dependencies:**
218+
* **utils.js:** Uses the `getDefaultSelectors` method to retrieve the canonical selector definitions
219+
* **config.js (Service Worker):** Communicates with the service worker to save and load custom selectors
212220

213221
### `popup-page-scripts/popup-page-floating-window-handler.js`
214222

popup-page-scripts/popup-page-advanced.js

Lines changed: 12 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -81,113 +81,18 @@ document.addEventListener('DOMContentLoaded', () => {
8181

8282
// Helper function to get default selectors for a site
8383
function getDefaultSelectorsForSite(site) {
84-
// This replicates the default selector structure from utils.js
85-
const defaultSelectors = {
86-
ChatGPT: {
87-
containers: ['div.flex.w-full.flex-col:has(textarea)'],
88-
sendButtons: [
89-
'button[data-testid="send-button"]',
90-
'button.send-button-class',
91-
'button[type="submit"]'
92-
],
93-
editors: ['div.ProseMirror#prompt-textarea', 'div.ProseMirror'],
94-
buttonsContainerId: 'chatgpt-custom-buttons-container'
95-
},
96-
Claude: {
97-
containers: [
98-
'div.flex.flex-col.bg-bg-000.rounded-2xl',
99-
'div.flex.flex-col.bg-bg-000.gap-1\\.5'
100-
],
101-
sendButtons: ['button[aria-label="Send Message"]'],
102-
editors: ['div.ProseMirror[contenteditable="true"]'],
103-
buttonsContainerId: 'claude-custom-buttons-container'
104-
},
105-
Copilot: {
106-
containers: ['div.shadow-composer-input'],
107-
sendButtons: [
108-
'button.rounded-submitButton[title="Submit message"]',
109-
'button[type="button"][title="Submit message"]'
110-
],
111-
editors: [
112-
'div.shadow-composer-input textarea#userInput',
113-
'textarea#userInput[placeholder="Message Copilot"]'
114-
],
115-
buttonsContainerId: 'copilot-custom-buttons-container'
116-
},
117-
DeepSeek: {
118-
containers: [
119-
'div.dd442025',
120-
'[class*="editorContainer"]'
121-
],
122-
sendButtons: [
123-
'div.bf38813a [role="button"]',
124-
'button:has(svg)',
125-
'[aria-label*="Send"]',
126-
'[data-testid="send-button"]'
127-
],
128-
editors: [
129-
'textarea#chat-input',
130-
'div.b13855df',
131-
'[contenteditable="true"]'
132-
],
133-
buttonsContainerId: 'deepseek-custom-buttons-container'
134-
},
135-
AIStudio: {
136-
containers: [
137-
'section.chunk-editor-main',
138-
'footer',
139-
'ms-chunk-editor-menu',
140-
'body > app-root > div > div > div.layout-wrapper > div > span > ms-prompt-switcher > ms-chunk-editor > section > footer'
141-
],
142-
sendButtons: [
143-
'button.run-button[type="submit"]',
144-
'button[aria-label="Run"]',
145-
'run-button button[type="submit"]',
146-
'footer > div.input-wrapper > div:nth-child(3) > run-button > button'
147-
],
148-
editors: [
149-
'ms-autosize-textarea textarea[aria-label="User text input"]',
150-
'textarea.textarea.gmat-body-medium[aria-label="Type something"]',
151-
'footer > div.input-wrapper > div.text-wrapper > ms-chunk-input > section > ms-text-chunk > ms-autosize-textarea'
152-
],
153-
buttonsContainerId: 'aistudio-custom-buttons-container'
154-
},
155-
Grok: {
156-
containers: [
157-
'form.bottom-0.w-full.text-base.flex.flex-col.gap-2.items-center.justify-center.relative.z-10'
158-
],
159-
sendButtons: [
160-
'form.bottom-0.w-full.text-base.flex.flex-col.gap-2.items-center.justify-center.relative.z-10 button[type="submit"].group'
161-
],
162-
editors: [
163-
'textarea.w-full.bg-transparent.focus\\:outline-none.text-primary',
164-
'textarea.w-full.px-2.\\@\\[480px\\]\\/input\\:px-3.pt-5.mb-5.bg-transparent.focus\\:outline-none.text-primary.align-bottom'
165-
],
166-
buttonsContainerId: 'grok-custom-buttons-container'
167-
},
168-
Gemini: {
169-
containers: [
170-
'input-container',
171-
'main'
172-
],
173-
sendButtons: [
174-
'button.send-button[aria-label="Send message"]',
175-
'button[aria-label="Send message"][aria-disabled="false"]'
176-
],
177-
editors: [
178-
'div.ql-editor[contenteditable="true"]',
179-
'rich-textarea div.ql-editor'
180-
],
181-
buttonsContainerId: 'gemini-custom-buttons-container'
182-
}
183-
};
184-
185-
return defaultSelectors[site] || {
186-
containers: [],
187-
sendButtons: [],
188-
editors: [],
189-
buttonsContainerId: site.toLowerCase() + '-custom-buttons-container'
190-
};
84+
// Use the getDefaultSelectors method from utils.js
85+
if (window.InjectionTargetsOnWebsite) {
86+
return window.InjectionTargetsOnWebsite.getDefaultSelectors(site);
87+
} else {
88+
// Fallback if InjectionTargetsOnWebsite is not available
89+
return {
90+
containers: [],
91+
sendButtons: [],
92+
editors: [],
93+
buttonsContainerId: site.toLowerCase() + '-custom-buttons-container'
94+
};
95+
}
19196
}
19297

19398
// Save the current selector configuration

popup.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ <h2>Theme</h2>
266266
<div id="toastContainer" class="toast-container"></div>
267267

268268
<script src="log.js"></script>
269+
<script src="utils.js"></script>
269270
<script src="/popup-page-scripts/popup-page-visuals.js"></script>
270271
<script src="/popup-page-scripts/popup-page-profiles.js"></script>
271272
<script src="/popup-page-scripts/popup-page-backup-handler.js"></script>

0 commit comments

Comments
 (0)