[GM > Plugin] Add addCSS(css), source tweaks
This commit is contained in:
parent
8b347972ac
commit
42e2c02719
|
@ -3,12 +3,23 @@ import showToast from '@goosemod/toast';
|
||||||
export default class Plugin {
|
export default class Plugin {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.patches = [];
|
this.patches = [];
|
||||||
|
this.stylesheets = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
enqueueUnpatch(unpatch) {
|
enqueueUnpatch(unpatch) {
|
||||||
this.patches.push(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) {
|
toast(content, options) {
|
||||||
showToast(content, {
|
showToast(content, {
|
||||||
subtext: this.name,
|
subtext: this.name,
|
||||||
|
@ -17,14 +28,13 @@ export default class Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
goosemodHandlers = {
|
goosemodHandlers = {
|
||||||
onImport() {
|
onImport: () => {
|
||||||
this.onImport();
|
this.onImport();
|
||||||
},
|
},
|
||||||
|
|
||||||
onRemove() {
|
onRemove: () => {
|
||||||
for (const unpatch of this.patches) {
|
this.patches.forEach((x) => x());
|
||||||
unpatch();
|
this.stylesheets.forEach((x) => x.remove());
|
||||||
}
|
|
||||||
|
|
||||||
this.onRemove();
|
this.onRemove();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue