-
Notifications
You must be signed in to change notification settings - Fork 25
/
imgur_a.js
63 lines (57 loc) · 1.75 KB
/
imgur_a.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
// Copyright (c) 2010 Romain Vallet
// Licensed under the MIT license, read license.txt
var hoverZoomPlugins = hoverZoomPlugins || [];
hoverZoomPlugins.push( {
name: 'Imgur',
version: '0.2',
prepareImgLinks: function(callback) {
var res = [],
minSplitLength = 4;
function prepareImgLink() {
var link = $(this);
if (link.data('hoverZoomSrc')) { return; }
var aHref = link.attr('href').split('/');
if (aHref.length < minSplitLength) { return; }
var excl = ['delete', 'forum', 'removalrequest', 'contact', 'upgrade', 'tools', 'stats', 'logout', 'signin', 'register', 'blog'];
if (excl.indexOf(aHref[minSplitLength - 1]) > -1) { return; }
var hash = '';
try {
while (!hash) {
hash = aHref.pop().trim();
}
} catch(e) {}
if (aHref.length < minSplitLength - 1 || hash.length < 5) { return; }
var i = hash.indexOf('?');
if (i > -1) {
hash = hash.substr(0, i);
}
i = hash.indexOf('&');
if (i > -1) {
hash = hash.substr(0, i);
}
excl.push('gallery');
if (excl.indexOf(hash) > -1) { return; }
i = hash.indexOf('/');
if (i > -1) {
hash = hash.substr(0, i);
}
var srcs;
if (hash.indexOf('.') == -1) {
var url = 'http://i.imgur.com/' + hash;
srcs = [url + '.jpg', url + '.png', url + '.gif'];
} else {
srcs = ['http://i.imgur.com/' + hash];
}
link.data('hoverZoomSrc', srcs);
res.push(link);
}
// Every sites
$('a[href*=//imgur.com/], a[href*=//i.imgur.com/]').each(prepareImgLink);
// On imgur.com (galleries, etc)
if (window.location.host.indexOf('imgur.com') > -1) {
minSplitLength = 2;
$('a[href^=/]').each(prepareImgLink);
}
if (res.length) { callback($(res)); }
}
});