diff options
| author | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-03-25 09:21:11 +0530 |
|---|---|---|
| committer | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-03-25 09:36:24 +0530 |
| commit | d6682a1ed9acd31dbfdb9e645cc8230c61a268c3 (patch) | |
| tree | 63c5577b701c377896f4aa2985adf67f7aa3d679 | |
| parent | feac7acb91a78b117241abdd0a5d80f778e15f06 (diff) | |
| download | banglar-bhumi-utils-d6682a1ed9acd31dbfdb9e645cc8230c61a268c3.tar.gz banglar-bhumi-utils-d6682a1ed9acd31dbfdb9e645cc8230c61a268c3.zip | |
Disable minification in development.
| -rw-r--r-- | config/webpack.config.js | 3 | ||||
| -rw-r--r-- | config/webpack/plugins/create-manifest-webpack-plugin/index.js | 2 | ||||
| -rw-r--r-- | config/webpack/utils/get-injection-code.js | 2 | ||||
| -rw-r--r-- | package.json | 6 | ||||
| -rw-r--r-- | src/scripts/functionality/application-receipt.ts | 4 | ||||
| -rw-r--r-- | src/scripts/optimize.ts | 8 | ||||
| -rw-r--r-- | src/utils/modify-dom.ts | 32 | ||||
| -rw-r--r-- | src/utils/observe-dom.ts | 4 |
8 files changed, 29 insertions, 32 deletions
diff --git a/config/webpack.config.js b/config/webpack.config.js index 8e27b8a..31d838e 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -53,6 +53,9 @@ module.exports = { } ] }, + optimization: { + minimize: process.env.NODE_ENV === "production" + }, plugins: [ new InjectScriptPlugin(), new CopyPlugin({ diff --git a/config/webpack/plugins/create-manifest-webpack-plugin/index.js b/config/webpack/plugins/create-manifest-webpack-plugin/index.js index 6984955..1940c6e 100644 --- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js +++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js @@ -52,7 +52,7 @@ class CreateManifestPlugin { compilation.emitAsset( "manifest.json", - new sources.RawSource(JSON.stringify(manifest)) + new sources.RawSource(JSON.stringify(manifest, undefined, process.env.NODE_ENV === "production" ? undefined : "\t")) ); } ); diff --git a/config/webpack/utils/get-injection-code.js b/config/webpack/utils/get-injection-code.js index 71afa93..51d1c20 100644 --- a/config/webpack/utils/get-injection-code.js +++ b/config/webpack/utils/get-injection-code.js @@ -19,5 +19,5 @@ module.exports.getInjectionCode = (code, front) => { ? "t.innerHTML=i+t.innerHTML" : "t.innerHTML+=i"; - return `(()=>{let e=new MutationObserver(()=>{let t=document.querySelector("head > script:nth-child(54)");if(t){let i=\`(()=>{${finalCode}})();\`;${concatenationCode},e.disconnect()}});e.observe(document,{childList:!0,subtree:!0})})();`; + return `(()=>{let e=new MutationObserver(()=>{let t=document.querySelector("head > script:nth-child(54)");if(t){let i=\`${finalCode}\`;${concatenationCode},e.disconnect()}});e.observe(document,{childList:!0,subtree:!0})})();`; }; diff --git a/package.json b/package.json index a40aa42..7d613a3 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,9 @@ "author": "Arpit Chakladar", "license": "MIT", "scripts": { - "watch": "webpack watch --config config/webpack.config.js --mode production", - "build": "webpack build --config config/webpack.config.js --mode production", - "build:dev": "webpack build --config config/webpack.config.js --mode development" + "watch": "NODE_ENV=development webpack watch --config config/webpack.config.js", + "build": "NODE_ENV=production webpack build --config config/webpack.config.js", + "build:dev": "NODE_ENV=development webpack build --config config/webpack.config.js" }, "devDependencies": { "@types/chrome": "^0.0.213", diff --git a/src/scripts/functionality/application-receipt.ts b/src/scripts/functionality/application-receipt.ts index 7fdf4d0..878b910 100644 --- a/src/scripts/functionality/application-receipt.ts +++ b/src/scripts/functionality/application-receipt.ts @@ -1,4 +1,4 @@ -const receiptFormElement = document.querySelector("#form_reprint_request") as HTMLElement; +const receiptFormElement = document.getElementById("form_reprint_request") as HTMLElement; receiptFormElement.removeAttribute("id"); receiptFormElement.removeAttribute("name"); receiptFormElement.removeAttribute("onsubmit"); @@ -10,7 +10,7 @@ let captchaElement = document.querySelector("#werter > div > div:nth-child(4)") if (captchaElement) { captchaElement = captchaElement!; - const captchaValueElement = document.querySelector("#captchaText") as HTMLInputElement; + const captchaValueElement = document.getElementById("captchaText") as HTMLInputElement; const captchaFieldElement = document.querySelector("[name=txtDrawText]") as HTMLInputElement; const removeCaptcha = () => { captchaFieldElement.value = captchaValueElement.value; diff --git a/src/scripts/optimize.ts b/src/scripts/optimize.ts index 4acf66f..8389c53 100644 --- a/src/scripts/optimize.ts +++ b/src/scripts/optimize.ts @@ -1,7 +1,7 @@ -import { modifyDOM, DOMModifier } from "@/utils/modify-dom"; +import { modifyDOM } from "@/utils/modify-dom"; modifyDOM([ - new DOMModifier("head > script:nth-child(34)", { src: null }), - new DOMModifier("head > script:nth-child(36)", { src: null, innerHTML: "$.prototype.nivoSlider = () => {};" }), - new DOMModifier("head > script:nth-child(43)", { src: null }) + ["head > script:nth-child(34)", { src: null }], + ["head > script:nth-child(36)", { src: null, innerHTML: "$.prototype.nivoSlider = () => {};" }], + ["head > script:nth-child(43)", { src: null }] ]); diff --git a/src/utils/modify-dom.ts b/src/utils/modify-dom.ts index da0944b..f08f7d9 100644 --- a/src/utils/modify-dom.ts +++ b/src/utils/modify-dom.ts @@ -1,41 +1,35 @@ import { observeDOM } from "@/utils/observe-dom"; -type Replacements = { - [key: string]: string | null +type DOMReplacements = { + innerHTML?: string; + [key: string]: string | undefined | null; }; -export class DOMModifier { - selector: string; - attributes: Replacements; - constructor(selector: string, attributes: Replacements) { - this.selector = selector; - this.attributes = attributes; - } -} +type DOMModificaitonRule = readonly [string, DOMReplacements]; -export const modifyDOM = (elements: (DOMModifier | null)[]) => { +export const modifyDOM = (modificationRules: (DOMModificaitonRule | null)[]) => { let count = 0; observeDOM(() => { - for (let i = 0; i < elements.length; i++) { - if (elements[i]) { - const element = document.querySelector(elements[i]!.selector) as HTMLElement | null; + 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 = elements[i]!.attributes as any; + const attributes = modificationRules[i]![1] as DOMReplacements; if (attributes.innerHTML) { - element.innerHTML = 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]); + element.setAttribute(attribute, attributes[attribute] as string); } } - elements[i] = null; + modificationRules[i] = null; count++; - if (count >= elements.length) { + if (count >= modificationRules.length) { return true; } } diff --git a/src/utils/observe-dom.ts b/src/utils/observe-dom.ts index 8ea1a98..4a447a0 100644 --- a/src/utils/observe-dom.ts +++ b/src/utils/observe-dom.ts @@ -1,11 +1,11 @@ -export const observeDOM = (callback: () => boolean, element: HTMLElement = document as unknown as HTMLElement) => { +export const observeDOM = (callback: () => boolean) => { const observer = new MutationObserver(() => { if (callback()) { observer.disconnect(); } }); - observer.observe(element, { + observer.observe(document, { childList: true, subtree: true }); |
