refactor: convert contentScriptsUtils to Typescript
Change-Id: I78031a291a34198ac6335a4ee42eb23753f2c37b
diff --git a/src/common/contentScriptsUtils.js b/src/common/contentScriptsUtils.js
deleted file mode 100644
index 51257c0..0000000
--- a/src/common/contentScriptsUtils.js
+++ /dev/null
@@ -1,21 +0,0 @@
-export function injectStylesheet(stylesheetName, attributes = {}) {
- var link = document.createElement('link');
- link.setAttribute('rel', 'stylesheet');
- link.setAttribute('href', stylesheetName);
- if ('media' in attributes) link.setAttribute('media', attributes['media']);
- document.head.appendChild(link);
-}
-
-export function injectStyles(css) {
- injectStylesheet('data:text/css;charset=UTF-8,' + encodeURIComponent(css));
-}
-
-export function injectScript(scriptName, prepend = false) {
- var script = document.createElement('script');
- script.src = scriptName;
- const root = (document.head || document.documentElement);
- if (prepend)
- root.prepend(script);
- else
- root.append(script);
-}
diff --git a/src/common/contentScriptsUtils.ts b/src/common/contentScriptsUtils.ts
new file mode 100644
index 0000000..588e4af
--- /dev/null
+++ b/src/common/contentScriptsUtils.ts
@@ -0,0 +1,32 @@
+export interface StylesheetAttributes {
+ media?: string;
+}
+
+export function injectStylesheet(
+ stylesheetName: string,
+ attributes: StylesheetAttributes = {},
+) {
+ var link = document.createElement('link');
+ link.setAttribute('rel', 'stylesheet');
+ link.setAttribute('href', stylesheetName);
+ if ('media' in attributes) {
+ link.setAttribute('media', attributes['media']);
+ }
+ document.head.appendChild(link);
+ return link;
+}
+
+export function injectStyles(css: string) {
+ injectStylesheet('data:text/css;charset=UTF-8,' + encodeURIComponent(css));
+}
+
+export function injectScript(scriptName: string, prepend = false) {
+ var script = document.createElement('script');
+ script.src = scriptName;
+ const root = document.head || document.documentElement;
+ if (prepend) {
+ root.prepend(script);
+ } else {
+ root.append(script);
+ }
+}
diff --git a/src/contentScripts/communityConsole/main.js b/src/contentScripts/communityConsole/main.js
index 32576e4..22e35f7 100644
--- a/src/contentScripts/communityConsole/main.js
+++ b/src/contentScripts/communityConsole/main.js
@@ -1,4 +1,4 @@
-import {injectScript, injectStyles, injectStylesheet} from '../../common/contentScriptsUtils.js';
+import {injectScript, injectStyles, injectStylesheet} from '../../common/contentScriptsUtils';
import {getOptions} from '../../common/options/optionsUtils.js';
import XHRProxyKillSwitchHandler from '../../xhrInterceptor/killSwitchHandler.js';
import {injectPreviousPostsLinksUnifiedProfileIfEnabled} from '../utilsCommon/unifiedProfiles.js';
diff --git a/src/contentScripts/communityConsole/start.js b/src/contentScripts/communityConsole/start.js
index cace3aa..2f8ba2a 100644
--- a/src/contentScripts/communityConsole/start.js
+++ b/src/contentScripts/communityConsole/start.js
@@ -1,4 +1,4 @@
-import {injectStylesheet} from '../../common/contentScriptsUtils.js';
+import {injectStylesheet} from '../../common/contentScriptsUtils';
import {getOptions} from '../../common/options/optionsUtils.js';
import FlattenThreadsReplyActionHandler from './flattenThreads/replyActionHandler.js';
diff --git a/src/contentScripts/communityConsole/updateHandler/index.js b/src/contentScripts/communityConsole/updateHandler/index.js
index b976b24..48d0ce1 100644
--- a/src/contentScripts/communityConsole/updateHandler/index.js
+++ b/src/contentScripts/communityConsole/updateHandler/index.js
@@ -1,4 +1,4 @@
-import {injectScript} from '../../../common/contentScriptsUtils.js';
+import {injectScript} from '../../../common/contentScriptsUtils';
import MWI18nServer from '../../../common/mainWorldI18n/Server.js';
import UpdateBanner from './banner/index.js';
diff --git a/src/contentScripts/profileIndicator.js b/src/contentScripts/profileIndicator.js
index 74fc2e7..ef789f8 100644
--- a/src/contentScripts/profileIndicator.js
+++ b/src/contentScripts/profileIndicator.js
@@ -1,4 +1,4 @@
-import {injectScript, injectStylesheet} from '../common/contentScriptsUtils.js';
+import {injectScript, injectStylesheet} from '../common/contentScriptsUtils';
import {setUpListener} from '../common/csEventListener.js';
setUpListener();
diff --git a/src/contentScripts/publicProfileStart.js b/src/contentScripts/publicProfileStart.js
index fbe6540..cc7277c 100644
--- a/src/contentScripts/publicProfileStart.js
+++ b/src/contentScripts/publicProfileStart.js
@@ -1,4 +1,4 @@
-import {injectScript} from '../common/contentScriptsUtils.js';
+import {injectScript} from '../common/contentScriptsUtils';
import {getOptions} from '../common/options/optionsUtils.js';
getOptions('perforumstats').then(options => {
diff --git a/src/contentScripts/publicThread.js b/src/contentScripts/publicThread.js
index bc12236..b5864cd 100644
--- a/src/contentScripts/publicThread.js
+++ b/src/contentScripts/publicThread.js
@@ -1,4 +1,4 @@
-import {injectStylesheet} from '../common/contentScriptsUtils.js';
+import {injectStylesheet} from '../common/contentScriptsUtils';
import {getOptions} from '../common/options/optionsUtils.js';
import {redirectIfApplicable} from '../redirect/index.js';
diff --git a/src/contentScripts/publicThreadStart.js b/src/contentScripts/publicThreadStart.js
index a95485b..40cd302 100644
--- a/src/contentScripts/publicThreadStart.js
+++ b/src/contentScripts/publicThreadStart.js
@@ -1,4 +1,4 @@
-import {injectStylesheet} from '../common/contentScriptsUtils.js';
+import {injectStylesheet} from '../common/contentScriptsUtils';
import {getOptions} from '../common/options/optionsUtils.js';
import {setUpRedirectIfEnabled} from '../redirect/setup.js';
diff --git a/src/features/workflows/core/communityConsole/import.js b/src/features/workflows/core/communityConsole/import.js
index 92abaee..5fde499 100644
--- a/src/features/workflows/core/communityConsole/import.js
+++ b/src/features/workflows/core/communityConsole/import.js
@@ -1,7 +1,7 @@
import {waitFor} from 'poll-until-promise';
import {recursiveParentElement} from '../../../../common/commonUtils.js';
-import {injectStylesheet} from '../../../../common/contentScriptsUtils.js';
+import {injectStylesheet} from '../../../../common/contentScriptsUtils';
import {isOptionEnabled} from '../../../../common/options/optionsUtils.js';
const kListCannedResponsesResponse = 'TWPT_ListCannedResponsesResponse';
diff --git a/src/injections/litComponentsInject.js b/src/injections/litComponentsInject.js
index b1c40cf..ce8ace8 100644
--- a/src/injections/litComponentsInject.js
+++ b/src/injections/litComponentsInject.js
@@ -7,7 +7,7 @@
import '../contentScripts/communityConsole/flattenThreads/components/index.js';
import '../contentScripts/communityConsole/updateHandler/banner/components/index.js';
-import {injectStylesheet} from '../common/contentScriptsUtils.js';
+import {injectStylesheet} from '../common/contentScriptsUtils';
// Also, we import Material Symbols Outlined since the Community Console uses
// "Google Material Icons" instead. This is necessary for the MD3 components.
diff --git a/src/injections/updateHandlerLitComponents.js b/src/injections/updateHandlerLitComponents.js
index e6449f5..8faef99 100644
--- a/src/injections/updateHandlerLitComponents.js
+++ b/src/injections/updateHandlerLitComponents.js
@@ -1,6 +1,6 @@
import '../contentScripts/communityConsole/updateHandler/banner/components/index.js';
-import {injectStylesheet} from '../common/contentScriptsUtils.js';
+import {injectStylesheet} from '../common/contentScriptsUtils';
// This is necessary for the MD3 components. It is also done in
// litComponentsInject.js, but when installing the extension