aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-03-26 22:39:07 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-03-26 22:39:07 +0530
commit068a14ffa464d6cb0ccc5c3cec11d10d8cceae90 (patch)
treeb0d721ca44a705d6d554e3a93479eee51645d3e7 /src/utils
parentd6682a1ed9acd31dbfdb9e645cc8230c61a268c3 (diff)
downloadbanglar-bhumi-utils-068a14ffa464d6cb0ccc5c3cec11d10d8cceae90.tar.gz
banglar-bhumi-utils-068a14ffa464d6cb0ccc5c3cec11d10d8cceae90.zip
Sharing code between scripts for reduced bundle size.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/modify-dom.ts41
-rw-r--r--src/utils/observe-dom.ts12
-rw-r--r--src/utils/styling.ts8
3 files changed, 0 insertions, 61 deletions
diff --git a/src/utils/modify-dom.ts b/src/utils/modify-dom.ts
deleted file mode 100644
index f08f7d9..0000000
--- a/src/utils/modify-dom.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import { observeDOM } from "@/utils/observe-dom";
-
-type DOMReplacements = {
- innerHTML?: string;
- [key: string]: string | undefined | null;
-};
-
-type DOMModificaitonRule = readonly [string, DOMReplacements];
-
-export const modifyDOM = (modificationRules: (DOMModificaitonRule | null)[]) => {
- let count = 0;
-
- observeDOM(() => {
- for (let i = 0; i < modificationRules.length; i++) {
- if (modificationRules[i]) {
- const element = document.querySelector(modificationRules[i]![0]) as HTMLElement | null;
- if (element) {
- const attributes = modificationRules[i]![1] as DOMReplacements;
- if (attributes.innerHTML) {
- element.innerHTML = attributes.innerHTML as string;
- }
- delete attributes.innerHTML;
- for (const attribute in attributes) {
- if (attributes[attribute] === null) {
- element.removeAttribute(attribute);
- } else {
- element.setAttribute(attribute, attributes[attribute] as string);
- }
- }
- modificationRules[i] = null;
- count++;
- if (count >= modificationRules.length) {
- return true;
- }
- }
- }
- }
-
- return false;
- });
-};
diff --git a/src/utils/observe-dom.ts b/src/utils/observe-dom.ts
deleted file mode 100644
index 4a447a0..0000000
--- a/src/utils/observe-dom.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-export const observeDOM = (callback: () => boolean) => {
- const observer = new MutationObserver(() => {
- if (callback()) {
- observer.disconnect();
- }
- });
-
- observer.observe(document, {
- childList: true,
- subtree: true
- });
-};
diff --git a/src/utils/styling.ts b/src/utils/styling.ts
deleted file mode 100644
index 0e527d9..0000000
--- a/src/utils/styling.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-export const styles = (selector: string, styles: { [key: string]: string }) => {
- const elements = Array.from(document.querySelectorAll(selector)) as HTMLElement[];
- for (const element of elements) {
- for (const styleType in styles) {
- element.style[styleType as any] = styles[styleType];
- }
- }
-};