blob: 6867dd4fb58859ac7ad2ace6b29389d45e3a84c1 [file] [log] [blame]
Adrià Vilanova Martínezdfe71fc2024-05-25 22:13:32 +02001import { StylesheetAttributes, injectStylesheet } from './contentScriptsUtils';
2
3export default class StylesheetManager {
4 private injectedElement: HTMLElement;
5
6 constructor(
7 /**
8 * Relative path to the stylesheet from the extension root.
9 */
10 public stylesheet: string,
11
12 /**
13 * Attributes to include in the injected <link> element.
14 */
15 public attributes: StylesheetAttributes = {},
16 ) {}
17
18 isInjected() {
19 return this.injectedElement !== undefined;
20 }
21
22 inject() {
23 this.injectedElement = injectStylesheet(
24 chrome.runtime.getURL(this.stylesheet),
25 this.attributes,
26 );
27 }
28
29 remove() {
30 this.injectedElement.remove();
31 this.injectedElement = undefined;
32 }
33}