From a6e70a41dd1262d61e56804f64ba8bfd793456c9 Mon Sep 17 00:00:00 2001 From: Oj Date: Wed, 7 Apr 2021 19:06:31 +0100 Subject: [PATCH] [PCCompat > Plugin] Implement Plugin.loadStylesheet --- moduleWrappers/powercord/entities.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/moduleWrappers/powercord/entities.js b/moduleWrappers/powercord/entities.js index 0e0e0d0..eb05508 100644 --- a/moduleWrappers/powercord/entities.js +++ b/moduleWrappers/powercord/entities.js @@ -2,13 +2,19 @@ import * as Settings from './util/settings'; export class Plugin { constructor() { - + this.stylesheets = []; } - loadStylesheet(path) { // TODO: actually implement this func - const url = `https://raw.githubusercontent.com/${this.github.repo}/main/${path}`; + loadStylesheet(path) { + const url = `https://raw.githubusercontent.com/${this.github.repo}/HEAD/${path}`; // HEAD essentially means default branch - return url; + 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) @@ -44,7 +50,11 @@ export class Plugin { this.startPlugin.bind(this)(); }, - onRemove: this.pluginWillUnload.bind(this) + onRemove: () => { + this.stylesheets.forEach((x) => x.remove()); // Remove loaded stylesheets which were added with Plugin.loadStylesheet + + this.pluginWillUnload.bind(this)(); + } }; } }