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. --- src/scripts.json | 2 +- src/scripts/block-unnecessary.ts | 36 ------------------------------------ src/scripts/optimize.ts | 30 ++++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 37 deletions(-) delete mode 100644 src/scripts/block-unnecessary.ts create mode 100644 src/scripts/optimize.ts (limited to 'src') 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}); -- cgit v1.2.3