Skip to content

Commit

Permalink
less annoying
Browse files Browse the repository at this point in the history
  • Loading branch information
wont-stream committed Sep 22, 2024
1 parent e7cbee2 commit d9135cb
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
78 changes: 78 additions & 0 deletions plugins/eurotilities/helpers/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,81 @@ export function findByProps(...props) {
}
return result;
}

{
// Original code taken from https://github.com/Vendicated/Vencord under GPLv3 license

// biome-ignore lint/suspicious/noImplicitAnyLet: N/A
let wreq;
// biome-ignore lint/suspicious/noImplicitAnyLet: N/A
// biome-ignore lint/style/useConst: N/A
let cache;

window.webpackChunkdiscord_app.push([
[Symbol()],
{},
(x) => {
wreq = x;
},
]);
window.webpackChunkdiscord_app.pop();
cache = wreq.c;

const filters = {
byProps:
(...props) =>
(m) =>
props.every((p) => m[p] !== void 0),
};

function handleModuleNotFound(method, ...filter) {
const errMsg = `webpack.${method} found no module. Filter: ${filter}`;
console.error(new Error(errMsg));
return { error: errMsg };
}

function find(filter, { isIndirect = false, isWaitFor = false } = {}) {
if (typeof filter !== "function") {
return handleModuleNotFound("find", "Invalid filter function");
}

for (const key in cache) {
const mod = cache[key];
if (!mod.loaded || !mod?.exports) continue;

const exports = mod.exports;

if (filter(exports)) return isWaitFor ? [exports, key] : exports;

if (exports.default && filter(exports.default)) {
const found = exports.default;
return isWaitFor ? [found, key] : found;
}

if (typeof exports === "object") {
for (const nestedKey in exports) {
if (nestedKey.length > 3) continue;

const nested = exports[nestedKey];
if (nested && filter(nested)) {
return isWaitFor ? [nested, key] : nested;
}
}
}
}

if (!isIndirect) {
return handleModuleNotFound("find", filter);
}

return isWaitFor ? [null, null] : null;
}

function findByProps(...props) {
const result = find(filters.byProps(...props), { isIndirect: true });
if (!result || result.error) {
return handleModuleNotFound("findByProps", ...props);
}
return result;
}
}
1 change: 1 addition & 0 deletions plugins/eurotilities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function onLoad() {
...modules[module],
title: `${modules[module].title} - Enabled`,
content: null,
duration: 0,
});
}
}
Expand Down

0 comments on commit d9135cb

Please sign in to comment.