MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / installScriptByCode

Function installScriptByCode

e2e/utils.ts:158–175  ·  view source on GitHub ↗
(context: BrowserContext, extensionId: string, code: string)

Source from the content-addressed store, hash-verified

156
157/** Install a script by injecting code into the Monaco editor and saving */
158export async function installScriptByCode(context: BrowserContext, extensionId: string, code: string): Promise<void> {
159 const page = await openEditorPage(context, extensionId);
160 // Wait for Monaco editor DOM and default template content to be ready
161 await focusMonacoEditor(page);
162 // Select all existing content
163 await page.keyboard.press("ControlOrMeta+a");
164 // Capture current content fingerprint, then paste replacement
165 const initialText = await page.locator(".view-lines").textContent();
166 await page.evaluate((text) => navigator.clipboard.writeText(text), code);
167 await page.keyboard.press("ControlOrMeta+v");
168 // Wait for Monaco to finish rendering the pasted content (content will differ from template)
169 await page.waitForFunction((init) => document.querySelector(".view-lines")?.textContent !== init, initialText, {
170 timeout: 5_000,
171 });
172 // Save
173 await saveCurrentEditor(context, extensionId, page);
174 await page.close();
175}
176
177/** A sample userscript for testing */
178export const sampleUserScript = `// ==UserScript==

Callers 7

runTestScriptFunction · 0.90
backup-zip.spec.tsFile · 0.90
runInlineTestScriptFunction · 0.85

Calls 4

openEditorPageFunction · 0.85
focusMonacoEditorFunction · 0.85
saveCurrentEditorFunction · 0.85
closeMethod · 0.65

Tested by 1

runTestScriptFunction · 0.72