-
Notifications
You must be signed in to change notification settings - Fork 0
/
public.js
40 lines (34 loc) · 1.03 KB
/
public.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
function send(btn) {
let channel = document.getElementById("channelIn").value;
let password = document.getElementById("passwordIn").value;
let text = document.getElementById("textIn").value;
fet("postText", {channel: channel, text: text, password: password});
flash(btn);
}
function recieve(btn) {
let channel = document.getElementById("channelOut").value;
let password = document.getElementById("passwordOut").value;
let textElem = document.getElementById("textOut");
fet("getText", {channel: channel, password: password}, res=> {
textElem.value = res.text;
});
flash(btn);
}
function flash(btn) {
btn.style.backgroundColor = "rgba(0, 255, 0, 255)";
setTimeout(()=>{
btn.style.backgroundColor = "rgba(0, 255, 0, 0)"
}, 200);
}
function fet(url, body, callback = ()=>{}) {
fetch(url,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
}).then(a=>{return a.json()}).then(res=>{
callback(res);
});
}