Lazy load all the images
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Hamcha 2020-06-21 20:03:41 +02:00
parent e700bb9c30
commit 389a5b33d0
Signed by: hamcha
GPG key ID: 41467804B19A3315

View file

@ -4,7 +4,7 @@ import { findParent } from "./utils";
// This is used for cache busting when userscript changes significantly. // This is used for cache busting when userscript changes significantly.
// Only change it when you made changes to the processHTML part! // 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) { function chemistryFixups(root: HTMLElement) {
// Enable page-specific CSS rules // Enable page-specific CSS rules
@ -147,6 +147,11 @@ export function processHTML(root: HTMLElement, docname: string): void {
header.appendChild(document.createTextNode(docname.replace(/_/g, " "))); header.appendChild(document.createTextNode(docname.replace(/_/g, " ")));
root.insertBefore(header, root.firstChild); root.insertBefore(header, root.firstChild);
// Lazy load all images
root
.querySelectorAll<HTMLImageElement>("img")
.forEach((elem) => elem.setAttribute("loading", "lazy"));
// Remove edit links // Remove edit links
root.querySelectorAll(".mw-editsection").forEach((editLink) => { root.querySelectorAll(".mw-editsection").forEach((editLink) => {
editLink.parentElement.removeChild(editLink); editLink.parentElement.removeChild(editLink);