-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscripts.js
52 lines (43 loc) · 1.59 KB
/
scripts.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
---
---
// https://webdesign.tutsplus.com/tutorials/how-to-lazy-load-embedded-youtube-videos--cms-26743
(function() {
var youtube = document.querySelectorAll( ".youtube-video" );
for (var i = 0; i < youtube.length; i++) {
// thumbnail image source.
// var source = "https://img.youtube.com/vi/"+ youtube[i].dataset.embed +"/sddefault.jpg";
var source = "{{ site.baseurl }}/images/youtube-placeholder.jpg";
// Load the image asynchronously
var image = new Image();
image.src = source;
image.addEventListener( "load", function() {
youtube[ i ].appendChild( image );
}( i ) );
youtube[i].addEventListener( "click", function() {
var iframe = document.createElement( "iframe" );
iframe.setAttribute( "frameborder", "0" );
iframe.setAttribute( "allowfullscreen", "" );
iframe.setAttribute( "src", "https://www.youtube.com/embed/"+ this.dataset.embed +"?rel=0&showinfo=0&autoplay=1" );
this.innerHTML = "";
this.appendChild( iframe );
} );
}
})();
fetch(window.location.origin+"/api.json")
.then(res => res.json())
.then(out => {
window.posts = out
})
function selectRandom() {
if (window.posts) {
window.location.href = window.location.origin + window.posts[Math.floor(Math.random()*window.posts.length)].url;
} else {
fetch(window.location.origin+"/api.json")
.then(res => res.json())
.then((out) => {
var randomURL = out[Math.floor(Math.random()*out.length)];
window.location.href = window.location.origin + randomURL.url;
})
.catch(err => { throw err });
}
}