BetterDiscordApp-rauenzi/src/builtins/customcss.js

66 lines
2.0 KiB
JavaScript
Raw Normal View History

2019-06-10 05:40:35 +02:00
import Builtin from "../structs/builtin";
2019-06-10 22:37:50 +02:00
import {Settings, DataStore, React, Events} from "modules";
2019-06-10 05:40:35 +02:00
import CSSEditor from "../ui/customcss/editor";
2019-06-10 22:37:50 +02:00
const electron = require("electron");
2019-06-10 05:40:35 +02:00
export default new class CustomCSS extends Builtin {
get name() {return "Custom CSS";}
get category() {return "customcss";}
get id() {return "customcss";}
2019-06-10 22:37:50 +02:00
get startDetached() {return Settings.get(this.collection, this.category, "startDetached");}
get nativeOpen() {return Settings.get(this.collection, this.category, "nativeOpen");}
constructor() {
super();
this.css = "";
}
2019-06-10 05:40:35 +02:00
enabled() {
Settings.registerPanel(this.id, this.name, {
2019-06-10 22:37:50 +02:00
order: 2,
element: () => React.createElement(CSSEditor, {
css: this.css,
save: this.saveCSS.bind(this),
update: this.insertCSS.bind(this),
openNative: this.openNative.bind(this)
}),
onClick: (thisObject) => {
if (this.nativeOpen) this.openNative();
else if (this.startDetached) this.openDetached();
else thisObject._reactInternalFiber.child.memoizedProps.children.props.onSetSection(this.name);
}
2019-06-10 05:40:35 +02:00
});
2019-06-10 22:37:50 +02:00
this.loadCSS();
this.insertCSS();
2019-06-10 05:40:35 +02:00
}
disabled() {
Settings.removePanel(this.id);
}
2019-06-10 22:37:50 +02:00
loadCSS() {
this.css = DataStore.loadCustomCSS();
}
insertCSS(newCss) {
if (typeof(newCss) === "undefined") newCss = this.css;
if ($("#customcss").length == 0) {
$("head").append("<style id=\"customcss\"></style>");
}
$("#customcss").text(newCss).detach().appendTo(document.head);
}
saveCSS(newCss) {
if (typeof(newCss) !== "undefined") this.css = newCss;
DataStore.saveCustomCSS(this.css);
}
openNative() {
electron.shell.openExternal(`file://${DataStore.customCSS}`);
}
openDetached() {
this.log("Should open detached");
}
2019-06-10 05:40:35 +02:00
};