refactor: migrate temp "CC slowness fix" feature to the new architecture
Bug: twpowertools:176
Change-Id: I09819e4a5a0429631d76f1f7063a1e35b5b1ac05
diff --git a/src/contentScripts/communityConsole/start.js b/src/contentScripts/communityConsole/start.js
index b9c7f58..f890bd0 100644
--- a/src/contentScripts/communityConsole/start.js
+++ b/src/contentScripts/communityConsole/start.js
@@ -4,21 +4,6 @@
import FlattenThreadsReplyActionHandler from './flattenThreads/replyActionHandler.js';
getOptions(null).then(options => {
- /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
- if (options.fixpekb269560789) {
- var startup =
- JSON.parse(document.querySelector('html').getAttribute('data-startup'));
-
- if (options.fixpekb269560789) {
- if (startup[1]?.[1]?.[8]?.[7]) {
- delete startup[1]?.[1]?.[8]?.[7];
- }
- }
-
- document.querySelector('html').setAttribute(
- 'data-startup', JSON.stringify(startup));
- }
-
if (options.uispacing) {
injectStylesheet(chrome.runtime.getURL('css/ui_spacing/shared.css'));
injectStylesheet(chrome.runtime.getURL('css/ui_spacing/console.css'));
diff --git a/src/features/Features.ts b/src/features/Features.ts
index 67c93aa..bf4d83c 100644
--- a/src/features/Features.ts
+++ b/src/features/Features.ts
@@ -5,6 +5,7 @@
import ExtraInfoFeature from './extraInfo/extraInfo.feature';
import WorkflowsFeature from './workflows/workflows.feature';
import CCDarkThemeFeature from './ccDarkTheme/ccDarkTheme.feature';
+import FixCCSlownessFeature from './fixCCSlowness/fixCCSlowness.feature';
export type ConcreteFeatureClass = { new (): Feature };
@@ -13,6 +14,7 @@
AutoRefreshFeature,
CCDarkThemeFeature,
ExtraInfoFeature,
+ FixCCSlownessFeature,
InfiniteScrollFeature,
WorkflowsFeature,
];
diff --git a/src/features/fixCCSlowness/fixCCSlowness.feature.ts b/src/features/fixCCSlowness/fixCCSlowness.feature.ts
new file mode 100644
index 0000000..5703311
--- /dev/null
+++ b/src/features/fixCCSlowness/fixCCSlowness.feature.ts
@@ -0,0 +1,14 @@
+import Feature from '../../common/architecture/features/Feature';
+import { ConcreteScript } from '../../common/architecture/scripts/Script';
+import { OptionCodename } from '../../common/options/optionsPrototype';
+import RemoveUserAbuseEventsFromDataStartupScript from './scripts/removeUserAbuseEventsFromDataStartup.script';
+
+// This feature also has an associated response modifier.
+export default class FixCCSlownessFeature extends Feature {
+ public readonly scripts: ConcreteScript[] = [
+ RemoveUserAbuseEventsFromDataStartupScript,
+ ];
+
+ readonly codename = 'fixCCSlowness';
+ readonly relatedOptions: OptionCodename[] = ['fixpekb269560789'];
+}
diff --git a/src/features/fixCCSlowness/scripts/removeUserAbuseEventsFromDataStartup.script.ts b/src/features/fixCCSlowness/scripts/removeUserAbuseEventsFromDataStartup.script.ts
new file mode 100644
index 0000000..7618b78
--- /dev/null
+++ b/src/features/fixCCSlowness/scripts/removeUserAbuseEventsFromDataStartup.script.ts
@@ -0,0 +1,32 @@
+import DependenciesProviderSingleton, {
+ OptionsProviderDependency,
+ StartupDataStorageDependency,
+} from '../../../common/architecture/dependenciesProvider/DependenciesProvider';
+import Script, {
+ ScriptEnvironment,
+ ScriptPage,
+ ScriptRunPhase,
+} from '../../../common/architecture/scripts/Script';
+
+export default class RemoveUserAbuseEventsFromDataStartupScript extends Script {
+ page = ScriptPage.CommunityConsole;
+ environment = ScriptEnvironment.ContentScript;
+ runPhase = ScriptRunPhase.Start;
+
+ async execute() {
+ const dependenciesProvider = DependenciesProviderSingleton.getInstance();
+ const optionsProvider = dependenciesProvider.getDependency(
+ OptionsProviderDependency,
+ );
+ if (optionsProvider.isEnabled('fixpekb269560789')) {
+ const startupDataStorage = dependenciesProvider.getDependency(
+ StartupDataStorageDependency,
+ );
+ startupDataStorage.enqueueModification((startupDataModel) => {
+ if (startupDataModel.data[1]?.[1]?.[8]?.[7]) {
+ delete startupDataModel.data[1]?.[1]?.[8]?.[7];
+ }
+ });
+ }
+ }
+}