forked from ywzhaiqi/userscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PanLinkCheck.user.js
299 lines (263 loc) · 11.9 KB
/
PanLinkCheck.user.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// ==UserScript==
// @name PanLinkCheck 网盘死链检查
// @namespace http://jixun.org/
// @version 1.0.0.4
// @description 浏览网页的时候检查死链
// @include http://www.jebook.org/bbs/*
// @copyright 2012+, Jixun
// @run-at document-start
// @grant GM_xmlhttpRequest
// @note 自用修改版,2014-5-27,https://greasyfork.org/scripts/1262
// ==/UserScript==
(function () {
var $$ = {
styleAdded: false
};
// 常量定义
var arrMarks = ['live', 'dead', 'unk', 'lock'],
__FILE_WORKING = 0,
__FILE_NOT_EXIST = 1,
__FILE_UNKNOWN = 2,
__FILE_LOCKED = 3;
function parseHTML (responseText) {
// For Firefox
var ret = (new DOMParser()).parseFromString(responseText, "text/html");
// For Chrome
if (ret == undefined) {
var ret = document.implementation.createHTMLDocument("");
ret.querySelector('html').innerHTML = responseText;
}
return ret;
}
var addressToCheck = [
{ // 百度盘
urlSyntax: /^(pan|yun)\.baidu\.com\/((share\/(link|init)|netdisk\/singlepublic)\?|s\/)/i,
// checkFunc: 回调函数, 检查指定的链接内容. 4 个参数 (返回的网页内容, DOM 数据[当成 Document 来用就是], 完整链接, 链接元素)
checkFunc: function (responseText, parsedDomContent, sFullLink, oElement) {
var typeCode = (parsedDomContent.querySelector('p.share-frm-lbl') ? __FILE_WORKING : // 正常
(parsedDomContent.querySelector('dl.pickpw') ? __FILE_LOCKED : // 上锁
(parsedDomContent.querySelector('div#share_nofound_des') ? __FILE_NOT_EXIST : // 不存在
__FILE_UNKNOWN))); // 未知状态
// console.log (parsedDomContent.querySelector('p.share-frm-lbl, dl.pickpw, div#share_nofound_des'));
// 标记链接
generalMarkLink (typeCode, oElement);
// 告诉框架: 我已经自己处理完了
return true;
}
},
{ // 360云盘(有效文件的检查未完成)
urlSyntax: /^[^\/]*yunpan\.cn\/(?:lk|link\/data)?\/?[a-z0-9]+$/i,
checkFunc: function(r, d, f, e) {
var isDeadLink = function() {
if (d.querySelector('div#linkError')) {
return true;
}
var tip = d.querySelector('#doc .tip');
if (tip) {
return tip.textContent.indexOf('页面不存在') != -1
}
};
var typeCode = (d.querySelector('strong.strong_from_name') ? __FILE_WORKING :
(d.querySelector('div#extract-panel') ? __FILE_LOCKED :
( isDeadLink() ? __FILE_NOT_EXIST :
__FILE_UNKNOWN)));
generalMarkLink (typeCode, e);
return true;
}
},
{ // 快船
urlSyntax: /^kuai\.xunlei\.com\/d(s|)\//i,
checkFunc: function (r, d, f, e) {
var typeCode = (d.querySelector('strong.strong_from_name') ? __FILE_WORKING :
(d.querySelector('div.restriction_msg_y') ? __FILE_LOCKED :
(d.querySelector('div.z_no_result') ? __FILE_NOT_EXIST :
__FILE_UNKNOWN)));
generalMarkLink (typeCode, e);
return true;
}
},
{ // HowFile
urlSyntax: /^howfile\.com\/file\//i,
checkFunc: function (r, d, f, e) {
var typeCode = (d.querySelector('div#floatdiv') ? __FILE_WORKING :
(d.querySelector('div.message_div') ? __FILE_NOT_EXIST :
__FILE_UNKNOWN));
generalMarkLink (typeCode, e);
return true;
}
},
{ // Kuaipan
urlSyntax: /^kuaipan(\.com|)\.cn\/file\/id_/i,
checkFunc: function (r, d, f, e) {
var typeCode = (d.querySelector('#errorContaier') ? __FILE_NOT_EXIST :
d.querySelector ('#pwdContaier') ? __FILE_LOCKED :
d.querySelector ('a.download') ? __FILE_WORKING :
__FILE_UNKNOWN);
generalMarkLink (typeCode, e);
return true;
}
},
{ // 飞速盘
urlSyntax: /^rayfile\.com\/([^\/]+?)\/files\//i,
checkFunc: function (r, d, f, e) {
var typeCode = (d.querySelector('div.mid div.wj h1') ? __FILE_WORKING :
__FILE_NOT_EXIST);
generalMarkLink (typeCode, e);
return true;
}
},
{ // 115
urlSyntax: /^115\.com\/file\//i,
checkFunc: function (r, d, f, e) {
var typeCode = (d.querySelector('.file-info') ? __FILE_WORKING :
__FILE_NOT_EXIST);
generalMarkLink (typeCode, e);
return true;
}
},
{ // Yunfile
urlSyntax: /^yunfile\.com\/file\//i,
checkFunc: function (r, d, f, e) {
var typeCode = (d.querySelector('div.downpage h2.title') ? __FILE_WORKING :
__FILE_UNKNOWN);
generalMarkLink (typeCode, e);
return true;
}
}
];
// 图像设定
var pngData = [
'iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAYAAABy6+R8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAAL'+
'EwEAmpwYAAAAB3RJTUUH2AMJCQY36Sc4vgAAAlRJREFUeNpV0r9PE3EABfD3veu1lJYr15ZCoBHBqJBAMEbjL0hY'+
'FAkyOAmJMUYd/Q+cXF1wYPQPILppYkKIRARiMDGoaAKimBaKHMWDXnu93venE0Tf9Ib3tg/BP7m3NGgwxtKcM4vy'+
'IKSk4BBqn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'mJ9JP3+RuXK+c/gmAPxGhfbLln2VyQDIRvVhuwU6B9fNQ5CNreZ3gGwwxeH3aZ8TCJwKBoO3LMvitSxeFlDLANmA'+
'tgHK4Vp/PZjy6Dx5HyAP0AJMBkASgMYfCUBLgHIAnStCKIedFSnAKACKwNoASIBJgjcFeFmAcoC2weQinS1A6GWw'+
'V3RlEoCWKwmwDuAtAeoLWP8AiACSONs4DtYCrFYAWqyAygBGp7Y8W0hXCdZVABedmAWgBabmBcCiCGABK1M5YVlP'+
'N976X+oXHmgjHsxZeGIAAAAASUVORK5CYII'
];
function addMyStyle () {
$$.styleAdded = true;
var eStyle = document.createElement ('style');
arrMarks.forEach (function (e, i) {
eStyle.innerHTML += 'span.linkcheck_' + e + ' {background:transparent url(data:image/png;base64,'
+ pngData[i] + ') no-repeat 0 50%; padding-left:18px}';
});
document.body.appendChild (eStyle);
}
function generalMarkLink (marker, element, sAdditonalText, bTextAsHTML) {
var sMarker, nElement = document.createElement('span');
if (typeof(marker) == 'string'){
sMarker = marker;
} else {
// 按照序号标记
try {
sMarker = arrMarks [marker];
} catch (err) {
sMarker = 'unk';
}
}
if (sAdditonalText) {
if (bTextAsHTML)
nElement.innerHTML = sAdditonalText;
else
nElement.textContent = sAdditonalText;
}
nElement.className = 'linkcheck_' + sMarker;
element.parentNode.insertBefore (nElement, element);
console.log ('Marking', element, 'as', sMarker);
}
function main () {
var links = document.links;
var arrLink = [].filter.call(links, function(link) {
var url = link.getAttribute ('href'),
fullUrl = link.href;
return !link.hasAttribute('thisLinkChecked')
&& fullUrl.substr(0, 4).toLowerCase() == 'http'
&& url.trim().substr(0,1) != '#'
&& url.trim().substr(0,11) != 'javascript:'
&& url.replace(/\s/g, '') != ''
});
arrLink.forEach (function (e) {
var bSkip = false,
sCurLink = (e.href.match(/\:\/\/(.+)/)[1]).replace(/^www\./, '');
if (e.hasAttribute('thisLinkChecked'))
return;
addressToCheck.forEach (function (o) {
if (bSkip || !o.urlSyntax.test(sCurLink))
return;
console.log ('Checking link:', e.getAttribute ('href'));
e.setAttribute ('thisLinkChecked', 0);
bSkip = true;
GM_xmlhttpRequest ({
method: 'GET',
url: e.href,
onload: function (r) {
// 转交相应处理函数
var ret = o.checkFunc (r.responseText, parseHTML(r.responseText),
sCurLink, e);
// 已经添加标记
if (ret === true)
return;
// 标记
generalMarkLink (ret, e);
},
onerror: function () {
// 提示网页无法读取
generalMarkLink (2, e);
}
})
});
});
}
addEventListener ('DOMContentLoaded', function () {
// 添加样式表
if (!$$.styleAdded)
addMyStyle ();
main ();
var observer = new MutationObserver(function(mutations) {
// console.log('1111')
main ();
});
observer.observe(document.body, {
childList: true,
subtree: true,
characterData: true
});
}, false);
})();