From a6f62616b7c10092451cb2b7d6ed5c7c5b250712 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Sun, 12 Feb 2023 06:43:51 +0530 Subject: Added home page optimizations. --- config/webpack/loaders/scoped-loader.js | 2 +- src/scripts.json | 3 ++- src/scripts/optimize.ts | 30 ------------------------------ src/scripts/optimize/home-page.ts | 30 ++++++++++++++++++++++++++++++ src/scripts/optimize/index.ts | 30 ++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 32 deletions(-) delete mode 100644 src/scripts/optimize.ts create mode 100644 src/scripts/optimize/home-page.ts create mode 100644 src/scripts/optimize/index.ts diff --git a/config/webpack/loaders/scoped-loader.js b/config/webpack/loaders/scoped-loader.js index c2f9636..ec7b7eb 100644 --- a/config/webpack/loaders/scoped-loader.js +++ b/config/webpack/loaders/scoped-loader.js @@ -12,7 +12,7 @@ const getScriptType = scriptName => { }; module.exports = function (source) { - return `/*<--\t${getScriptType(path.basename(this.resourcePath))}\t-->*/ + return `/*<--\t${getScriptType(this.resourcePath.replace(path.resolve(SOURCE_DIR, "scripts") + "/", ""))}\t-->*/ (() => {\n${source}\n})(); /*<---->*/` }; 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.ts b/src/scripts/optimize.ts deleted file mode 100644 index 3994333..0000000 --- a/src/scripts/optimize.ts +++ /dev/null @@ -1,30 +0,0 @@ -const replace: (any[] | undefined)[] = [ - ["head > script:nth-child(34)", { src: "" }], - ["head > script:nth-child(43)", { 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; - } - attributes.innerHTML = undefined; - 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/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/index.ts b/src/scripts/optimize/index.ts new file mode 100644 index 0000000..8b63c53 --- /dev/null +++ b/src/scripts/optimize/index.ts @@ -0,0 +1,30 @@ +const replace: (any[] | undefined)[] = [ + ["head > script:nth-child(34)", { src: "" }], + ["head > script:nth-child(43)", { 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}); -- cgit v1.2.3