-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
108 lines (92 loc) · 3.54 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
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
_386 = { onePass: true, speedFactor: 1.25 };
var originalAnswer = ''
function getUserLang() {
var userLang = localStorage.getItem('userLang')
var path = window.location.pathname
if(path === '/pt-BR/' || path === '/pt-BR') { localStorage.setItem('userLang', 'pt-BR') }
if((path === '/' || path === '') && userLang) { localStorage.setItem('userLang', 'en-US') }
if(userLang) { return userLang }
var userBrowserLang = navigator.language || navigator.userLanguage || 'en-US';
localStorage.setItem('userLang', userBrowserLang)
return userLang
}
function createContainer(extra) {
$('.answer-box').empty();
for( var i = 0; i < 17; i++) {
setTimeout(function() {
$('<div class="block ' + extra + '" />').appendTo('.answer-box');
}, 100*i)
}
removeContainer(extra);
setTimeout(printAnswer, 1700);
}
function removeContainer(extra) {
$('.answer-box').empty();
for( var i = 17; i > 0; i--) {
setTimeout(function() { $('.block.' + extra).eq(i).remove()}, 100*(17 + i))
}
}
function getAnswer() {
createContainer('block-left');
createContainer('block-right');
}
function printAnswer() {
var answers = []
answers['pt-BR'] = [
'Tire suas mãos sujas deste teclado!',
'Saia daqui e deixe as perguntas para quem serve a mim!',
'Você não tem capacidade de fazer uma pergunta direito!',
'Sai deste teclado otário!'
]
answers['en-US'] = [
'Get out of my keyboard piece of shit!',
'Get out and leave the questions for a servant to me!',
"You can't do a question right!",
'Get out of this keyboard asshole'
]
var item = answers[getUserLang()][Math.floor(Math.random()*answers[getUserLang()].length)];
$('.answer-line').empty();
$('<div class="answer-line" />').html(originalAnswer.length ? originalAnswer : item).appendTo('.answer-box');
}
function startMask(e) {
maskOn();
e.preventDefault();
}
function maskOn() {
var questions = []
questions['pt-BR'] = [
'Querido computador, razão da minha vida, venho por meio deste lhe perguntar sobre questões deste universo que sei que na sua magnitude você terá a resposta'
];
questions['en-US'] = [
'Dear computer, reason of my life, I want to gentle ask you about some questions surrounding the universe and I know of the power of your wise answers'
];
var item = questions[getUserLang()][Math.floor(Math.random()*questions[getUserLang()].length)];
$('#inputQuestion').on('keydown.mask',function(event) {
if(event.keyCode === 13) {
$('#inputQuestion').off('keydown.mask');
return false;
} else {
if((event.keyCode === 32) || (event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 65 && event.keyCode <= 90) || (event.keyCode >= 188 && event.keyCode <= 222)) {
originalAnswer += String.fromCharCode(event.keyCode)
var value = $('#inputQuestion').val();
$('#inputQuestion').val(value + item.charAt(value.length))
event.preventDefault();
}
}
});
}
$(function() {
getUserLang()
$('#inputQuestion').on('keydown',function(e) {
if(e.keyCode === 186) {
startMask(e);
}
});
$('#question-form').on('submit', function(e) {
getAnswer();
//var audio = new Audio('audio_file.mp3');
//audio.play()
return false;
});
$('.language-bar li[lang="' + getUserLang() + '"]').addClass('active')
});