From 4627e5dd8e8d2d4fed6cb666f3633df417f052da Mon Sep 17 00:00:00 2001 From: Etorix <92535668+EtorixDev@users.noreply.github.com> Date: Mon, 2 Feb 2026 04:11:59 -0800 Subject: [PATCH] Experiments: Allow more link formats. (#719) * Allow more experiment link formats. * Support clear button. --- src/plugins/experiments/index.tsx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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),