-
Notifications
You must be signed in to change notification settings - Fork 9
/
script.js
111 lines (89 loc) · 3.14 KB
/
script.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
109
110
111
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
bot_content.style.visibility = 'hidden';
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
bot_content.style.visibility = 'visible';
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
bot_content.style.visibility = 'visible';
}
}
let bot = new RiveScript();
const message_container = document.querySelector('.messages');
const form = document.querySelector('form');
const input_box = document.querySelector('input');
const brains = [
'https://gist.githubusercontent.com/benjamin-bala/6ad440da644d80c33f22e6266c087d0c/raw/ecf426567e926cec48f6dda8b5adf5bfe0943983/brain.rive'
];
const anagram =[
'https://gist.githubusercontent.com/benjamin-bala/984cfdacdd7e89aa86f58bb04948daec/raw/2273bbcd7bc9504a50fbbd3774c3a50c550fa73a/anagram.rive'
];
bot.loadFile(anagram).catch(botNotReady);
bot.loadFile(brains).then(botReady).catch(botNotReady);
form.addEventListener('submit', (e) => {
e.preventDefault();
selfReply(input_box.value);
input_box.value = '';
input_box.focus();
});
//days array
var day = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursdäy", "Friday", "Saturday"];
//months array
var month = ["January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
//to distinuish each msg timestamp fro the other
var j = 0;
//get all classes in an array,same class name tho
var classesbot = [];
function botReply(message){
message_container.innerHTML += `<p class='testbot' style='margin-bottom:0'></p>
<div class="bot">${message}</div>`;
classesbot = document.getElementsByClassName('testbot');
classesbot[j].innerHTML= new Date().getHours() + ":" + addZero(new Date().getMinutes());
//increment variable, so next timestamp will not affect previous
j= j+1;
location.href = '#edge';
}
//same procedure as above
var i = 0;
var classes = [];
function selfReply(message){
message_container.innerHTML += `<p class='testself'></p>
<div class="self">${message}</div>`;
classes = document.getElementsByClassName('testself');
bot.reply("local-user", message).then(function(reply) {
botReply(reply);
input_box.focus();
});
classes[i].innerHTML= new Date().getHours() + ":" + addZero(new Date().getMinutes());
i= i+1;
location.href = '#edge';
}
function addZero(minute){ //incase minute is returned as a single number, add a '0' to it as prefix
if (minute < 10)
{
return ("0"+minute);
}
else{
return minute;
}
}
function botReady(){
bot.sortReplies();
botReply('Hello, What is your name?');
input_box.focus();
}
function botNotReady(err){
console.log("An error has occurred.", err);
}