-
-
Save noromanba/d6401655958f3d553589 to your computer and use it in GitHub Desktop.
immediately load images w/ PagerExtention for UserScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Load Image Immediately | |
// @namespace http://noromanba.flavors.me | |
// @description images immediately load w/ PagerExtention for UserScript | |
// @include *://gigazine.net/* | |
// @include *://www.moae.jp/comic/* | |
// @include *://omocoro.jp/* | |
// @include *://rocketnews24.com/* | |
// @grant none | |
// @noframes | |
// @run-at document-end | |
// @version 2017.3.10.0 | |
// @homepage https://gist.github.com/noromanba/d6401655958f3d553589 | |
// @downloadURL https://gist.github.com/noromanba/d6401655958f3d553589/raw/g-lii.user.js | |
// @contributor to https://gist.github.com/to/5334394 | |
// @contributor dlwr https://gist.github.com/dlwr/39f87b3f07229c7d5ce9 | |
// @org-license Unknown (as-is) | |
// @license TBD (as-is) | |
// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/6/6b/Toilet_paper_roll_revisited.svg/128px-Toilet_paper_roll_revisited.svg.png | |
// ==/UserScript== | |
// Icon (CC0 by PeterM) | |
// https://commons.wikimedia.org/wiki/File%3AToilet_paper_roll_revisited.svg | |
// Devel | |
// https://gist.github.com/noromanba/d6401655958f3d553589 | |
(() => { | |
// c.f. jQuery.lazyload | |
// https://www.appelsiini.net/projects/lazyload | |
// https://github.com/tuupola/jquery_lazyload | |
const immediate = (img) => { | |
img.src = | |
img.dataset.original || | |
img.dataset.src || | |
img.dataset.lazySrc || | |
img.src; | |
}; | |
const loadImmediate = (ctx = document.body) => { | |
if (!ctx.querySelectorAll) return; | |
if (ctx.nodeName.toLowerCase() === 'img') { | |
immediate(ctx); | |
} else { | |
Array.from(ctx.querySelectorAll('img'), img => { | |
immediate(img); | |
}); | |
} | |
}; | |
loadImmediate(document.body); | |
new MutationObserver(records => { | |
records.forEach(record => { | |
// TBD omit addedNodes | |
Array.from(record.addedNodes, node => { | |
loadImmediate(node); | |
}); | |
}); | |
}).observe(document.body, { childList: true, subtree: true }); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment