BetterFolder Fixes

This commit is contained in:
thororen1234 2025-04-04 09:19:21 -04:00
parent eaf508dd20
commit ad4ab4c1e5
No known key found for this signature in database
2 changed files with 40 additions and 8 deletions

View file

@ -191,7 +191,7 @@ export default definePlugin({
const originalOnClick = originalProps.onClick!;
originalProps.onClick = e => {
if (!isBlocked) return originalOnClick(e);
this.openConfirmationModal(e, () => originalOnClick(e), user, true);
this.openConfirmationModal(e as unknown as MouseEvent, () => originalOnClick(e), user, true);
};
}

View file

@ -65,8 +65,16 @@ function patchSidebar(css: string): string {
css.includes("grid-template-areas") && Settings.plugins.BetterFolders.enabled
) {
css = css.replace(
/(["'])([^"']*?)guildsList\s+/g,
(_, quote, pre) => `${quote}${pre}guildsList sidebar `
/\btitleBar\b/,
"titleBar titleBar"
);
css = css.replace(
/\buserPanel\b/,
"userPanel userPanel"
);
css = css.replace(
/guildsList/g,
"guildsList sidebar"
);
css = css.replace(
/guildsEnd\]/g,
@ -76,6 +84,32 @@ function patchSidebar(css: string): string {
return css;
}
async function fetchAndPatchCSS(url: string): Promise<string> {
try {
const res = await fetch(url);
const css = await res.text();
const importLinks = extractImportLinks(css);
const patchedCSS = await Promise.all(importLinks.map(fetchAndPatchCSS));
const combinedCSS = patchedCSS.join("\n") + "\n" + patchSidebar(css);
return combinedCSS;
} catch (e) {
console.warn(`Failed to fetch and patch CSS from ${url}`, e);
return "";
}
}
function extractImportLinks(css: string): string[] {
const importRegex = /@import url\(([^)]+)\)/g;
const links: string[] = [];
let match;
while ((match = importRegex.exec(css)) !== null) {
links.push(match[1].trim().replace(/['"]/g, ""));
}
return links;
}
async function initThemes() {
themesStyle ??= createStyle("vencord-themes");
@ -96,11 +130,9 @@ async function initThemes() {
const links: string[] = [];
for (const url of rawLinks) {
try {
const res = await fetch(url);
const css = await res.text();
const patched = patchSidebar(css);
const blob = new Blob([patched], { type: "text/css" });
const css = await fetchAndPatchCSS(url);
if (css) {
const blob = new Blob([css], { type: "text/css" });
links.push(URL.createObjectURL(blob));
} catch (e) {
console.warn(`Failed to fetch theme from ${url}`, e);