aboutsummaryrefslogtreecommitdiff
path: root/src/utils/quickCss.ts
diff options
context:
space:
mode:
authormegumin <megumin.bakaretsurie@gmail.com>2023-08-04 18:52:20 +0100
committerGitHub <noreply@github.com>2023-08-04 19:52:20 +0200
commitd6c43986fd665b60a8a83d41ef907dab22e990e7 (patch)
treeff9eda6794ef371568662b389a5e71e32bbbc16c /src/utils/quickCss.ts
parentbb7deeb09cb263d158de0d99e873c3d3f43a73bb (diff)
downloadVencord-d6c43986fd665b60a8a83d41ef907dab22e990e7.tar.gz
Vencord-d6c43986fd665b60a8a83d41ef907dab22e990e7.tar.bz2
Vencord-d6c43986fd665b60a8a83d41ef907dab22e990e7.zip
Add proper user-friendly theme manager (#635)
Co-authored-by: Justice Almanzar <superdash993@gmail.com> Co-authored-by: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Co-authored-by: V <vendicated@riseup.net>
Diffstat (limited to 'src/utils/quickCss.ts')
-rw-r--r--src/utils/quickCss.ts24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/utils/quickCss.ts b/src/utils/quickCss.ts
index 0ce50e5..488dcfb 100644
--- a/src/utils/quickCss.ts
+++ b/src/utils/quickCss.ts
@@ -46,9 +46,23 @@ async function initThemes() {
document.documentElement.appendChild(themesStyle);
}
- const { themeLinks } = Settings;
- const links = themeLinks.map(link => `@import url("${link.trim()}");`).join("\n");
- themesStyle.textContent = links;
+ const { themeLinks, enabledThemes } = Settings;
+
+ const links: string[] = [...themeLinks];
+
+ if (IS_WEB) {
+ for (const theme of enabledThemes) {
+ const themeData = await VencordNative.themes.getThemeData(theme);
+ if (!themeData) continue;
+ const blob = new Blob([themeData], { type: "text/css" });
+ links.push(URL.createObjectURL(blob));
+ }
+ } else {
+ const localThemes = enabledThemes.map(theme => `vencord:///themes/${theme}?v=${Date.now()}`);
+ links.push(...localThemes);
+ }
+
+ themesStyle.textContent = links.map(link => `@import url("${link.trim()}");`).join("\n");
}
document.addEventListener("DOMContentLoaded", () => {
@@ -57,4 +71,8 @@ document.addEventListener("DOMContentLoaded", () => {
initThemes();
addSettingsListener("themeLinks", initThemes);
+ addSettingsListener("enabledThemes", initThemes);
+
+ if (!IS_WEB)
+ VencordNative.quickCss.addThemeChangeListener(initThemes);
});