feat(plugins): SilentMessageToggle (#586)

Co-authored-by: Ven <vendicated@riseup.net>
This commit is contained in:
Nuckyz 2023-03-08 21:19:28 -03:00 committed by GitHub
parent 253183a16a
commit bff6788546
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 11 deletions

View file

@ -38,13 +38,11 @@ function listener(exports: any, id: number) {
noWarn: true,
find: "navId:",
replacement: [{
/** Regex explanation
* Use of https://blog.stevenlevithan.com/archives/mimic-atomic-groups to mimick atomic groups: (?=(...))\1
* Match ${id} and look behind it for the first match of `<variable name>=`: ${id}(?=(\i)=.+?)
* Match rest of the code until it finds `<variable name>.${key},{`: .+?\2\.${key},{
*/
match: RegExp(`(?=(${id}(?<=(\\i)=.+?).+?\\2\\.${key},{))\\1`, "g"),
replace: "$&contextMenuApiArguments:arguments,"
match: RegExp(`${id}(?<=(\\i)=.+?).+$`),
replace: (code, varName) => {
const regex = RegExp(`${key},{(?<=${varName}\\.${key},{)`, "g");
return code.replace(regex, "$&contextMenuApiArguments:arguments,");
}
}]
});