mirror of
https://github.com/NovaGM/ModuleBuilder.git
synced 2024-08-15 00:23:33 +00:00
[GM > Plugin] Add addCSS(css), source tweaks
This commit is contained in:
parent
8b347972ac
commit
42e2c02719
1 changed files with 15 additions and 5 deletions
|
@ -3,12 +3,23 @@ import showToast from '@goosemod/toast';
|
|||
export default class Plugin {
|
||||
constructor() {
|
||||
this.patches = [];
|
||||
this.stylesheets = [];
|
||||
}
|
||||
|
||||
enqueueUnpatch(unpatch) {
|
||||
this.patches.push(unpatch);
|
||||
}
|
||||
|
||||
addCss(css) {
|
||||
const el = document.createElement('style');
|
||||
|
||||
el.appendChild(document.createTextNode(css)); // Load the stylesheet via style element w/ CSS text
|
||||
|
||||
document.head.appendChild(el);
|
||||
|
||||
this.stylesheets.push(el); // Push to internal array so we can remove the elements on unload
|
||||
}
|
||||
|
||||
toast(content, options) {
|
||||
showToast(content, {
|
||||
subtext: this.name,
|
||||
|
@ -17,14 +28,13 @@ export default class Plugin {
|
|||
}
|
||||
|
||||
goosemodHandlers = {
|
||||
onImport() {
|
||||
onImport: () => {
|
||||
this.onImport();
|
||||
},
|
||||
|
||||
onRemove() {
|
||||
for (const unpatch of this.patches) {
|
||||
unpatch();
|
||||
}
|
||||
onRemove: () => {
|
||||
this.patches.forEach((x) => x());
|
||||
this.stylesheets.forEach((x) => x.remove());
|
||||
|
||||
this.onRemove();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue