const Plugin = require("../plugin") const path = window.require("path") const fs = window.require("fs") module.exports = new Plugin({ name: "CSS Loader + Glasscord Integration", author: "Joe 🎸#7070 + AryToNeX", description: "Loads and hot-reloads CSS.", preload: true, //load this before Discord has finished starting up color: "blue", config: { path: { default: "./plugins/style.css", parse: function (filePath) { if (!filePath || !filePath.endsWith(".css")) { return false } if (path.isAbsolute(filePath)) { if (!fs.existsSync(filePath)) { return false } return path.relative(process.env.injDir, filePath) } else { const p = path.join(process.env.injDir, filePath) if (!fs.existsSync(p)) { return false } return path.relative(process.env.injDir, p) } }, }, }, load: async function () { function readFile(path, encoding = "utf-8") { return new Promise((resolve, reject) => { fs.readFile(path, encoding, (err, data) => { if (err) reject(err) else resolve(data) }) }) } const cssPath = path.join(process.env.injDir, this.settings.path || this.config.path.default) readFile(cssPath) .then((css) => { if (!window.customCss) { window.customCss = document.createElement("style") document.head.appendChild(window.customCss) } window.customCss.innerHTML = css this.info("Custom CSS loaded!", window.customCss) window.require("electron").ipcRenderer.send("glasscord_refresh_variables") if (window.cssWatcher == null) { window.cssWatcher = fs.watch(cssPath, { encoding: "utf-8" }, (eventType) => { if (eventType == "change") { readFile(cssPath).then((newCss) => { window.customCss.innerHTML = newCss window.require("electron").ipcRenderer.send("glasscord_update") }) } }) } }) .catch(() => console.info("Custom CSS not found. Skipping...")) }, unload: function () { if (window.customCss) { document.head.removeChild(window.customCss) window.customCss = null } if (window.cssWatcher) { window.cssWatcher.close() window.cssWatcher = null } }, generateSettings: function () { const d = window.ED.classMaps.description const b = window.ED.classMaps.buttons const id = window.EDApi.findModule("inputDefault") const m = window.EDApi.findModule("marginTop8") const result = `
./big_gay.css
) or absolute (e.g. C:/theme.css
.)