Experiments: Allow more link formats. (#719)

* Allow more experiment link formats.

* Support clear button.
This commit is contained in:
Etorix 2026-02-02 04:11:59 -08:00 • committed by GitHub
parent 510de85112
commit 4627e5dd8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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),