aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/modify-dom.ts
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-02-14 12:27:01 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-02-14 12:27:01 +0530
commit7a6707374f231d9cb07476c9453727ee5c6c9a45 (patch)
tree91b42f57ee2a3fbc05cf1f8f46df8b5018bd2764 /src/utils/modify-dom.ts
parent1393f99b39906f85689f7781da188e6fb414eaf6 (diff)
downloadbanglar-bhumi-utils-7a6707374f231d9cb07476c9453727ee5c6c9a45.tar.gz
banglar-bhumi-utils-7a6707374f231d9cb07476c9453727ee5c6c9a45.zip
Using on loaded scripts for chaning styles.
Diffstat (limited to 'src/utils/modify-dom.ts')
-rw-r--r--src/utils/modify-dom.ts19
1 files changed, 4 insertions, 15 deletions
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);