-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_imgur.html
153 lines (134 loc) · 4.14 KB
/
random_imgur.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title id="titleprogress">Random Imgur Wall</title>
<style type="text/css">
body {color:white;font-family:sans-serif;background-color:black;}
span#current{font-family:monospace}
img{height:200px;max-width:600px;border:1px solid #000;}
img:hover {border:1px solid #fff;}
a{color:#fff;}
</style>
<script type="text/javascript">
var bodyWidth = GetWidth();
var imageWidth = Math.floor((bodyWidth-5)/6);
var numCols = Math.floor(bodyWidth/imageWidth);
var columns = Array();
for (i=0; i<numCols; i++)
{
columns[i] = 200;
}
var totalCounter = 0;
var threads = 0;
var syncloc = 0;
function GetWidth()
{
var x = 0;
if (self.innerHeight)
{
x = self.innerWidth;
}
else if (document.documentElement && document.documentElement.clientHeight)
{
x = document.documentElement.clientWidth;
}
else if (document.body)
{
x = document.body.clientWidth;
}
return x;
};
function randomString(string_length)
{
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var output = "";
var index;
for (var i = 0; i < string_length; i++)
{
var index = Math.floor(Math.random() * chars.length);
output += chars.substring(index, index + 1);
}
document.getElementById("current").innerHTML = output;
return output;
};
function creatediv(id, html) {
var newdiv = document.createElement('div');
newdiv.setAttribute('id', id);
newdiv.innerHTML = html;
newdiv.style.display = "inline";
//newdiv.style.position = "absolute";
document.body.appendChild(newdiv);
return newdiv;
} ;
function getLowestIndex() {
var proc = false;
while (!proc) {
if (syncloc == 0) {
syncloc = 1;
var lowestIndex = 0;
var lowestDepth = columns[0];
for (var i = 1; i < numCols; i++)
{
if (columns[i] < lowestDepth) {
lowestDepth = columns[i];
lowestIndex = i;
}
}
syncloc = 0;
return lowestIndex;
}
}
};
function loadImages()
{
if (totalCounter < 10) {
scroll(0, 0);
document.getElementById('p').value = totalCounter;
document.getElementById('titleprogress').innerHTML= '('+totalCounter+'/10) '+'Random Imgur Wall';
if (threads < 10) {
setTimeout(function() { loadImages();},100);
var imgObject = new Image();
imgObject.onload = function()
{
if (this.width == 161 && this.height == 81)
{
var randStr = randomString(7);
this.src = "http://i.imgur.com/" + randStr + ".jpg";
} else {
var randStr = randomString(7);
var imgurl = imgObject.src.replace("http://i.", "http://");
var imgurl = imgurl.replace(".jpg", "");
var newdiv = creatediv(randStr, "<a target=\"_blank\" href=\"" + imgurl + "\"><img src=\"" + imgObject.src + "\" /></a>");
var lowestIndex = getLowestIndex();
columns[lowestIndex] += Math.floor(Math.min((imgObject.height * (1 / (imgObject.width / imageWidth))),imageWidth));
newdiv.style.left = (lowestIndex) * imageWidth;
newdiv.style.top = columns[lowestIndex] - Math.floor(Math.min((imgObject.height * (1 / (imgObject.width / imageWidth))),imageWidth));
threads--;
totalCounter++;
setTimeout(function() { loadImages();},100);
}
}
imgObject.src = "http://i.imgur.com/" + randomString(7) + ".jpg";
threads++;
}
} else {
document.getElementById("dots").innerHTML = 'Done!';
document.getElementById('titleprogress').innerHTML= '(done) Random Imgur Wall';
for (var i = 0; i < numCols; i++)
{
var lowestIndex = i;
columns[lowestIndex] += 300;
newdiv.style.left = (lowestIndex) * imageWidth;
newdiv.style.top = columns[lowestIndex] - 300;
}
}
};
</script>
<body onLoad="loadImages();">
<h1>Random Imgur Wall</h1>
<p>Warning: the script "bruteforces" Imgur for totally random pictures. May include offensive content. <a href="#" onClick="window.location.reload();return false;">→reload←</a></p>
<div id="dots">Finding 10 images, need a few minutes. [<span id="current"></span>] <progress id='p' value='0' max="10"></progress>
</div>
</body>
</html>