Adrià Vilanova Martínez | 8b591d9 | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @deprecated |
| 3 | */ |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 4 | export enum ScriptRunPhase { |
| 5 | /** |
| 6 | * Executed before any Javascript is executed. |
| 7 | */ |
| 8 | Start, |
| 9 | /** |
| 10 | * Executed after the document is ready. |
| 11 | */ |
| 12 | Main, |
| 13 | } |
| 14 | |
Adrià Vilanova Martínez | 8b591d9 | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 15 | /** |
| 16 | * @deprecated |
| 17 | */ |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 18 | export enum ScriptEnvironment { |
| 19 | ContentScript, |
| 20 | InjectedScript, |
| 21 | } |
| 22 | |
Adrià Vilanova Martínez | 8b591d9 | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 23 | /** |
| 24 | * @deprecated |
| 25 | */ |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 26 | export enum ScriptPage { |
| 27 | CommunityConsole, |
| 28 | } |
| 29 | |
Adrià Vilanova Martínez | 8b591d9 | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 30 | /** |
| 31 | * @deprecated |
| 32 | */ |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 33 | export const ScriptRunPhaseToRunTime: Record< |
| 34 | ScriptRunPhase, |
| 35 | chrome.userScripts.RunAt |
| 36 | > = { |
| 37 | [ScriptRunPhase.Start]: 'document_start', |
| 38 | [ScriptRunPhase.Main]: 'document_idle', |
| 39 | }; |
| 40 | |
Adrià Vilanova Martínez | 8b591d9 | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 41 | /** |
| 42 | * @deprecated |
| 43 | */ |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 44 | export const ScriptEnvironmentToExecutionWorld: Record< |
| 45 | ScriptEnvironment, |
| 46 | chrome.scripting.ExecutionWorld |
| 47 | > = { |
| 48 | [ScriptEnvironment.ContentScript]: 'ISOLATED', |
| 49 | [ScriptEnvironment.InjectedScript]: 'MAIN', |
| 50 | }; |
| 51 | |
| 52 | export type ConcreteScript = { new (): Script }; |
| 53 | |
| 54 | export default abstract class Script { |
| 55 | /** |
| 56 | * Priority with which the script is executed. Scripts with a lower value are |
| 57 | * executed first. |
| 58 | */ |
Adrià Vilanova Martínez | e7f9be8 | 2024-05-31 22:37:04 +0200 | [diff] [blame] | 59 | readonly priority: number = 2 ** 31; |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Page where the script should be executed. |
Adrià Vilanova Martínez | 8b591d9 | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 63 | * @deprecated |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 64 | */ |
| 65 | abstract readonly page: ScriptPage; |
| 66 | |
| 67 | /** |
| 68 | * Environment where the script should be executed. |
Adrià Vilanova Martínez | 8b591d9 | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 69 | * @deprecated |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 70 | */ |
| 71 | abstract readonly environment: ScriptEnvironment; |
| 72 | |
| 73 | /** |
| 74 | * If {@link environment} is {@link ScriptEnvironment.ContentScript}, phase of |
| 75 | * the page loading when the script should be executed. |
Adrià Vilanova Martínez | 8b591d9 | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 76 | * @deprecated |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 77 | */ |
| 78 | abstract readonly runPhase?: ScriptRunPhase; |
| 79 | |
| 80 | /** |
| 81 | * Method which contains the logic of the script. |
| 82 | */ |
| 83 | abstract execute(): void; |
| 84 | } |