diff --git a/src/plugins/experiments/index.tsx b/src/plugins/experiments/index.tsx index 47f9e3dad..7e889c8f5 100644 --- a/src/plugins/experiments/index.tsx +++ b/src/plugins/experiments/index.tsx @@ -45,6 +45,7 @@ export default definePlugin({ Devs.Nuckyz, ], + isModified: true, settings, patches: [ @@ -126,9 +127,39 @@ export default definePlugin({ match: /PotionIcon.{0,250}getCurrentUser\(\);return/, replace: "$& true||" } + }, + { + // Expands the experiment regex to allow negative numbers as well as text in the last segment of the URL. + find: "?\"dev://experiment/\".concat", + replacement: { + match: /(\[0-9\]\+)/, + replace: "[a-zA-Z0-9-]+" + } + }, + { + find: ".EXPERIMENT_TREATMENT&&null", + replacement: [ + { + // Uses the label instead of the value for the button text in the experiment embed. + match: /"Clear Treatment ".concat\((\i).value\):"Apply Treatment ".concat\(\i.value\)/, + replace: '"Clear Treatment: ".concat($1.label):"Apply Treatment: ".concat($1.label)' + }, + { + // Allow linking experiments by their label instead of their value. + match: /(?<=find\(\i=>)((\i).value===\i)/, + replace: "{return($1)||($self.matchExperiment(arguments[0].url,$2.label))}" + } + ] } ], + matchExperiment(url: string, label: string): boolean { + const items = url.split("/"); + const labelCleaned = label.replace(/[^a-zA-Z0-9]+/g, "").toLowerCase(); + const urlEndCleaned = items[items.length - 1]?.replace(/[^a-zA-Z0-9]+/g, "").toLowerCase(); + return !!labelCleaned && urlEndCleaned !== undefined && labelCleaned === urlEndCleaned; + }, + start: () => !BugReporterExperiment.getCurrentConfig().hasBugReporterAccess && enableStyle(hideBugReport), stop: () => disableStyle(hideBugReport),