aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-02-12 06:43:51 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-02-12 06:43:51 +0530
commita6f62616b7c10092451cb2b7d6ed5c7c5b250712 (patch)
tree785456fbe40cb256c1cdcf8eb5b5e67e06c31d95 /src
parent1caecf35a2d0ee81cedea40ccbd4ad4150bca2f8 (diff)
downloadbanglar-bhumi-utils-a6f62616b7c10092451cb2b7d6ed5c7c5b250712.tar.gz
banglar-bhumi-utils-a6f62616b7c10092451cb2b7d6ed5c7c5b250712.zip
Added home page optimizations.
Diffstat (limited to 'src')
-rw-r--r--src/scripts.json3
-rw-r--r--src/scripts/optimize/home-page.ts30
-rw-r--r--src/scripts/optimize/index.ts (renamed from src/scripts/optimize.ts)2
3 files changed, 33 insertions, 2 deletions
diff --git a/src/scripts.json b/src/scripts.json
index ee042b2..6980407 100644
--- a/src/scripts.json
+++ b/src/scripts.json
@@ -1,6 +1,7 @@
{
"before": {
- "optimize.ts": "*"
+ "optimize/index.ts": "*",
+ "optimize/home-page.ts": "Home.action"
},
"injected": {
"stop-blocking.js": "*"
diff --git a/src/scripts/optimize/home-page.ts b/src/scripts/optimize/home-page.ts
new file mode 100644
index 0000000..5ca4c2e
--- /dev/null
+++ b/src/scripts/optimize/home-page.ts
@@ -0,0 +1,30 @@
+const replace: (any[] | undefined)[] = [
+ ["#slider > img", { src: "" }],
+ ["#slider > img.nivo-main-image", { src: "" }]
+];
+let count = 0;
+
+const observer = new MutationObserver(() => {
+ for (let i = 0; i < replace.length; i++) {
+ if (replace[i]) {
+ const element = document.querySelector(replace[i]![0]) as HTMLElement | null;
+ if (element) {
+ const attributes = replace[i]![1];
+ if (attributes.innerHTML) {
+ element.innerHTML = attributes.innerHTML;
+ }
+ delete attributes.innerHTML;
+ for (const attribute in attributes) {
+ element.setAttribute(attribute, attributes[attribute]);
+ }
+ replace[i] = undefined;
+ count++;
+ if (count >= replace.length) {
+ observer.disconnect();
+ break;
+ }
+ }
+ }
+ }
+});
+observer.observe(document, {childList: true, subtree: true});
diff --git a/src/scripts/optimize.ts b/src/scripts/optimize/index.ts
index 3994333..8b63c53 100644
--- a/src/scripts/optimize.ts
+++ b/src/scripts/optimize/index.ts
@@ -13,7 +13,7 @@ const observer = new MutationObserver(() => {
if (attributes.innerHTML) {
element.innerHTML = attributes.innerHTML;
}
- attributes.innerHTML = undefined;
+ delete attributes.innerHTML;
for (const attribute in attributes) {
element.setAttribute(attribute, attributes[attribute]);
}