| 182 | } |
| 183 | |
| 184 | function patchTargetMatchCode(code: string, targetUrl: string): string { |
| 185 | const url = new URL(targetUrl); |
| 186 | const targetPattern = `${url.protocol}//${url.hostname}/*${url.search}`; |
| 187 | return code.replace( |
| 188 | /^\/\/\s*@match\s+.*\?(gm_api_sync|gm_api_async|inject_content|WINDOW_MESSAGE_TEST_SC|SANDBOX_TEST_SC|unwrap_e2e_test)$/gm, |
| 189 | `// @match ${targetPattern}` |
| 190 | ); |
| 191 | } |
| 192 | |
| 193 | function patchGMApiTestCode(code: string, mockOrigin: string): string { |
| 194 | const mockHost = new URL(mockOrigin).host; |