diff soranews-image.user.js @ 117:d9dc190bccaf

Undo combining fixes into single script per site
author nanaya <me@nanaya.net>
date Sun, 15 Jan 2023 23:49:35 +0900
parents ef21ef445fc6
children 8de2d53a4cb1
line wrap: on
line diff
--- a/soranews-image.user.js	Sun Jan 15 23:46:56 2023 +0900
+++ b/soranews-image.user.js	Sun Jan 15 23:49:35 2023 +0900
@@ -11,47 +11,43 @@
 
 'use strict';
 
-function unlazy () {
-  const fix = function (image) {
-    // basic sanity check
-    if (!image.classList.contains('lazy')) {
-      return;
-    }
+const fix = function (image) {
+  // basic sanity check
+  if (!image.classList.contains('lazy')) {
+    return;
+  }
 
-    image.classList.remove('lazy');
-    image.removeAttribute('src');
-    image.setAttribute('srcset', image.dataset.scoSrcset);
-  };
+  image.classList.remove('lazy');
+  image.removeAttribute('src');
+  image.setAttribute('srcset', image.dataset.scoSrcset);
+};
 
-  // loop through passed nodes (or body if called without arguments)
-  const run = function (nodes) {
-    if (nodes == null) {
-      nodes = [document.body];
-    }
-
-    for (let i = 0; i < nodes.length; i++) {
-      // find all the images inside (and self)
-      const images = [nodes[i], ...nodes[i].querySelectorAll('.lazy')];
+// loop through passed nodes (or body if called without arguments)
+const run = function (nodes) {
+  if (nodes == null) {
+    nodes = [document.body];
+  }
 
-      for (let j = 0; j < images.length; j++) {
-        fix(images[j]);
-      }
-    }
-  };
+  for (let i = 0; i < nodes.length; i++) {
+    // find all the images inside (and self)
+    const images = [nodes[i], ...nodes[i].querySelectorAll('.lazy')];
 
-  const onMutate = function (mutations) {
-    for (const mutation in mutations) {
-      run(mutation.addedNodes);
+    for (let j = 0; j < images.length; j++) {
+      fix(images[j]);
     }
-  };
-
-  // the observer
-  const observer = new window.MutationObserver(onMutate);
+  }
+};
 
-  // start the observer
-  observer.observe(document, { childList: true, subtree: true });
-  // initial run on existing document
-  run();
-}
+const onMutate = function (mutations) {
+  for (const mutation in mutations) {
+    run(mutation.addedNodes);
+  }
+};
 
-unlazy();
+// the observer
+const observer = new window.MutationObserver(onMutate);
+
+// start the observer
+observer.observe(document, { childList: true, subtree: true });
+// initial run on existing document
+run();