-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
300 lines (269 loc) · 8.68 KB
/
Copy pathindex.html
File metadata and controls
300 lines (269 loc) · 8.68 KB
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
300
<!DOCTYPE HTML>
<!--
Created by Pierce Zaifman
GrowingCoder.com
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PPTK Generator</title>
<link rel="stylesheet" href="./css/style.css" type="text/css" media="screen" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" type="text/css" media="screen" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var allPosts = new Array();
var normalPosts = new Array();
//Initialization
$(document).ready(function() {
$("#image-container").hide();
$('#generate-button').click(function() {
generatePPTK();
});
});
function generatePPTK() {
allPosts = new Array();
$.mobile.loading( "show", {
text: "",
textVisible: false,
theme: "a",
html: ""
});
allPosts = new Array();
normalPosts = new Array();
var normalURL = "http://www.reddit.com/r/pics/hot/.json?limit=100&jsonp=?";
$.getJSON(normalURL,
function(json) {
var posts = json.data.children;
normalPosts.push.apply(normalPosts, posts);
var funnyURL = "http://www.reddit.com/r/funny/hot/.json?limit=100&jsonp=?";
downloadImages(funnyURL, 0, 2, "");
}
).fail(function(xhr, status, text) {
$.mobile.loading("hide");
alert("An error has occurred, please try again later.");
});
}
function downloadImages(url, counter, extraPages, urlExtension) {
$.getJSON(url + urlExtension,
function(json) {
var posts = json.data.children;
var funnyURLExtension = "&after=" + posts[posts.length - 1].data.name;
allPosts.push.apply(allPosts, posts);
if(counter == extraPages) {
$.mobile.loading("hide");
processPosts();
} else {
downloadImages(url, counter + 1, extraPages, funnyURLExtension)
}
}
).fail(function(xhr, status, text) {
$.mobile.loading("hide");
alert("An error has occurred, please try again later.");
});
}
function processPosts() {
var numImages = getSliderValue("#num-images");
var allowNSFW = $("#allow-nsfw").val() == "on";
var resultImages = new Array();
normalPosts = shuffle(normalPosts);
for (var i = 0; i < normalPosts.length; i++) {
var data = normalPosts[i].data;
if(!allowNSFW && data.over_18) {
continue;
}
if(stringEndsWith(data.url, "png") || stringEndsWith(data.url, "jpg")) {
resultImages.push(data.url);
break;
} else {
continue;
}
}
allPosts = shuffle(allPosts);
var counter = 1;
for(var i = 0; i < allPosts.length; i++) {
var data = allPosts[i].data;
if(!allowNSFW && data.over_18) {
continue;
}
if(stringEndsWith(data.url, "png") || stringEndsWith(data.url, "jpg")) {
resultImages.push(data.url);
counter++;
if(counter >= numImages) {
break;
}
} else {
continue;
}
}
startSlideShow(resultImages);
}
function stringEndsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
//If the user didn't enter a properly formatted number, then set it to 15
function getSliderValue(selector) {
var value = $(selector).val();
return (value + "").match(/^[0-9]+$/g) ? value : 15;
}
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/array/shuffle [v1.0]
function shuffle(o){ //v1.0
for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
};
//Either run the slideshow or print out the links
function startSlideShow(imageLinks) {
var firstTime = getSliderValue("#first-slide-time");
var otherTime = getSliderValue("#other-slide-time");
var generateLinks = $("#generate-links").val() == "on";
var showTimer = $("#show-timer").val() == "on";
var $linkContainer = $("#link-container");
if(generateLinks) {
$linkContainer.html("");
$linkContainer.show();
for(var i = 0; i < imageLinks.length; i++) {
var imageURL = imageLinks[i];
$linkContainer.append('<div><a href="' + imageURL + '" target="_blank">' + imageURL + '</a></div>');
}
return;
} else {
$linkContainer.hide();
}
var $slideShow1 = $("#slideshow1");
var $slideShow2 = $("#slideshow2");
var $timer = $("#timer");
var firstDisplayed = true;
var counter = 2;
var fadeTime = 500;
$("#options-section").slideUp();
$slideShow1.hide();
$slideShow2.hide();
$("#image-container").show();
$slideShow1.attr('src', imageLinks[0]);
$slideShow1.fadeIn(fadeTime, function() {
$slideShow2.attr('src', imageLinks[1]);
});
if(showTimer) {
startTimer(firstTime);
$timer.show();
}
setTimeout(function() {
$slideShow2.show();
$slideShow1.fadeOut(fadeTime, function() {
$slideShow1.attr('src', imageLinks[counter]);
counter++;
});
if(showTimer) {
startTimer(otherTime);
}
firstDisplayed = false;
var timerId = setInterval(function() {
if(counter >= imageLinks.length) {
$("#options-section").show("slow");
$("#image-container").hide();
$timer.hide();
clearInterval(timerId);
} else {
if(showTimer) {
startTimer(otherTime);
}
if(firstDisplayed) {
$slideShow1.fadeOut(fadeTime, function() {
$slideShow1.attr('src', imageLinks[counter]);
counter++;
});
} else {
$slideShow1.fadeIn(fadeTime, function() {
$slideShow2.attr('src', imageLinks[counter]);
counter++;
});
}
firstDisplayed = !firstDisplayed;
}
}, otherTime*1000);
}, firstTime*1000);
}
//Start the timer with the specified number of seconds
function startTimer(time) {
var counter = time;
var $timer = $("#timer");
$timer.text("" + counter);
var timerId = setInterval(function() {
if(counter == 0) {
clearInterval(timerId);
} else {
counter--;
$timer.text("" + counter);
}
}, 950);
}
//]]>
</script>
</head>
<body>
<div data-role="page" id="mainpage">
<div data-role="header">
<a href="http://www.growingcoder.com" data-icon="home" class="ui-btn-left" target="_blank">Growing Coder</a>
<h1>PPTK Generator</h1>
</div>
<div class="mainbody">
<a href="https://github.com/piercez" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
<div id="options-section">
<h3>Generate random images from reddit to create a <a href="http://ppt-karaoke.com/" target="_blank">Powerpoint Karaoke</a> Slideshow</h3>
<div>
<div>
<div class="input-container">
<label for="first-slide-time">Seconds on First Image: </label>
<input name="first-slide-time" id="first-slide-time" min="15" max="40" value="25" type="range" pattern="[0-9]+">
</div>
<div class="input-container">
<label id="other-time-label" for="other-slide-time">Seconds on Other Images: </label>
<input name="other-slide-time" id="other-slide-time" min="10" max="30" value="15" type="range" pattern="[0-9]+">
</div>
<div class="input-container" id="num-images-container">
<label id="num-images-label" for="num-images">Number of Images: </label>
<input name="num-images" id="num-images" min="8" max="20" value="12" type="range" pattern="[0-9]+">
</div>
</div>
<div>
<div class="switch-container">
<label for="generate-links">Links Only</label>
<select name="generate-links" id="generate-links" data-role="slider">
<option value="off">Off</option>
<option value="on">On</option>
</select>
</div>
<div class="switch-container">
<label for="allow-nsfw">Allow NSFW(18+)</label>
<select name="allow-nsfw" id="allow-nsfw" data-role="slider">
<option value="off">Off</option>
<option value="on">On</option>
</select>
</div>
<div class="switch-container">
<label for="show-timer">Show Timer</label>
<select name="show-timer" id="show-timer" data-role="slider">
<option value="off">Off</option>
<option value="on">On</option>
</select>
</div>
</div>
</div>
<div>
<a href="#" id="generate-button" data-role="button" data-inline="true">Generate Images</a>
</div>
</div>
<div id="link-container"></div>
<div>
<p id="timer">15</p>
</div>
<div id="image-container">
<img id="slideshow2" src="" >
<img id="slideshow1" src="" >
</div>
</div>
</div>
</body>
</html>