Fix everything broken by recent Discord update (#3177)

Co-authored-by: sadan <117494111+sadan4@users.noreply.github.com>
Co-authored-by: Vendicated <vendicated@riseup.net>
This commit is contained in:
Nuckyz 2025-01-29 01:04:36 -03:00 committed by GitHub
parent cdc756193e
commit 33d4f13a24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 389 additions and 244 deletions

View file

@ -56,11 +56,14 @@ export const filters = {
: m => props.every(p => m[p] !== void 0),
byCode: (...code: CodeFilter): FilterFn => {
code = code.map(canonicalizeMatch);
return m => {
const parsedCode = code.map(canonicalizeMatch);
const filter = m => {
if (typeof m !== "function") return false;
return stringMatches(Function.prototype.toString.call(m), code);
return stringMatches(Function.prototype.toString.call(m), parsedCode);
};
filter.$$vencordProps = [...code];
return filter;
},
byStoreName: (name: StoreNameFilter): FilterFn => m =>
m.constructor?.displayName === name,
@ -131,8 +134,7 @@ export const find = traceFunction("find", function find(filter: FilterFn, { isIn
return isWaitFor ? [found, key] : found;
}
// the length check makes search about 20% faster
for (const nestedMod in mod.exports) if (nestedMod.length <= 3) {
for (const nestedMod in mod.exports) {
const nested = mod.exports[nestedMod];
if (nested && filter(nested)) {
return isWaitFor ? [nested, key] : nested;
@ -163,7 +165,7 @@ export function findAll(filter: FilterFn) {
if (mod.exports.default && filter(mod.exports.default))
ret.push(mod.exports.default);
else for (const nestedMod in mod.exports) if (nestedMod.length <= 3) {
else for (const nestedMod in mod.exports) {
const nested = mod.exports[nestedMod];
if (nested && filter(nested)) ret.push(nested);
}
@ -226,16 +228,15 @@ export const findBulk = traceFunction("findBulk", function findBulk(...filterFns
break;
}
for (const nestedMod in mod.exports)
if (nestedMod.length <= 3) {
const nested = mod.exports[nestedMod];
if (nested && filter(nested)) {
results[j] = nested;
filters[j] = undefined;
if (++found === length) break outer;
continue outer;
}
for (const nestedMod in mod.exports) {
const nested = mod.exports[nestedMod];
if (nested && filter(nested)) {
results[j] = nested;
filters[j] = undefined;
if (++found === length) break outer;
continue outer;
}
}
}
}