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 | /** |
Adrià Vilanova Martínez | ce9df17 | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 56 | * Used to indicate that this script should run after the members of the |
| 57 | * provided array. |
| 58 | */ |
| 59 | readonly runAfter: ConcreteScript[] = []; |
| 60 | |
| 61 | /** |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 62 | * Priority with which the script is executed. Scripts with a lower value are |
| 63 | * executed first. |
| 64 | */ |
Adrià Vilanova Martínez | e7f9be8 | 2024-05-31 22:37:04 +0200 | [diff] [blame] | 65 | readonly priority: number = 2 ** 31; |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Page 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 page: ScriptPage; |
| 72 | |
| 73 | /** |
| 74 | * Environment where the script should be executed. |
Adrià Vilanova Martínez | 8b591d9 | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 75 | * @deprecated |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 76 | */ |
| 77 | abstract readonly environment: ScriptEnvironment; |
| 78 | |
| 79 | /** |
| 80 | * If {@link environment} is {@link ScriptEnvironment.ContentScript}, phase of |
| 81 | * the page loading when the script should be executed. |
Adrià Vilanova Martínez | 8b591d9 | 2024-10-19 15:55:15 +0200 | [diff] [blame] | 82 | * @deprecated |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 83 | */ |
| 84 | abstract readonly runPhase?: ScriptRunPhase; |
| 85 | |
| 86 | /** |
| 87 | * Method which contains the logic of the script. |
| 88 | */ |
| 89 | abstract execute(): void; |
| 90 | } |