Skip to content

Commit

Permalink
the gunners
Browse files Browse the repository at this point in the history
  • Loading branch information
mobalife committed Aug 22, 2024
1 parent 7169d12 commit 9291136
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
28 changes: 28 additions & 0 deletions demo.html
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>
56 changes: 56 additions & 0 deletions onet.html
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>

0 comments on commit 9291136

Please sign in to comment.