ModuleBuilder/moduleWrappers/goosemod/plugin.js

51 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-06-16 07:57:48 +00:00
import showToast from '@goosemod/toast';
2021-07-05 14:21:08 +00:00
import { commands } from '@goosemod/patcher';
2021-06-16 07:57:48 +00:00
export default class Plugin {
constructor() {
this.patches = [];
2021-07-05 14:21:08 +00:00
this.commands = [];
this.stylesheets = [];
2021-06-16 07:57:48 +00:00
}
2021-07-05 14:21:08 +00:00
command(...args) {
this.commands.push(args[0]);
commands.add(...args);
}
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-07-05 14:21:08 +00:00
this.commands.forEach((x) => commands.remove(x));
2021-06-16 07:57:48 +00:00
this.onRemove();
}
}
}