Experiments: Allow more link formats. (#719)
* Allow more experiment link formats. * Support clear button.
This commit is contained in:
parent
510de85112
commit
4627e5dd8e
1 changed files with 31 additions and 0 deletions
|
|
@ -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),
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue