-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNoLazyLoad.js
100 lines (89 loc) · 3.07 KB
/
NoLazyLoad.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// ==UserScript==
// @name No Lazy Load by X-Force
// @namespace http://www.iplaysoft.com
// @version 0.1.3
// @description Disable images Lazy Load
// @match *://*.jd.com/*
// @match *://*.taobao.com/*
// @match *://*.tmall.com/*
// @match *://*.iapps.im/*
// @match *://*.weixin.qq.com/*
// @match *://blog.sina.com.cn/*
// @downloadURL https://raw.githubusercontent.com/xtremforce/UserScripts/master/NoLazyLoad.js
// @updateURL https://raw.githubusercontent.com/xtremforce/UserScripts/master/NoLazyLoad.js
// @run-at document-end
// @copyright 2012, X-Force
// ==/UserScript==
//removeLazy function from https://gist.github.com/ihsoy-s/
(function() {
// removeLazy
// elm: target element
// attr: attribute that contains real url of the image
function removeLazy(elm, attr) {
if (elm.getAttribute(attr) && elm.src != elm.getAttribute(attr)) {
// copy real url
if (elm.src == "" || elm.src == null) {
elm.src = elm.getAttribute(attr);
} else {
//没有 src 标签的时候要用 setAttribute
elm.setAttribute("src", elm.getAttribute(attr));
}
//
// remove original attribute
elm.removeAttribute(attr);
// debug message
console.debug("[Remove Lazy-load]: ", elm.src);
}
}
function removeLazyloadProcess(img) {
var url = window.location.href;
if (url.indexOf(".jd.com/") != -1) {
removeLazy(img, "data-lazyload"); //京东
return;
}
if (url.indexOf(".taobao.com/") != -1 || url.indexOf(".tmall.com/") != -1) {
removeLazy(img, "data-ks-lazyload");
return;
}
if (url.indexOf(".weixin.qq.com/") != -1) {
removeLazy(img, "data-src"); //微信
return;
}
//sina_blog
if (url.indexOf("://blog.sina.com.cn/") != -1) {
removeLazy(img, "data-thumb");
return;
}
//通用
removeLazy(img, "data-lazy-src");
removeLazy(img, "data-original");
}
// replaceLazyload
// doc: target
function replaceLazyload(doc) {
var img = doc.images;
var i;
if (img != undefined) {
for (i = 0; i < img.length; i++) {
// execute removeLazy function for each lazyload attributes
removeLazyloadProcess(img[i]);
}
}
}
// event
function getEvent(evt) {
//
var st = evt.target.innerHTML;
if (st != null) {
evt.target.innerHTML = st.replace('data-lazyload', 'src');
}
// console.debug(node.innerHTML);
//console.debug("[Replace Lazy-load] Get event:", evt.detail);
//replaceLazyload(node);
}
// exec
replaceLazyload(document);
// exec if AutoPagerize was called
document.body.addEventListener('DOMNodeInserted', getEvent, false);
//document.body.addEventListener('AutoPagerize_DOMNodeInserted', getEvent, false);
}());