//META{"name":"ThemeSettings"}*// class ThemeSettings { getName () {return "ThemeSettings";} getVersion () {return "1.0.9";} getAuthor () {return "DevilBro";} getDescription () {return "Allows you to change Theme Variables within BetterDiscord. Adds a Settings button (similar to Plugins) to customizable Themes in your Themes Page.";} initConstructor () { this.patchModules = { "V2C_ThemeCard":"componentDidMount" }; } //legacy load () {} start () { var libraryScript = null; if (typeof BDFDB !== "object" || typeof BDFDB.isLibraryOutdated !== "function" || BDFDB.isLibraryOutdated()) { libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]'); if (libraryScript) libraryScript.remove(); libraryScript = document.createElement("script"); libraryScript.setAttribute("type", "text/javascript"); libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"); document.head.appendChild(libraryScript); } this.startTimeout = setTimeout(() => {this.initialize();}, 30000); if (typeof BDFDB === "object" && typeof BDFDB.isLibraryOutdated === "function") this.initialize(); else libraryScript.addEventListener("load", () => {this.initialize();}); } initialize () { if (typeof BDFDB === "object") { BDFDB.loadMessage(this); this.fs = require("fs"); this.path = require("path"); this.dir = BDFDB.getThemesFolder(); BDFDB.WebModules.forceAllUpdates(this); } else { console.error(this.getName() + ": Fatal Error: Could not load BD functions!"); } } stop () { if (typeof BDFDB === "object") { BDFDB.removeEles(".themes-settings-button",".themes-settings-footer"); BDFDB.unloadMessage(this); } } // begin of own functions processV2CThemeCard (instance, wrapper) { if (instance.props && instance.props.theme && !wrapper.querySelector(BDFDB.dotCN._reposettingsbutton + ".themes-settings-button")) { let vars = this.getThemeVars(instance.props.theme.css); if (vars.length) { let footer = wrapper.querySelector(BDFDB.dotCN._repofooter); if (!footer) { footer = document.createElement("div"); footer.className = BDFDB.disCNS._repofooter + "themes-settings-footer"; wrapper.appendChild(footer); } let button = document.createElement("button"); button.className = BDFDB.disCNS._reposettingsbutton + "themes-settings-button"; button.innerText = "Settings"; footer.appendChild(button); button.addEventListener("click", () => { wrapper.classList.add(BDFDB.disCN._reposettingsopen); wrapper.classList.remove(BDFDB.disCN._reposettingsclosed); let children = []; while (wrapper.childElementCount) { children.push(wrapper.firstChild); wrapper.firstChild.remove(); } let closebutton = BDFDB.htmlToElement(`
`); wrapper.appendChild(closebutton); closebutton.addEventListener("click", () => { wrapper.classList.remove(BDFDB.disCN._reposettingsopen); wrapper.classList.add(BDFDB.disCN._reposettingsclosed); while (wrapper.childElementCount) wrapper.firstChild.remove(); while (children.length) wrapper.appendChild(children.shift()); }) this.createThemeSettings(wrapper, instance.props.theme, vars); }); } } } getThemeVars (css) { let vars = css.split(":root"); if (vars.length > 1) { vars = vars[1].replace(/\t| {2,}/g,"").replace(/\n\/\*.*?\*\//g,"").replace(/[\n\r]/g,""); vars = vars.split("{"); vars.shift(); vars = vars.join("{").replace(/\s*(:|;|--|\*)\s*/g,"$1"); vars = vars.split("}")[0]; return vars.slice(2).split(/;--|\*\/--/); } return []; } createThemeSettings (wrapper, theme, vars) { if (!this.started || typeof BDFDB !== "object") return; var settingshtml = `