forked from hamcha/tghandbook
Lazy load all the images
This commit is contained in:
parent
e700bb9c30
commit
389a5b33d0
1 changed files with 6 additions and 1 deletions
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue