-
Notifications
You must be signed in to change notification settings - Fork 1
/
realtime.html
186 lines (181 loc) · 4.74 KB
/
realtime.html
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<html>
<head>
<meta name="viewport" content="width=device-width">
<!-- meta -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:creator" content="@_unwriter" />
<meta name="twitter:title" content="MemoButton" />
<meta name="twitter:description" content="Post to memo.cash with Moneybutton!" />
<meta name="twitter:image" content="https://unwriter.github.io/memobutton/btn.png" />
<meta property="og:url" content="https://unwriter.github.io/memobutton" />
<meta property="og:type" content="website" />
<meta property="og:title" content="MemoButton" />
<meta property="og:description" content="Post to memo.cash with Moneybutton!" />
<meta property="og:image" content="https://unwriter.github.io/memobutton/btn.png" />
<style>
body {
font-family: "Helvetica Neue", helvetica, arial;
padding: 50px;
font-size: 14px;
color: rgba(0,0,0,0.8);
}
hr {
margin: 20px 0;
border: none;
background: rgba(0,0,0,0.1);
height: 1px;
}
h1 {
color: #4772F6;
text-align: center;
font-weight: 900;
font-size: 40px;
}
h1 > small {
font-size: 12px;
display: block;
font-weight: 400;
}
h2 {
background: rgba(0,0,0,0.04);
font-size: 20px;
color: rgba(0,0,0,0.8);
}
h1, h2 {
padding: 10px;
font-weight: 700;
margin: 0;
}
.btn {
background: #4772F6;
color: white;
display: block;
text-align: center;
padding: 10px;
}
.container {
margin:0 auto;
width: 400px;
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
word-break: break-word;
}
.form textarea {
padding: 10px;
width: 100%;
font-size: 14px;
}
.hidden {
display: none;
}
#submit {
font-size: 12px;
text-align: center;
}
#submit > * {
margin: 10px;
}
.feed {
width: 100%;
}
a.outlink {
padding: 5px;
text-align: right;
display: block;
color: #F97467;
}
.row {
border-bottom: 1px solid rgba(0,0,0,0.1);
padding-bottom: 10px;
}
.center {
text-align: center;
}
</style>
<script src="https://api.moneybutton.com/moneybutton.js"></script>
<script src='https://unpkg.com/datacash'></script>
<script src='https://unpkg.com/databutton'></script>
<script>
var feed = function(uri) {
console.log("rendering feed")
var header = { headers: { key: "qqjtyk2qmphm4d2ddqfeg855we2u4ly7m59a0tuenn" } };
fetch(uri, header).then(function(r) {
return r.json()
}).then(function(r) {
var unconfirmed_feed = r.u.map(function(item) {
let output = item.out.filter(function(o) {
return o.b0.op && o.b0.op === 106;
})
return "<div class='row'> "
+ output[0].s2
+ "<a target='_blank' class='outlink' href='https://memo.cash/post/" + item.tx.h + "'>view on memo</a>"
+ " </div>";
}).join("<br>")
var confirmed_feed = r.c.map(function(item) {
let output = item.out.filter(function(o) {
return o.b0.op && o.b0.op === 106;
})
return "<div class='row'> "
+ output[0].s2
+ "<a target='_blank' class='outlink' href='https://memo.cash/post/" + item.tx.h + "'>view on memo</a>"
+ " </div>";
}).join("<br>")
document.querySelector(".feed").innerHTML = "<hr><h2>" + r.u.length + " Unconfirmed</h2><br>" + unconfirmed_feed + "<h2>" + r.c.length + " Confirmed</h2><br>" + confirmed_feed;
})
}
document.addEventListener("DOMContentLoaded", function() {
// Pull
var query = { v: 3, q: { find: { "out.h1": "6d02" } } }
var b64 = btoa(JSON.stringify(query));
var uri = "https://bitdb.network/q/" + b64;
feed(uri)
// Push
var bitsocket = new EventSource('https://bitsocket.org/s/'+b64)
bitsocket.onmessage = function(e) {
feed(uri)
}
document.querySelector("#done").addEventListener("click", function(e) {
document.querySelector("#submit").classList.remove('hidden')
databutton.build({
data: ["0x6d02", document.querySelector("#msg").value],
button: {
$el: "#button",
label: "Slide to Post!",
onPayment: function(e) {
console.log("paid!", e)
}
}
})
})
})
</script>
</head>
<body>
<div class='container'>
<h1>
MemoButton
<small>Post to memo.cash with <a href='https://moneybutton.com'>moneybutton</a></small>
</h1>
<hr>
<div class='center'>
Powered by:
<a href='https://moneybutton.com'>Moneybutton</a> +
<a href='https://memo.cash/protocol'>Memo.cash</a> +
<a href='https://bitdb.network'>BitDB</a>
</div>
<hr>
<div class='form'>
<textarea id='msg' placeholder='Enter text to post to memo.cash from moneybutton'></textarea>
<a href='#' id='done' class='btn'>Done</a>
<div id='submit' class='hidden'>
<hr>
<div >Press the money button to post to memo.cash!</div>
<div id='button'></div>
</div>
</div>
<div class='feed'>
</div>
</div>
</body>
</html>