summaryrefslogtreecommitdiff
path: root/source/feature-manager.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'source/feature-manager.tsx')
-rw-r--r--source/feature-manager.tsx48
1 files changed, 20 insertions, 28 deletions
diff --git a/source/feature-manager.tsx b/source/feature-manager.tsx
index 17590b73..fecad60b 100644
--- a/source/feature-manager.tsx
+++ b/source/feature-manager.tsx
@@ -5,12 +5,12 @@ import stripIndent from 'strip-indent';
import {Promisable} from 'type-fest';
import * as pageDetect from 'github-url-detection';
-import waitFor from './helpers/wait-for';
-import onAbort from './helpers/abort-controller';
-import ArrayMap from './helpers/map-of-arrays';
-import bisectFeatures from './helpers/bisect';
-import {shouldFeatureRun} from './github-helpers';
-import optionsStorage, {RGHOptions} from './options-storage';
+import waitFor from './helpers/wait-for.js';
+import onAbort from './helpers/abort-controller.js';
+import ArrayMap from './helpers/map-of-arrays.js';
+import bisectFeatures from './helpers/bisect.js';
+import {shouldFeatureRun} from './github-helpers/index.js';
+import optionsStorage, {RGHOptions} from './options-storage.js';
import {
applyStyleHotfixes,
getStyleHotfix,
@@ -19,7 +19,7 @@ import {
updateHotfixes,
updateLocalStrings,
_,
-} from './helpers/hotfix';
+} from './helpers/hotfix.js';
type BooleanFunction = () => boolean;
export type CallerFunction = (callback: VoidFunction, signal: AbortSignal) => void | Promise<void> | Deinit;
@@ -59,7 +59,7 @@ const {version} = browser.runtime.getManifest();
const currentFeatureControllers = new ArrayMap<FeatureID, AbortController>();
-const logError = (url: string, error: unknown): void => {
+function logError(url: string, error: unknown): void {
const id = getFeatureID(url);
const message = error instanceof Error ? error.message : String(error);
@@ -87,7 +87,7 @@ const logError = (url: string, error: unknown): void => {
console.log('🔍 Search issue', searchIssueUrl.href);
console.log('🚨 Report issue', newIssueUrl.href);
console.groupEnd();
-};
+}
const log = {
info: console.log,
@@ -157,7 +157,7 @@ function castArray<Item>(value: Item | Item[]): Item[] {
return Array.isArray(value) ? value : [value];
}
-const setupPageLoad = async (id: FeatureID, config: InternalRunConfig): Promise<void> => {
+async function setupPageLoad(id: FeatureID, config: InternalRunConfig): Promise<void> {
const {asLongAs, include, exclude, init, additionalListeners, onlyAdditionalListeners} = config;
if (!shouldFeatureRun({asLongAs, include, exclude})) {
@@ -196,7 +196,7 @@ const setupPageLoad = async (id: FeatureID, config: InternalRunConfig): Promise<
onAbort(featureController, ...castArray(deinit));
}
}
-};
+}
const shortcutMap = new Map<string, string>();
@@ -213,17 +213,17 @@ type FeatureHelper = {
selector: string;
};
-const getIdentifiers = (url: string): FeatureHelper => {
+function getIdentifiers(url: string): FeatureHelper {
const id = getFeatureID(url);
return {
id,
class: 'rgh-' + id,
selector: '.rgh-' + id,
};
-};
+}
/** Register a new feature */
-const add = async (url: string, ...loaders: FeatureLoader[]): Promise<void> => {
+async function add(url: string, ...loaders: FeatureLoader[]): Promise<void> {
const id = getFeatureID(url);
/* Feature filtering and running */
const options = await globalReady;
@@ -238,15 +238,7 @@ const add = async (url: string, ...loaders: FeatureLoader[]): Promise<void> => {
for (const loader of loaders) {
// Input defaults and validation
const {
- shortcuts = {},
- asLongAs,
- include,
- exclude,
- init,
- awaitDomReady = false,
- deduplicate = false,
- onlyAdditionalListeners = false,
- additionalListeners = [],
+ shortcuts = {}, asLongAs, include, exclude, init, awaitDomReady = false, deduplicate = false, onlyAdditionalListeners = false, additionalListeners = [],
} = loader;
if (include?.length === 0) {
@@ -279,9 +271,9 @@ const add = async (url: string, ...loaders: FeatureLoader[]): Promise<void> => {
}
});
}
-};
+}
-const addCssFeature = async (url: string, include?: BooleanFunction[]): Promise<void> => {
+async function addCssFeature(url: string, include?: BooleanFunction[]): Promise<void> {
const id = getFeatureID(url);
void add(id, {
include,
@@ -289,14 +281,14 @@ const addCssFeature = async (url: string, include?: BooleanFunction[]): Promise<
document.documentElement.classList.add('rgh-' + id);
},
});
-};
+}
-const unload = (featureUrl: string): void => {
+function unload(featureUrl: string): void {
const id = getFeatureID(featureUrl);
for (const controller of currentFeatureControllers.get(id) ?? []) {
controller.abort();
}
-};
+}
document.addEventListener('turbo:render', () => {
for (const feature of currentFeatureControllers.values()) {