-
-
Save dlwr/39f87b3f07229c7d5ce9 to your computer and use it in GitHub Desktop.
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 immediately load images w/ PagerExtention for UserScript | |
// @include http://gigazine.net/* | |
// @include http://www.moae.jp/comic/* | |
// @include http://omocoro.jp/* | |
// @include http://rocketnews24.com/* | |
// @grant none | |
// @run-at document-end | |
// @version 2014.10.23 | |
// @homepage https://gist.github.com/dlwr/39f87b3f07229c7d5ce9 | |
// @downloadURL https://gist.github.com/dlwr/39f87b3f07229c7d5ce9/raw/g-lii.user.js | |
// @contributor to https://gist.github.com/to/5334394 | |
// @contributor noromanba https://gist.github.com/noromanba/d6401655958f3d553589 | |
// @org-license Unknown (as-is) | |
// @author dlwr | |
// @license TBD (as-is) | |
// @icon http://upload.wikimedia.org/wikipedia/commons/thumb/6/6b/Toilet_paper_roll_revisited.svg/32px-Toilet_paper_roll_revisited.svg.png | |
// @icon64 http://upload.wikimedia.org/wikipedia/commons/thumb/6/6b/Toilet_paper_roll_revisited.svg/64px-Toilet_paper_roll_revisited.svg.png | |
// ==/UserScript== | |
// Icon (CC0 by PeterM) | |
// http://commons.wikimedia.org/wiki/File:Toilet_paper_roll_revisited.svg | |
(function() { | |
// c.f. jQuery.lazyload | |
// http://www.appelsiini.net/projects/lazyload | |
// https://github.com/tuupola/jquery_lazyload | |
var loadImmediate = function(ctx) { | |
function immediate(img) { | |
img.src = | |
img.dataset.original ? img.dataset.original : | |
img.dataset.src ? img.dataset.src : | |
img.dataset.lazySrc ? img.dataset.lazySrc : | |
img.src; | |
} | |
ctx = ctx || document; | |
if (typeof (ctx.querySelectorAll) !== "undefined") { | |
if (ctx.nodeName === "IMG") { | |
immediate(ctx); | |
} else { | |
Array.prototype.forEach.call(ctx.querySelectorAll('img'), function(img) { | |
immediate(img); | |
}); | |
} | |
} | |
}; | |
loadImmediate(); | |
// c.f. MutationObserver | |
// https://developer.mozilla.org/ja/docs/Web/API/MutationObserver | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
for (var i = 0; i < mutation.addedNodes.length; i++) { | |
loadImmediate(mutation.addedNodes[i]); | |
} | |
}); | |
}); | |
observer.observe(document, {childList: true, subtree: true}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@dlwr MutationObserver:cupid: img handling:metal: nice hacks! :+1: