refactor: move classes instantiated at CC start to scripts
Bug: twpowertools:176
Change-Id: I5ac38aa432ee85bd276ee1c867492100d82c1438
diff --git a/src/scripts/Scripts.ts b/src/scripts/Scripts.ts
new file mode 100644
index 0000000..dca90d6
--- /dev/null
+++ b/src/scripts/Scripts.ts
@@ -0,0 +1,21 @@
+import Script, { ConcreteScript } from '../common/architecture/scripts/Script';
+import ScriptFilterListProvider from '../common/architecture/scripts/ScriptFilterListProvider';
+import MWI18nServerScript from './mainWorldServers/MWI18nServerScript.script';
+import MWOptionsWatcherServerScript from './mainWorldServers/MWOptionsWatcherServerScript.script';
+import XHRInterceptorScript from './xhrInterceptor/xhrInterceptor.script';
+
+export default class StandaloneScripts extends ScriptFilterListProvider {
+ private scripts: ConcreteScript[] = [
+ MWI18nServerScript,
+ MWOptionsWatcherServerScript,
+ XHRInterceptorScript,
+ ];
+ private initializedScripts: Script[];
+
+ protected getUnfilteredScriptsList() {
+ if (this.initializedScripts === undefined) {
+ this.initializedScripts = this.scripts.map((script) => new script());
+ }
+ return this.initializedScripts;
+ }
+}
diff --git a/src/scripts/mainWorldServers/MWI18nServerScript.script.ts b/src/scripts/mainWorldServers/MWI18nServerScript.script.ts
new file mode 100644
index 0000000..dbd87fe
--- /dev/null
+++ b/src/scripts/mainWorldServers/MWI18nServerScript.script.ts
@@ -0,0 +1,17 @@
+import Script, { ScriptEnvironment, ScriptPage, ScriptRunPhase } from "../../common/architecture/scripts/Script"
+import MWI18nServer from "../../common/mainWorldI18n/Server";
+
+export default class MWI18nServerScript extends Script {
+ // The server should be available as soon as possible, since e.g. the
+ // XHRProxy already sends a request to the optionsWatcher server as soon as it
+ // is constructed.
+ priority = 1;
+
+ page = ScriptPage.CommunityConsole;
+ environment = ScriptEnvironment.ContentScript;
+ runPhase = ScriptRunPhase.Start;
+
+ execute() {
+ new MWI18nServer();
+ }
+}
diff --git a/src/scripts/mainWorldServers/MWOptionsWatcherServerScript.script.ts b/src/scripts/mainWorldServers/MWOptionsWatcherServerScript.script.ts
new file mode 100644
index 0000000..a7aa405
--- /dev/null
+++ b/src/scripts/mainWorldServers/MWOptionsWatcherServerScript.script.ts
@@ -0,0 +1,18 @@
+import Script, { ScriptEnvironment, ScriptPage, ScriptRunPhase } from "../../common/architecture/scripts/Script"
+import MWOptionsWatcherServer from "../../common/mainWorldOptionsWatcher/Server"
+import { kCSTarget, kMWTarget } from "../../xhrInterceptor/responseModifiers"
+
+export default class MWOptionsWatcherServerScript extends Script {
+ // The server should be available as soon as possible, since e.g. the
+ // XHRProxy already sends a request to the optionsWatcher server as soon as it
+ // is constructed.
+ priority = 0;
+
+ page = ScriptPage.CommunityConsole;
+ environment = ScriptEnvironment.ContentScript;
+ runPhase = ScriptRunPhase.Start;
+
+ execute() {
+ new MWOptionsWatcherServer(kCSTarget, kMWTarget);
+ }
+}
diff --git a/src/scripts/xhrInterceptor/xhrInterceptor.script.ts b/src/scripts/xhrInterceptor/xhrInterceptor.script.ts
new file mode 100644
index 0000000..551c85f
--- /dev/null
+++ b/src/scripts/xhrInterceptor/xhrInterceptor.script.ts
@@ -0,0 +1,21 @@
+import Script, {
+ ScriptEnvironment,
+ ScriptPage,
+ ScriptRunPhase,
+} from '../../common/architecture/scripts/Script';
+import { injectScript } from '../../common/contentScriptsUtils';
+
+export default class XHRInterceptorScript extends Script {
+ priority = 10;
+
+ page = ScriptPage.CommunityConsole;
+ environment = ScriptEnvironment.ContentScript;
+ runPhase = ScriptRunPhase.Start;
+
+ execute() {
+ injectScript(
+ chrome.runtime.getURL('xhrInterceptorInject.bundle.js'),
+ /* prepend = */ true,
+ );
+ }
+}