blob: 0e33e7e85085764d6e96343d4e3e4884741c35c6 [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 /**
56 * Priority with which the script is executed. Scripts with a lower value are
57 * executed first.
58 */
Adrià Vilanova Martíneze7f9be82024-05-31 22:37:04 +020059 readonly priority: number = 2 ** 31;
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020060
61 /**
62 * Page where the script should be executed.
Adrià Vilanova Martínez8b591d92024-10-19 15:55:15 +020063 * @deprecated
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020064 */
65 abstract readonly page: ScriptPage;
66
67 /**
68 * Environment 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 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ínez8b591d92024-10-19 15:55:15 +020076 * @deprecated
Adrià Vilanova Martínez18d03c42024-04-21 16:43:01 +020077 */
78 abstract readonly runPhase?: ScriptRunPhase;
79
80 /**
81 * Method which contains the logic of the script.
82 */
83 abstract execute(): void;
84}