diff options
Diffstat (limited to 'source/features/index.tsx')
-rw-r--r-- | source/features/index.tsx | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/source/features/index.tsx b/source/features/index.tsx index 32ab7e3c..e017197c 100644 --- a/source/features/index.tsx +++ b/source/features/index.tsx @@ -8,6 +8,7 @@ import * as pageDetect from 'github-url-detection'; import waitFor from '../helpers/wait-for'; import onNewComments from '../github-events/on-new-comments'; import bisectFeatures from '../helpers/bisect'; +import {shouldFeatureRun} from '../github-helpers'; import optionsStorage, {RGHOptions} from '../options-storage'; import {getLocalHotfixesAsOptions, updateHotfixes} from '../helpers/hotfix'; @@ -34,8 +35,9 @@ interface FeatureLoader extends Partial<InternalRunConfig> { } interface InternalRunConfig { - include: BooleanFunction[]; - exclude: BooleanFunction[]; + asLongAs: BooleanFunction[] | undefined; + include: BooleanFunction[] | undefined; + exclude: BooleanFunction[] | undefined; init: FeatureInit; deinit?: VoidFunction | VoidFunction[]; additionalListeners: CallerFunction[]; @@ -138,10 +140,9 @@ const globalReady: Promise<RGHOptions> = new Promise(async resolve => { }); const setupPageLoad = async (id: FeatureID, config: InternalRunConfig): Promise<void> => { - const {include, exclude, init, deinit, additionalListeners, onlyAdditionalListeners} = config; + const {asLongAs, include, exclude, init, deinit, additionalListeners, onlyAdditionalListeners} = config; - // If every `include` is false and no `exclude` is true, don’t run the feature - if (include.every(c => !c()) || exclude.some(c => c())) { + if (!shouldFeatureRun({asLongAs, include, exclude})) { return; } @@ -192,7 +193,7 @@ function enforceDefaults( additionalListeners: InternalRunConfig['additionalListeners'], ): void { for (const [detection, listener] of defaultPairs) { - if (!include.includes(detection)) { + if (!include?.includes(detection)) { continue; } @@ -218,8 +219,9 @@ const add = async (id: FeatureID, ...loaders: FeatureLoader[]): Promise<void> => // Input defaults and validation const { shortcuts = {}, - include = [() => true], // Default: every page - exclude = [], // Default: nothing + asLongAs, + include, + exclude, init, deinit, awaitDomReady = true, @@ -234,13 +236,13 @@ const add = async (id: FeatureID, ...loaders: FeatureLoader[]): Promise<void> => } // 404 pages should only run 404-only features - if (pageDetect.is404() && !include.includes(pageDetect.is404)) { + if (pageDetect.is404() && !include?.includes(pageDetect.is404) && !asLongAs?.includes(pageDetect.is404)) { continue; } enforceDefaults(id, include, additionalListeners); - const details = {include, exclude, init, deinit, additionalListeners, onlyAdditionalListeners}; + const details = {asLongAs, include, exclude, init, deinit, additionalListeners, onlyAdditionalListeners}; if (awaitDomReady) { (async () => { await domLoaded; @@ -258,7 +260,7 @@ const add = async (id: FeatureID, ...loaders: FeatureLoader[]): Promise<void> => } }; -const addCssFeature = async (id: FeatureID, include: BooleanFunction[], deduplicate?: false | string): Promise<void> => { +const addCssFeature = async (id: FeatureID, include: BooleanFunction[] | undefined, deduplicate?: false | string): Promise<void> => { void add(id, { include, deduplicate, |