-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathleekspins.js
94 lines (91 loc) · 2.54 KB
/
leekspins.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
var audio,
playButtonHtml,
bodyCss,
playing = false;
var frames = new Array(4);
document.addEventListener("DOMContentLoaded", function() {
document.body.parentNode.style.height = "100%";
document.body.style.cssText = bodyCss;
var i = frames.length;
while (i--) {
frames[i] = new Image();
frames[i].src = window["frame" + (i + 1)];
frames[i].style.width = "100%";
frames[i].style.pointerEvents = "none";
}
audio = new Audio();
audio.addEventListener("canplaythrough", canPlayHandler);
audio.loop = true;
audio.src = loituma_ogg;
});
function canPlayHandler(e) {
audio.removeEventListener("canplaythrough", canPlayHandler);
if (/fullcpgrid/.test(document.location.pathname)) {
showPlayButton();
} else {
tryPlayback();
}
}
function tryPlayback() {
window.removeEventListener("click", tryPlayback, true);
return canPlay(audio)
.then(function() {
startPlayback();
})
.catch(function(e) {
showPlayButton();
});
}
function showPlayButton() {
document.body.innerHTML = playButtonHtml;
document.body.style.backgroundImage = "url(" + frames[0].src + ")";
window.addEventListener("click", tryPlayback, true);
}
function startPlayback() {
window.addEventListener("click", muteHandler, true);
document.body.innerHTML = "";
audio.play();
var frame = 0;
setInterval(function() {
document.body.style.backgroundImage = "url(" + frames[frame].src + ")";
frame++;
if (frames[frame] === undefined) frame = 0;
}, 100);
}
function muteHandler() {
audio.muted = !audio.muted;
}
function canPlay(audio) {
var playHandler, timeout;
return new Promise(function(resolve, reject) {
playHandler = resolve;
audio.play();
audio.addEventListener("play", playHandler);
timeout = setTimeout(reject, 10);
})
.then(function() {
audio.pause();
clearTimeout(timeout);
audio.removeEventListener("play", playHandler);
})
.catch(function(e) {
clearTimeout(timeout);
audio.removeEventListener("play", playHandler);
throw e;
});
}
(function() {
bodyCss =
"box-sizing:border-box;width:100%;height:100%;margin:0;background:#000 no-repeat 50% 50%/contain;";
})(); // bodyCss
(function() {
playButtonHtml =
'<div style="' +
"position:absolute;display:table;width:100%;height:100%;" +
"background:no-repeat 50% 50%/contain;" +
"cursor:pointer;font:4rem arial;text-shadow: 0 0 .5rem #fff;" +
'">' +
'<div style="display:table-cell;text-align:center;vertical-align:middle;">' +
"Play" +
"</div></div>";
})(); // html