aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/webpack/loaders/scoped-loader.js2
-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
4 files changed, 34 insertions, 3 deletions
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/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]);
}