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
}
|
| 7 |
+
|
| 8 |
+
body {
|
| 9 |
+
background-color: rgb(31, 31, 31);
|
| 10 |
+
font-family: 'Roboto', sans-serif;
|
| 11 |
+
overflow-x: hidden;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
ul { list-style: none; }
|
| 15 |
+
|
| 16 |
+
h1 {
|
| 17 |
+
text-transform: uppercase;
|
| 18 |
+
margin: 0 auto;
|
| 19 |
+
padding: 20px;
|
| 20 |
+
text-align: center;
|
| 21 |
+
color: #3c3c3e;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/* chatbox */
|
| 25 |
+
.chat {
|
| 26 |
+
max-width: 100px;
|
| 27 |
+
min-height: 400px;
|
| 28 |
+
background-color: rgb(31, 31, 31);
|
| 29 |
+
padding-right: 15px;
|
| 30 |
+
padding-left: 15px;
|
| 31 |
+
|
| 32 |
+
border-radius: 1rem;
|
| 33 |
+
height: --webkit-fill-available;
|
| 34 |
+
position: relative;
|
| 35 |
+
float: left;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
/* messages */
|
| 39 |
+
.messages {
|
| 40 |
+
display: flex;
|
| 41 |
+
flex-direction: column;
|
| 42 |
+
justify-content: space-between;
|
| 43 |
+
height: --webkit-fill-available;
|
| 44 |
+
font-family: 'Open Sans', sans-serif;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
.message-list {
|
| 48 |
+
padding: 2px;
|
| 49 |
+
overflow-y: scroll;
|
| 50 |
+
height: inherit;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.message-item {
|
| 54 |
+
padding: 12px;
|
| 55 |
+
border-radius: 0.75rem;
|
| 56 |
+
margin: 20px 0;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.message-item span{
|
| 60 |
+
font-weight: bold;
|
| 61 |
+
text-transform: uppercase;
|
| 62 |
+
padding: 5px;
|
| 63 |
+
border-radius: 7px;
|
| 64 |
+
margin-left: -5px;
|
| 65 |
+
cursor: pointer;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
.message-item:last-child {
|
| 69 |
+
margin-bottom: 0;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
.item-primary span{
|
| 73 |
+
background-color: #282828;
|
| 74 |
+
filter: brightness(1.3);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
.item-secondary span {
|
| 78 |
+
background-color: #d400ff;
|
| 79 |
+
filter: brightness(1.3);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/* messages input */
|
| 83 |
+
.message-input {
|
| 84 |
+
display: flex;
|
| 85 |
+
padding: 20px 0;
|
| 86 |
+
}
|
| 87 |
+
.message-input pre {
|
| 88 |
+
background: #0000005c;
|
| 89 |
+
padding: 13px;
|
| 90 |
+
border-radius: 5px;
|
| 91 |
+
|
| 92 |
+
}
|
| 93 |
+
.message-input input {
|
| 94 |
+
width: 100%;
|
| 95 |
+
padding: 16px;
|
| 96 |
+
border-radius:0.3rem;
|
| 97 |
+
border: 1px solid #2a2a2a;
|
| 98 |
+
background: #161616;
|
| 99 |
+
font-size: 17px;
|
| 100 |
+
color: #fff;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.message-input button {
|
| 104 |
+
padding: 10px;
|
| 105 |
+
margin-left: 10px;
|
| 106 |
+
border-radius: 5px;
|
| 107 |
+
border: none;
|
| 108 |
+
cursor: pointer;
|
| 109 |
+
background: #292929;
|
| 110 |
+
color: #d8d8d8;
|
| 111 |
+
font-weight: bold;
|
| 112 |
+
}
|
| 113 |
+
/*scroll bar*/
|
| 114 |
+
.message-list::-webkit-scrollbar {
|
| 115 |
+
margin-top: 0.5rem;
|
| 116 |
+
height: 1rem;
|
| 117 |
+
width: .5rem;
|
| 118 |
+
top: 10px;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
.message-list::-webkit-scrollbar:horizontal {
|
| 122 |
+
height: .5rem;
|
| 123 |
+
width: 1rem
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
.message-list::-webkit-scrollbar-track {
|
| 127 |
+
background-color: transparent;
|
| 128 |
+
border-radius: 9999px
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
.message-list::-webkit-scrollbar-thumb {
|
| 132 |
+
--tw-border-opacity: 1;
|
| 133 |
+
background-color: hsla(0, 0%, 50%, .8);
|
| 134 |
+
border-color: rgba(255, 255, 255, 0, 0, 0);
|
| 135 |
+
border-radius: 9999px;
|
| 136 |
+
border-width: 1px
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
.message-list::-webkit-scrollbar-thumb:hover {
|
| 140 |
+
--tw-bg-opacity: 1;
|
| 141 |
+
background-color: rgba(150, 150, 150, var(--tw-bg-opacity))
|
| 142 |
+
}
|
static/js/main.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Variables
|
| 2 |
+
var messages = document.querySelector('.message-list')
|
| 3 |
+
var btn = document.querySelector('.btn')
|
| 4 |
+
var input = document.querySelector('input')
|
| 5 |
+
|
| 6 |
+
// Button/Enter Key
|
| 7 |
+
btn.addEventListener('click', sendMessage)
|
| 8 |
+
input.addEventListener('keyup', function(e){ if(e.keyCode == 13) sendMessage() })
|
| 9 |
+
|
| 10 |
+
function loadHistory(){
|
| 11 |
+
fetch('/history')
|
| 12 |
+
.then(response => response.json())
|
| 13 |
+
.then(data => {
|
| 14 |
+
for(let i = 0; i < data.length; i++){
|
| 15 |
+
|
| 16 |
+
if(data[i].FROM == 'User') {
|
| 17 |
+
writeLine('<span>User</span><br><br> ${data[i].content}','primary')
|
| 18 |
+
}
|
| 19 |
+
else {
|
| 20 |
+
writeLine('<span>oshinoko</span><br><br> ${data[i].content}','secondary')
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
})
|
| 25 |
+
.catch(error => console.error('Error:', error));
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
loadHistory()
|
| 31 |
+
// Messenger Functions
|
| 32 |
+
function sendMessage(){
|
| 33 |
+
var msg = input.value;
|
| 34 |
+
writeLine(`<span>User</span><br><br> ${msg}`,'primary')
|
| 35 |
+
|
| 36 |
+
input.value = ''
|
| 37 |
+
fetch('/chat', {
|
| 38 |
+
method: 'POST',
|
| 39 |
+
headers: {
|
| 40 |
+
'Content-Type': 'application/json'
|
| 41 |
+
},
|
| 42 |
+
body: JSON.stringify({'message': msg})
|
| 43 |
+
})
|
| 44 |
+
.then(response => response.json())
|
| 45 |
+
.then(data => console.log(data, 'secondary'))
|
| 46 |
+
.catch(error => console.error('Error:', error));
|
| 47 |
+
|
| 48 |
+
}
|
| 49 |
+
function addMessage(msg,typeMessage ='primary'){
|
| 50 |
+
writeLine(`<span>${msg.FROM}</span><br><br> ${msg.MESSAGE}`,typeMessage)
|
| 51 |
+
}
|
| 52 |
+
function writeLine(text,typeMessage){
|
| 53 |
+
var message = document.createElement('li')
|
| 54 |
+
message.classList.add('message-item', 'item-'+typeMessage)
|
| 55 |
+
message.innerHTML = 'Miguel says: ' + text
|
| 56 |
+
messages.appendChild(message)
|
| 57 |
+
messages.scrollTop = messages.scrollHeight;
|
| 58 |
+
}
|