Skip to content

Commit

Permalink
noLazyImageLoad.user.js 版本 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ywzhaiqi committed Sep 17, 2014
1 parent e1d5b1e commit 486c5a6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NoLazyImageLoad/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
noLazyImageLoad.user.js
=======================

取消图片的延迟加载 。参考 [nolazyload](https://greasyfork.org/scripts/791-nolazyload)
54 changes: 54 additions & 0 deletions NoLazyImageLoad/noLazyImageLoad.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// ==UserScript==
// @name No Lazy Image load
// @namespace https://github.com/ywzhaiqi/
// @version 0.1
// @description 取消图片的延迟加载
// @include http*
// @grant none
// ==/UserScript==

var lazyAttributes = [
"zoomfile", "file", "original", "load-src", "_src", "imgsrc", "real_src", "src2", "origin-src",
"data-lazyload", "data-lazyload-src", "data-lazy-load-src",
"data-ks-lazyload", "data-ks-lazyload-custom",
"data-src", "data-defer-src", "data-actualsrc",
"data-cover", "data-original", "data-thumb", "data-imageurl", "data-placeholder",
];

function noLazyNode(node) {
if (node.localName != 'img') return;

lazyAttributes.some(function(attr) {
if (!node.hasAttribute(attr)) return;

var newSrc = node.getAttribute(attr);
if (node.src != newSrc) {
node.src = newSrc;
}
return true;
});
}

function addMutationObserver(selector, callback) {
var watch = document.querySelector(selector);
if (!watch) return;

var observer = new MutationObserver(function(mutations){
mutations.forEach(function(x) {
if (x.addedNodes.length) {
callback(x.addedNodes);
}
});
});
observer.observe(watch, {childList: true, subtree: true});
}

function run() {
[].map.call(document.images, noLazyNode);

addMutationObserver('body', function(addedNodes) {
[].map.call(addedNodes, noLazyNode)
});
}

run();

0 comments on commit 486c5a6

Please sign in to comment.