|
1 | | -# Use the Editor |
| 1 | +# Using the Editor |
2 | 2 |
|
3 | | -CodeTweak has two editing modes: |
| 3 | +This guide covers the features and workflow of the CodeTweak script editor. |
4 | 4 |
|
5 | | -- Standard script editor |
6 | | -- AI DOM Editor sidebar |
| 5 | +## Opening the Editor |
7 | 6 |
|
8 | | -## Standard editor workflow |
| 7 | +You can access the editor in two ways: |
| 8 | +1. **Create a New Script**: Click the **CodeTweak icon** in your browser toolbar and select **Create Script**. |
| 9 | +2. **Edit an Existing Script**: Go to the **Dashboard** and click on any script in the list. |
9 | 10 |
|
10 | | -1. Set metadata. |
11 | | -2. Write script code. |
12 | | -3. Save. |
13 | | -4. Test on a matching URL. |
| 11 | +## The Editor Interface |
14 | 12 |
|
15 | | -Minimal metadata template: |
| 13 | +The editor is split into several key areas: |
16 | 14 |
|
17 | | -```javascript |
18 | | -// ==UserScript== |
19 | | -// @name My Script |
20 | | -// @match https://app.example.com/* |
21 | | -// @run-at document-end |
22 | | -// @grant GM_getValue |
23 | | -// @grant GM_setValue |
24 | | -// ==/UserScript== |
25 | | -``` |
| 15 | +### 1. Code Editor (Center) |
| 16 | +The main window where you write your JavaScript and metadata block. It features syntax highlighting, auto-completion, and basic linting. |
26 | 17 |
|
27 | | -State example: |
| 18 | +### 2. Header & Toolbar (Top) |
| 19 | +- **Save**: Saves your script and immediately applies it to matched pages. |
| 20 | +- **Settings**: Opens the editor's display and behavior settings. |
| 21 | +- **Close**: Closes the editor and returns to the previous view. |
28 | 22 |
|
29 | | -```javascript |
30 | | -(async () => { |
31 | | - const count = await GM_getValue("count", 0); |
32 | | - await GM_setValue("count", count + 1); |
33 | | - console.log("runs:", count + 1); |
34 | | -})(); |
35 | | -``` |
| 23 | +### 3. Sidebar Panels (Right) |
| 24 | +These panels allow you to configure your script without manually editing the metadata block: |
| 25 | +- **Script Info**: Change the script's name, version, and description. |
| 26 | +- **Execution Settings**: Manage `@match` patterns and `@run-at` timing. |
| 27 | +- **GM API Access**: Toggle permissions for specific `GM_*` APIs. |
| 28 | +- **External Resources**: Add `@require` and `@resource` links. |
| 29 | +- **Script Errors**: View compilation and runtime errors for the current script. |
36 | 30 |
|
37 | | -## AI DOM Editor workflow |
| 31 | +## The AI DOM Editor |
38 | 32 |
|
39 | | -1. Open popup. |
40 | | -2. Click `AI DOM Editor`. |
41 | | -3. Click `Select Element` in sidebar. |
42 | | -4. Click target element on page. |
43 | | -5. Enter instruction. |
| 33 | +The AI DOM Editor is a powerful tool for generating userscript code by simply describing what you want to change on a webpage. |
44 | 34 |
|
45 | | -Example instructions: |
| 35 | +1. **Open AI Sidebar**: Click **AI DOM Editor** in the popup or from the editor's sidebar. |
| 36 | +2. **Select an Element**: Click the **Select Element** button and hover over the element on the page you want to modify. |
| 37 | +3. **Describe the Change**: In the text box, describe what you want the AI to do (e.g., "Hide this element" or "Change the background color to blue"). |
| 38 | +4. **Review and Apply**: The AI will generate code for you. You can review it and click **Apply to Script** to add it to your current userscript. |
46 | 39 |
|
47 | | -- `Hide this element` |
48 | | -- `Change this button text to "Checkout"` |
49 | | -- `Add red border to this card` |
| 40 | +## Debugging and Testing |
50 | 41 |
|
51 | | -Review generated code before saving. |
52 | | - |
53 | | -## Common mistakes |
54 | | - |
55 | | -- `@match` too broad (`*://*/*`) or too narrow. |
56 | | -- Wrong `@run-at` for the DOM state you expect. |
57 | | -- Missing `@grant` for GM APIs. |
| 42 | +- **Live Updates**: When you save a script, it is instantly updated. Refresh the target website to see your changes. |
| 43 | +- **Console Logs**: Use `console.log()` in your script and open the browser's DevTools (F12) to see output. |
| 44 | +- **Error Highlighting**: If your script has syntax errors, they will be highlighted in the **Script Errors** panel. |
0 commit comments