blob: 8a8e9de23bf5db545c07f39ca093646cd9185130 [file] [log] [blame]
Adrià Vilanova Martínez8b591d92024-10-19 15:55:15 +02001/**
2 * @deprecated
3 */
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +02004export 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ínez8b591d92024-10-19 15:55:15 +020015/**
16 * @deprecated
17 */
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020018export enum ScriptEnvironment {
19 ContentScript,
20 InjectedScript,
21}
22
Adrià Vilanova Martínez8b591d92024-10-19 15:55:15 +020023/**
24 * @deprecated
25 */
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020026export enum ScriptPage {
27 CommunityConsole,
28}
29
Adrià Vilanova Martínez8b591d92024-10-19 15:55:15 +020030/**
31 * @deprecated
32 */
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020033export 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ínez8b591d92024-10-19 15:55:15 +020041/**
42 * @deprecated
43 */
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020044export const ScriptEnvironmentToExecutionWorld: Record<
45 ScriptEnvironment,
46 chrome.scripting.ExecutionWorld
47> = {
48 [ScriptEnvironment.ContentScript]: 'ISOLATED',
49 [ScriptEnvironment.InjectedScript]: 'MAIN',
50};
51
52export type ConcreteScript = { new (): Script };
53
54export default abstract class Script {
55 /**
Adrià Vilanova Martínezce9df172024-10-19 15:55:15 +020056 * 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ínez18d03c42024-04-21 16:43:01 +020062 * Priority with which the script is executed. Scripts with a lower value are
63 * executed first.
64 */
Adrià Vilanova Martíneze7f9be82024-05-31 22:37:04 +020065 readonly priority: number = 2 ** 31;
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020066
67 /**
68 * Page where the script should be executed.
Adrià Vilanova Martínez8b591d92024-10-19 15:55:15 +020069 * @deprecated
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020070 */
71 abstract readonly page: ScriptPage;
72
73 /**
74 * Environment where the script should be executed.
Adrià Vilanova Martínez8b591d92024-10-19 15:55:15 +020075 * @deprecated
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020076 */
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ínez8b591d92024-10-19 15:55:15 +020082 * @deprecated
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020083 */
84 abstract readonly runPhase?: ScriptRunPhase;
85
86 /**
87 * Method which contains the logic of the script.
88 */
89 abstract execute(): void;
90}