mirror of
https://github.com/Equicord/Equicord.git
synced 2025-03-30 20:21:59 -04:00
Update quickCss.ts
This commit is contained in:
parent
f3ea99e573
commit
1bb0685aea
1 changed files with 5 additions and 63 deletions
|
@ -17,12 +17,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Settings, SettingsStore } from "@api/Settings";
|
import { Settings, SettingsStore } from "@api/Settings";
|
||||||
import { Toasts } from "@webpack/common";
|
|
||||||
|
|
||||||
import { Logger } from "./Logger";
|
|
||||||
import { compileUsercss } from "./themes/usercss/compiler";
|
|
||||||
|
|
||||||
const logger = new Logger("QuickCSS");
|
|
||||||
|
|
||||||
|
|
||||||
let style: HTMLStyleElement;
|
let style: HTMLStyleElement;
|
||||||
|
@ -63,71 +57,20 @@ export async function toggle(isEnabled: boolean) {
|
||||||
async function initThemes() {
|
async function initThemes() {
|
||||||
themesStyle ??= createStyle("vencord-themes");
|
themesStyle ??= createStyle("vencord-themes");
|
||||||
|
|
||||||
const { enabledThemeLinks, enabledThemes } = Settings;
|
const { themeLinks, enabledThemes } = Settings;
|
||||||
|
|
||||||
const links: string[] = [...enabledThemeLinks];
|
const links: string[] = [...themeLinks];
|
||||||
|
|
||||||
if (IS_WEB) {
|
if (IS_WEB) {
|
||||||
for (const theme of enabledThemes) {
|
for (const theme of enabledThemes) {
|
||||||
const themeData = await VencordNative.themes.getThemeData(theme);
|
const themeData = await VencordNative.themes.getThemeData(theme);
|
||||||
if (!themeData) continue;
|
if (!themeData) continue;
|
||||||
|
|
||||||
const blob = new Blob([themeData], { type: "text/css" });
|
const blob = new Blob([themeData], { type: "text/css" });
|
||||||
links.push(URL.createObjectURL(blob));
|
links.push(URL.createObjectURL(blob));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (const theme of enabledThemes) if (!theme.endsWith(".user.css")) {
|
const localThemes = enabledThemes.map(theme => `vencord:///themes/${theme}?v=${Date.now()}`);
|
||||||
links.push(`vencord:///themes/${theme}?v=${Date.now()}`);
|
links.push(...localThemes);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!IS_WEB || "armcord" in window) {
|
|
||||||
for (let i = enabledThemes.length - 1; i >= 0; i--) {
|
|
||||||
const theme = enabledThemes[i];
|
|
||||||
|
|
||||||
if (!theme.endsWith(".user.css")) continue;
|
|
||||||
|
|
||||||
// UserCSS goes through a compile step first
|
|
||||||
const css = await compileUsercss(theme);
|
|
||||||
if (!css) {
|
|
||||||
// let's not leave the user in the dark about this and point them to where they can find the error
|
|
||||||
Toasts.show({
|
|
||||||
message: `Failed to compile ${theme}, check the console for more info.`,
|
|
||||||
type: Toasts.Type.FAILURE,
|
|
||||||
id: Toasts.genId(),
|
|
||||||
options: {
|
|
||||||
position: Toasts.Position.BOTTOM
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Settings.enabledThemes = enabledThemes.splice(enabledThemes.indexOf(theme), 1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const blob = new Blob([css], { type: "text/css" });
|
|
||||||
links.push(URL.createObjectURL(blob));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!IS_WEB || "armcord" in window) {
|
|
||||||
for (const theme of enabledThemes) if (theme.endsWith(".user.css")) {
|
|
||||||
// UserCSS goes through a compile step first
|
|
||||||
const css = await compileUsercss(theme);
|
|
||||||
if (!css) {
|
|
||||||
// let's not leave the user in the dark about this and point them to where they can find the error
|
|
||||||
Toasts.show({
|
|
||||||
message: `Failed to compile ${theme}, check the console for more info.`,
|
|
||||||
type: Toasts.Type.FAILURE,
|
|
||||||
id: Toasts.genId(),
|
|
||||||
options: {
|
|
||||||
position: Toasts.Position.BOTTOM
|
|
||||||
}
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const blob = new Blob([css], { type: "text/css" });
|
|
||||||
links.push(URL.createObjectURL(blob));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
themesStyle.textContent = links.map(link => `@import url("${link.trim()}");`).join("\n");
|
themesStyle.textContent = links.map(link => `@import url("${link.trim()}");`).join("\n");
|
||||||
|
@ -140,9 +83,8 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||||
toggle(Settings.useQuickCss);
|
toggle(Settings.useQuickCss);
|
||||||
SettingsStore.addChangeListener("useQuickCss", toggle);
|
SettingsStore.addChangeListener("useQuickCss", toggle);
|
||||||
|
|
||||||
SettingsStore.addChangeListener("enabledThemeLinks", initThemes);
|
SettingsStore.addChangeListener("themeLinks", initThemes);
|
||||||
SettingsStore.addChangeListener("enabledThemes", initThemes);
|
SettingsStore.addChangeListener("enabledThemes", initThemes);
|
||||||
SettingsStore.addChangeListener("userCssVars", initThemes);
|
|
||||||
|
|
||||||
if (!IS_WEB)
|
if (!IS_WEB)
|
||||||
VencordNative.quickCss.addThemeChangeListener(initThemes);
|
VencordNative.quickCss.addThemeChangeListener(initThemes);
|
||||||
|
|
Loading…
Add table
Reference in a new issue