-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mobalife
committed
Aug 22, 2024
1 parent
7169d12
commit 9291136
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<html> | ||
|
||
<body> | ||
<input id="message" placeholder="Type your message" /> | ||
<button onclick="sendMessage()">Send</button> | ||
<ul id="messages"></ul> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script> | ||
<script> | ||
const gun = Gun(['https://themeticus.github.io/fengui/']) | ||
// const gun = Gun(['https://your-relay-server-url.com/gun']); | ||
const messages = gun.get('messages'); | ||
|
||
messages.map().on(function (data, id) { | ||
const li = document.createElement('li'); | ||
li.textContent = data; | ||
document.getElementById('messages').appendChild(li); | ||
}); | ||
|
||
function sendMessage() { | ||
const msg = document.getElementById('message').value; | ||
messages.set(msg); | ||
document.getElementById('message').value = ''; | ||
} | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<html> | ||
|
||
<body> | ||
<h1>Todo</h1> | ||
|
||
<form id="sign"> | ||
<input id="alias" placeholder="username"> | ||
<input id="pass" type="password" placeholder="passphrase"> | ||
<input id="in" type="submit" value="sign in"> | ||
<input id="up" type="button" value="sign up"> | ||
</form> | ||
|
||
<ul></ul> | ||
|
||
<form id="said"> | ||
<input id="say"> | ||
<input id="speak" type="submit" value="speak"> | ||
</form> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/gun/examples/jquery.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/gun/sea.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/gun/lib/webrtc.js"></script> | ||
<script> | ||
var gun = Gun(['http://localhost:5500/gun', 'https://gun-manhattan.herokuapp.com/gun']); | ||
var user = gun.user(); | ||
|
||
$('#up').on('click', function (e) { | ||
user.create($('#alias').val(), $('#pass').val()); | ||
}); | ||
|
||
$('#sign').on('submit', function (e) { | ||
e.preventDefault(); | ||
user.auth($('#alias').val(), $('#pass').val()); | ||
}); | ||
|
||
$('#said').on('submit', function (e) { | ||
e.preventDefault(); | ||
if (!user.is) { return } | ||
user.get('said').set($('#say').val()); | ||
$('#say').val(""); | ||
}); | ||
|
||
function UI(say, id) { | ||
var li = $('#' + id).get(0) || $('<li>').attr('id', id).appendTo('ul'); | ||
$(li).text(say); | ||
}; | ||
|
||
gun.on('auth', function () { | ||
$('#sign').hide(); | ||
user.get('said').map().once(UI); | ||
}); | ||
</script> | ||
</body> | ||
|
||
</html> |