From 7a6707374f231d9cb07476c9453727ee5c6c9a45 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Tue, 14 Feb 2023 12:27:01 +0530 Subject: Using on loaded scripts for chaning styles. --- src/utils/modify-dom.ts | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'src/utils/modify-dom.ts') diff --git a/src/utils/modify-dom.ts b/src/utils/modify-dom.ts index 4e36008..da0944b 100644 --- a/src/utils/modify-dom.ts +++ b/src/utils/modify-dom.ts @@ -1,20 +1,15 @@ import { observeDOM } from "@/utils/observe-dom"; type Replacements = { - innerHTML?: string; - styles?: { - [key: string]: string - }; -} | { [key: string]: string | null }; export class DOMModifier { selector: string; - replaced: Replacements; - constructor(selector: string, replaced: Replacements) { + attributes: Replacements; + constructor(selector: string, attributes: Replacements) { this.selector = selector; - this.replaced = replaced; + this.attributes = attributes; } } @@ -26,17 +21,11 @@ export const modifyDOM = (elements: (DOMModifier | null)[]) => { if (elements[i]) { const element = document.querySelector(elements[i]!.selector) as HTMLElement | null; if (element) { - const attributes = elements[i]!.replaced as any; + const attributes = elements[i]!.attributes as any; if (attributes.innerHTML) { element.innerHTML = attributes.innerHTML; } - if (attributes.styles) { - for (const styleType in attributes.styles) { - element.style[styleType as any] = attributes.styles[styleType]; - } - } delete attributes.innerHTML; - delete attributes.styles; for (const attribute in attributes) { if (attributes[attribute] === null) { element.removeAttribute(attribute); -- cgit v1.2.3