diff soranews-image.user.js @ 85:9c8cde985caf

Update standard and fix
author nanaya <me@nanaya.pro>
date Thu, 15 Apr 2021 15:01:22 +0900
parents af4f8b25495e
children 2c4470b73ad9
line wrap: on
line diff
--- a/soranews-image.user.js	Thu Apr 15 14:56:23 2021 +0900
+++ b/soranews-image.user.js	Thu Apr 15 15:01:22 2021 +0900
@@ -12,23 +12,7 @@
 ;(function () {
   'use strict'
 
-  // loop through passed nodes (or body if called without arguments)
-  var run = function (nodes) {
-    if (nodes == null) {
-      nodes = [document.body]
-    }
-
-    for (var i = 0; i < nodes.length; i++) {
-      // find all the images inside (and self)
-      var images = [nodes[i], ...nodes[i].querySelectorAll('.lazy')]
-
-      for (var j = 0; j < images.length; j++) {
-        fix(images[j])
-      }
-    }
-  }
-
-  var fix = function (image) {
+  const fix = function (image) {
     // basic sanity check
     if (!image.classList.contains('lazy')) {
       return
@@ -39,14 +23,30 @@
     image.setAttribute('srcset', image.dataset.scoSrcset)
   }
 
-  var onMutate = function (mutations) {
-    for (var mutation in mutations) {
+  // 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')]
+
+      for (let j = 0; j < images.length; j++) {
+        fix(images[j])
+      }
+    }
+  }
+
+  const onMutate = function (mutations) {
+    for (const mutation in mutations) {
       run(mutation.addedNodes)
     }
   }
 
   // the observer
-  var observer = new window.MutationObserver(onMutate)
+  const observer = new window.MutationObserver(onMutate)
 
   // start the observer
   observer.observe(document, { childList: true, subtree: true })