mirror of
https://github.com/amark/gun.git
synced 2026-03-18 22:29:18 +00:00
relay
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<ul id='list'></ul>
|
||||
<form id='form'>
|
||||
<input id='input' placeholder='say'>
|
||||
<input id='who' placeholder='name'>
|
||||
<input id='what' placeholder='say'>
|
||||
<input type='submit' value='send'>
|
||||
</form>
|
||||
<script src="../../../gun/gun.js"></script>
|
||||
@@ -9,14 +10,12 @@
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/emojione@4.0.0/extras/css/emojione.min.css"/>
|
||||
<script>
|
||||
gun = Gun(location.origin + '/gun'), chat = gun.get("chat/" + location.hash.slice(1));
|
||||
form.onsubmit = (eve) => { eve.preventDefault(), chat.set(input.value), input.value = "" }
|
||||
chat.map().once((msg) => { render(msg) });
|
||||
form.onsubmit = (eve) => { chat.set(who.value+': '+what.value), eve.preventDefault(what.value = "") }
|
||||
chat.map().once((data) => { render(data) });
|
||||
function render(msg, li, beep){ // render emoji, scroll to bottom, and notify sound!
|
||||
(li = document.createElement("li")).innerText = emojione.shortnameToUnicode(msg);
|
||||
list.appendChild(li);
|
||||
window.scroll(0, list.offsetHeight);
|
||||
list.appendChild(li), window.scroll(0, list.offsetHeight);
|
||||
(beep = new SpeechSynthesisUtterance()).text = "new";
|
||||
beep.rate = 10; beep.pitch = 2;
|
||||
window.speechSynthesis.speak(beep);
|
||||
beep.rate = 10, beep.pitch = 2, window.speechSynthesis.speak(beep);
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user