view melonbooks-unlazy.user.js @ 98:3e5f1fa9ed52

Skip redundant class check and add dataset check instead
author nanaya <me@nanaya.net>
date Fri, 23 Dec 2022 19:58:14 +0900
parents c8f9350c5307
children b44d5cb661c5
line wrap: on
line source

// ==UserScript==
// @name        melonbooks unlazy
// @namespace   https://nanaya.net
// @match       https://www.melonbooks.co.jp/*
// @grant       none
// @run-at      document-start
// @version     1.0.2
// @author      nanaya
// @description replace lazy loaded images with just images
// @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/melonbooks-unlazy.user.js
// ==/UserScript==

'use strict'

function fix (image) {
  const src = image.dataset.src

  if (src == null) return

  image.classList.remove('lazyload')
  image.src = image.dataset.src
  delete image.dataset.src
}

function onMutate (mutations) {
  for (const mutation of mutations) {
    for (const node of mutation.addedNodes) {
      if (node instanceof window.HTMLElement) {
        for (const image of node.querySelectorAll('.lazyload')) {
          fix(image)
        }
      }
    }
  }
}

const observer = new window.MutationObserver(onMutate)
observer.observe(document, { childList: true, subtree: true })