Mercurial > ec-userscripts
diff pixiv-fanbox-unlazy.user.js @ 85:9c8cde985caf
Update standard and fix
author | nanaya <me@nanaya.pro> |
---|---|
date | Thu, 15 Apr 2021 15:01:22 +0900 |
parents | 86da34e62d29 |
children | 74c33632c353 |
line wrap: on
line diff
--- a/pixiv-fanbox-unlazy.user.js Thu Apr 15 14:56:23 2021 +0900 +++ b/pixiv-fanbox-unlazy.user.js Thu Apr 15 15:01:22 2021 +0900 @@ -12,29 +12,10 @@ ;(function () { 'use strict' - var imageUrlPrefix = 'https://downloads.fanbox.cc/images/post/' - - // 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++) { - // first try fixing itself - fix(nodes[i]) + const imageUrlPrefix = 'https://downloads.fanbox.cc/images/post/' - // and then find all the links inside - var links = nodes[i].querySelectorAll(`[href^="${imageUrlPrefix}"]`) - - for (var j = 0; j < links.length; j++) { - fix(links[j]) - } - } - } - - var fix = function (link) { - var href = link.href + const fix = function (link) { + const href = link.href // basic sanity check if (typeof href !== 'string' || !href.startsWith(imageUrlPrefix)) { @@ -53,14 +34,33 @@ link.innerHTML = `<img style="width: 100%;" src="${href}" />` } - var onMutate = function (mutations) { - for (var mutation in mutations) { + const onMutate = function (mutations) { + for (const mutation in mutations) { run(mutation.addedNodes) } } + // 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++) { + // first try fixing itself + fix(nodes[i]) + + // and then find all the links inside + const links = nodes[i].querySelectorAll(`[href^="${imageUrlPrefix}"]`) + + for (let j = 0; j < links.length; j++) { + fix(links[j]) + } + } + } + // the observer - var observer = new window.MutationObserver(onMutate) + const observer = new window.MutationObserver(onMutate) // start the observer observer.observe(document, { childList: true, subtree: true })