import * as Settings from './util/settings'; export class Plugin { constructor() { this.stylesheets = []; } loadStylesheet(path) { const url = `https://raw.githubusercontent.com/${this.github.repo}/HEAD/${path}`; // HEAD essentially means default branch const el = document.createElement('style'); el.appendChild(document.createTextNode(`@import url(${url})`)); // Load the stylesheet via style element w/ CSS @import document.head.appendChild(el); this.stylesheets.push(el); // Push to internal array so we can remove the elements on unload } delayedConstructor() { // Run funcs which rely on after eval (GooseMod sets keys on this class with more info, mostly metadata) if (this.delayedConstructed) return; this.delayedConstructed = true; Settings.makeStore(this.entityID); } get entityID() { return this.name; } get settings() { const store = Settings.settingStores[this.entityID]; return { // Basic wrapper with renamed functions get: store.getSetting, set: store.setSetting, delete: store.deleteSetting, getKeys: store.getKeys, connectStore: () => {} // Unneeded util func, but here incase it is attempted to be called }; } get goosemodHandlers() { return { onImport: () => { this.delayedConstructor(); this.startPlugin.bind(this)(); }, onRemove: () => { this.stylesheets.forEach((x) => x.remove()); // Remove loaded stylesheets which were added with Plugin.loadStylesheet this.pluginWillUnload.bind(this)(); } }; } }