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
// Primary method to call AI APIs. Returns { type: 'script', code: '...' }
230
-
asynccallAIAPI(userMessage,domSummary){
231
-
232
-
constsystemPrompt=`You are an expert JavaScript developer specializing in DOM manipulation and userscripts. Your task is to generate clean, efficient JavaScript code that modifies a webpage based on the user's request.
233
-
234
-
**CRITICAL CONTEXT - YOU MUST ANALYZE THIS:**
235
-
236
-
**Current Page Structure (DOM Summary):**
237
-
${domSummary}
238
-
239
-
**INSTRUCTIONS:**
240
-
241
-
1. **DEEPLY ANALYZE THE DOM:** Study the DOM structure carefully. Look for:
242
-
- Element tags, IDs, and class names you can target
243
-
- The hierarchy and nesting of elements
244
-
- Text content that helps identify elements
245
-
- Attributes that can be used for precise selection
246
-
247
-
2. **USE SPECIFIC SELECTORS:** Based on your analysis:
248
-
- Prefer IDs when available (e.g., \`document.getElementById('specific-id')\`)
249
-
- Use class names with querySelector (e.g., \`document.querySelector('.specific-class')\`)
250
-
- Use tag names with additional context (e.g., \`document.querySelector('div > h1')\`)
251
-
- Combine selectors for precision (e.g., \`document.querySelector('div.container > h1.title')\`)
252
-
253
-
3. **GREASEMONKEY APIs AVAILABLE:**
254
-
You have access to these powerful APIs - USE THEM when they make the code better:
255
-
256
-
**STYLING (HIGHLY RECOMMENDED for CSS changes):**
257
-
- \`GM_addStyle(css)\` - Inject CSS (ALWAYS prefer this over inline styles for multiple elements)
258
-
259
-
**STORAGE (for persistent data):**
260
-
- \`GM_setValue(key, value)\` - Store data across page loads
261
-
- \`GM_getValue(key, defaultValue)\` - Retrieve stored data
262
-
- \`GM_deleteValue(key)\` - Delete stored data
263
-
- \`GM_listValues()\` - List all stored keys
264
-
265
-
**NETWORK (for API calls and cross-origin requests):**
266
-
- \`GM_xmlhttpRequest(details)\` - Make cross-origin HTTP requests
267
-
268
-
**UI ENHANCEMENTS:**
269
-
- \`GM_notification(options)\` - Show desktop notifications
270
-
- \`GM_addElement(parent, tag, attributes)\` - Create and insert DOM elements
271
-
- \`GM_registerMenuCommand(caption, callback)\` - Add custom menu commands
272
-
- \`GM_openInTab(url, options)\` - Open URLs in new tabs
273
-
274
-
**UTILITIES:**
275
-
- \`GM_setClipboard(data, type)\` - Copy data to clipboard
276
-
- \`GM_download(url, name)\` - Download files
277
-
- \`GM_getResourceText(name)\` - Get text resources
278
-
- \`unsafeWindow\` - Direct access to page's window object (use cautiously)
279
-
280
-
4. **CODE QUALITY REQUIREMENTS:**
281
-
- Write immediately executable code - no placeholders, no TODO comments
282
-
- Always check element existence before manipulation (e.g., \`if (element) { ... }\`)
283
-
- Use efficient selectors based on the actual DOM structure provided
284
-
- Handle edge cases gracefully with try-catch where appropriate
285
-
- Prefer GM_addStyle for ANY CSS changes affecting multiple elements
286
-
- Use modern JavaScript (ES6+) with arrow functions, const/let, template literals
0 commit comments