From 389a5b33d0c6db00bc0e8b1c4fa39ba4d831a348 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Sun, 21 Jun 2020 20:03:41 +0200 Subject: [PATCH] Lazy load all the images --- src/userscript.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/userscript.ts b/src/userscript.ts index b6d74c6..8b61c8d 100644 --- a/src/userscript.ts +++ b/src/userscript.ts @@ -4,7 +4,7 @@ import { findParent } from "./utils"; // This is used for cache busting when userscript changes significantly. // Only change it when you made changes to the processHTML part! -export const CURRENT_VERSION = "df914edcb5522670309ceb8dfd0195dc70fb81d4"; +export const CURRENT_VERSION = "e700bb9c309627b944618152a7d8e936ae7a05db"; function chemistryFixups(root: HTMLElement) { // Enable page-specific CSS rules @@ -147,6 +147,11 @@ export function processHTML(root: HTMLElement, docname: string): void { header.appendChild(document.createTextNode(docname.replace(/_/g, " "))); root.insertBefore(header, root.firstChild); + // Lazy load all images + root + .querySelectorAll("img") + .forEach((elem) => elem.setAttribute("loading", "lazy")); + // Remove edit links root.querySelectorAll(".mw-editsection").forEach((editLink) => { editLink.parentElement.removeChild(editLink);