-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
67 lines (56 loc) · 1.76 KB
/
main.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
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js');
}
const magicWords = [
'android', 'atom', 'aws',
'bash', 'bluetooth', 'boba', 'boto',
'chmod', 'chown', 'columnar', 'cron',
'datamart', 'dir',
'echo', 'etl',
'fax',
'git', 'glue', 'google', 'grep', 'gzip',
'hadoop', 'hbo', 'hmem', 'hulu',
'iphone',
'json',
'kindle',
'larp', 'less', 'ls', 'luigi',
'netflix', 'nohup',
'pager', 'parquet', 'pdf', 'php', 'ping', 'pip', 'postgres',
'query', 'queue',
'redshift', 'regex', 'root',
's3', 'sms', 'spark', 'sql', 'sriracha', 'ssh', 'sublime',
'vi',
];
const eventName = 'ontouchstart' in window ? 'touchstart' : 'click';
Array.prototype.random = function() {
return this[Math.floor(Math.random() * this.length)];
};
const $wrapper = document.querySelector('.js-wrapper');
const $outlet = document.querySelector('.js-outlet');
function openScroll() {
const spell = [magicWords.random(), magicWords.random(), magicWords.random()].join(' ');
$outlet.innerHTML = spell;
$wrapper.style.maxHeight = String($outlet.scrollHeight + 20) + 'px';
}
function closeScroll() {
$wrapper.addEventListener('transitionend', onCloseScroll);
$wrapper.style.maxHeight = 0;
}
function onCloseScroll() {
$wrapper.removeEventListener('transitionend', onCloseScroll);
openScroll();
document.body.addEventListener(eventName, newSpell);
}
function newSpell() {
document.body.removeEventListener(eventName, newSpell);
closeScroll();
}
window.addEventListener('load', function() {
openScroll();
document.body.addEventListener(eventName, newSpell);
});
document.addEventListener('visibilitychange', function() {
if (!document.hidden) {
newSpell();
}
});