From 1caecf35a2d0ee81cedea40ccbd4ad4150bca2f8 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Fri, 10 Feb 2023 11:59:32 +0530 Subject: Some minor changes. --- package.json | 3 +-- src/scripts.json | 2 +- src/scripts/block-unnecessary.ts | 36 ------------------------------------ src/scripts/optimize.ts | 30 ++++++++++++++++++++++++++++++ yarn.lock | 5 ----- 5 files changed, 32 insertions(+), 44 deletions(-) delete mode 100644 src/scripts/block-unnecessary.ts create mode 100644 src/scripts/optimize.ts diff --git a/package.json b/package.json index 7b0fb5f..2085ef6 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ "ts-loader": "^9.4.2", "typescript": "^4.9.5", "webpack": "^5.75.0", - "webpack-cli": "^5.0.1", - "webpack-virtual-modules": "^0.5.0" + "webpack-cli": "^5.0.1" } } diff --git a/src/scripts.json b/src/scripts.json index 8e8d0bd..ee042b2 100644 --- a/src/scripts.json +++ b/src/scripts.json @@ -1,6 +1,6 @@ { "before": { - "block-unnecessary.ts": "*" + "optimize.ts": "*" }, "injected": { "stop-blocking.js": "*" diff --git a/src/scripts/block-unnecessary.ts b/src/scripts/block-unnecessary.ts deleted file mode 100644 index 65d610a..0000000 --- a/src/scripts/block-unnecessary.ts +++ /dev/null @@ -1,36 +0,0 @@ -let replace: (any[] | undefined)[] = [ - ["head > script:nth-child(34)", { src: "" }], - ["head > script:nth-child(35)", { src: "https://code.jquery.com/jquery-1.12.4.min.js", crossorigin: "anonymous" }], - ["head > script:nth-child(43)", { src: "" }] -]; -let count = 0; -let notDone = true; - -const observer = new MutationObserver(() => { - if (notDone) { - const meta = document.querySelector("head > meta:nth-child(2)"); - if (meta) { - meta.setAttribute("http-equiv", "Content-Security-Policy"); - meta.setAttribute("content", "default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"); - notDone = false; - } - } - 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]; - 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.ts new file mode 100644 index 0000000..3994333 --- /dev/null +++ b/src/scripts/optimize.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; + } + 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/yarn.lock b/yarn.lock index 1f6f21a..6179dc9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1057,11 +1057,6 @@ webpack-sources@^3.2.3: resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde" integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== -webpack-virtual-modules@^0.5.0: - version "0.5.0" - resolved "https://registry.yarnpkg.com/webpack-virtual-modules/-/webpack-virtual-modules-0.5.0.tgz#362f14738a56dae107937ab98ea7062e8bdd3b6c" - integrity sha512-kyDivFZ7ZM0BVOUteVbDFhlRt7Ah/CSPwJdi8hBpkK7QLumUqdLtVfm/PX/hkcnrvr0i77fO5+TjZ94Pe+C9iw== - webpack@^5.75.0: version "5.75.0" resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.75.0.tgz#1e440468647b2505860e94c9ff3e44d5b582c152" -- cgit v1.2.3