[GM > Plugin] Add addCSS(css), source tweaks

This commit is contained in:
Ducko 2021-06-16 19:49:45 +01:00 committed by Alyxia Sother
parent 8b347972ac
commit 42e2c02719
No known key found for this signature in database
GPG Key ID: 355968D14144B739
1 changed files with 15 additions and 5 deletions

View File

@ -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();
}