ModuleBuilder/moduleWrappers/goosemod/plugin.js

42 lines
854 B
JavaScript
Raw Normal View History

2021-06-16 07:57:48 +00:00
import showToast from '@goosemod/toast';
export default class Plugin {
constructor() {
this.patches = [];
this.stylesheets = [];
2021-06-16 07:57:48 +00:00
}
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
}
2021-06-16 07:57:48 +00:00
toast(content, options) {
showToast(content, {
subtext: this.name,
...options
});
}
goosemodHandlers = {
onImport: () => {
2021-06-16 07:57:48 +00:00
this.onImport();
},
onRemove: () => {
this.patches.forEach((x) => x());
this.stylesheets.forEach((x) => x.remove());
2021-06-16 07:57:48 +00:00
this.onRemove();
}
}
}