Skip to content

Instantly share code, notes, and snippets.

@noromanba
Forked from to/g-lii.user.js
Last active June 20, 2020 23:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save noromanba/d6401655958f3d553589 to your computer and use it in GitHub Desktop.
Save noromanba/d6401655958f3d553589 to your computer and use it in GitHub Desktop.
immediately load images w/ PagerExtention for UserScript
// ==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