mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-13 00:23:02 -04:00
BetterFolder Fixes
This commit is contained in:
parent
eaf508dd20
commit
ad4ab4c1e5
2 changed files with 40 additions and 8 deletions
|
@ -191,7 +191,7 @@ export default definePlugin({
|
||||||
const originalOnClick = originalProps.onClick!;
|
const originalOnClick = originalProps.onClick!;
|
||||||
originalProps.onClick = e => {
|
originalProps.onClick = e => {
|
||||||
if (!isBlocked) return originalOnClick(e);
|
if (!isBlocked) return originalOnClick(e);
|
||||||
this.openConfirmationModal(e, () => originalOnClick(e), user, true);
|
this.openConfirmationModal(e as unknown as MouseEvent, () => originalOnClick(e), user, true);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,8 +65,16 @@ function patchSidebar(css: string): string {
|
||||||
css.includes("grid-template-areas") && Settings.plugins.BetterFolders.enabled
|
css.includes("grid-template-areas") && Settings.plugins.BetterFolders.enabled
|
||||||
) {
|
) {
|
||||||
css = css.replace(
|
css = css.replace(
|
||||||
/(["'])([^"']*?)guildsList\s+/g,
|
/\btitleBar\b/,
|
||||||
(_, quote, pre) => `${quote}${pre}guildsList sidebar `
|
"titleBar titleBar"
|
||||||
|
);
|
||||||
|
css = css.replace(
|
||||||
|
/\buserPanel\b/,
|
||||||
|
"userPanel userPanel"
|
||||||
|
);
|
||||||
|
css = css.replace(
|
||||||
|
/guildsList/g,
|
||||||
|
"guildsList sidebar"
|
||||||
);
|
);
|
||||||
css = css.replace(
|
css = css.replace(
|
||||||
/guildsEnd\]/g,
|
/guildsEnd\]/g,
|
||||||
|
@ -76,6 +84,32 @@ function patchSidebar(css: string): string {
|
||||||
return css;
|
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() {
|
async function initThemes() {
|
||||||
themesStyle ??= createStyle("vencord-themes");
|
themesStyle ??= createStyle("vencord-themes");
|
||||||
|
|
||||||
|
@ -96,11 +130,9 @@ async function initThemes() {
|
||||||
const links: string[] = [];
|
const links: string[] = [];
|
||||||
|
|
||||||
for (const url of rawLinks) {
|
for (const url of rawLinks) {
|
||||||
try {
|
const css = await fetchAndPatchCSS(url);
|
||||||
const res = await fetch(url);
|
if (css) {
|
||||||
const css = await res.text();
|
const blob = new Blob([css], { type: "text/css" });
|
||||||
const patched = patchSidebar(css);
|
|
||||||
const blob = new Blob([patched], { type: "text/css" });
|
|
||||||
links.push(URL.createObjectURL(blob));
|
links.push(URL.createObjectURL(blob));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(`Failed to fetch theme from ${url}`, e);
|
console.warn(`Failed to fetch theme from ${url}`, e);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue