forked from LynxLead/Anon-Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
493 lines (445 loc) · 17.5 KB
/
index.html
File metadata and controls
493 lines (445 loc) · 17.5 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
<html>
<head>
<title>Anedak Anon Chat</title>
<meta name="description" content="Free anonymous chat engraved on the Kadena network">
<script src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
<script src="https://kit.fontawesome.com/6c30d9724b.js" crossorigin="anonymous"></script>
<div class="maintext">
<div id="boxes">
<div style="top: 199.5px; left: 551.5px; display: none;" id="dialog" class="window"> IMPORTANT WARNING
<div id="lorem">
<p>This chat <b>cannot be moderated. It is a REAL dapp</b>. The front-end can go down but not the contract itself. You can host your own page to send messages and read them.</p>
<p>What is freedom of expression? Without the freedom to offend, it ceases to exist. <br /> -Salman Rushdie</p>
<p>Goebbels was in favor of free speech for views he liked. So was Stalin. If youre really in favor of free speech, then youre in favor of freedom of speech for precisely the views you despise. Otherwise, youre not in favor of free speech. <br /> -Noam Chomsky</p>
<p>Without freedom of thought, there can be no such thing as wisdom - and no such thing as public liberty without freedom of speech. </br>-Benjamin Franklin</p>
<p><b>Do you agree to see and read things you might not be comfortable with?</b> </p>
</div>
<div id="popupfoot"> <a href="#" class="close agree">I agree and I am 18+</a> <br /><br /> <a class="agree"style="color:red;" href="https://anedak.com/">I do not agree, take me to safety</a> </div>
</div>
<div style="width: 1478px; font-size: 32pt; color:white; height: 602px; display: none; opacity: 0.9;" id="mask"></div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
<script src="main.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36251023-1']);
_gaq.push(['_setDomainName', 'jqueryscript.net']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<style>
#mask {
position:absolute;
left:0;
top:0;
z-index:1000;
background-color:#000;
display:none;
}
#boxes .window {
position:absolute;
left:0;
top:0;
width:440px;
height:200px;
display:none;
z-index:9999;
padding:20px;
border-radius: 15px;
text-align: center;
}
#boxes #dialog {
width:450px;
height:auto;
padding:10px;
background-color:#ffffff;
font-family: 'Segoe UI Light', sans-serif;
font-size: 15pt;
}
.maintext{
text-align: center;
font-family: "Segoe UI", sans-serif;
text-decoration: none;
}
body{
background: url('bg.jpg');
}
#lorem{
font-family: "Segoe UI", sans-serif;
font-size: 12pt;
text-align: left;
}
#popupfoot{
font-family: "Segoe UI", sans-serif;
font-size: 16pt;
padding: 10px 20px;
}
#popupfoot a{
text-decoration: none;
}
.agree:hover{
background-color: #D1D1D1;
}
.popupoption:hover{
background-color:#D1D1D1;
color: green;
}
.popupoption2:hover{
color: red;
}
container{
margin-top: 50px;
}
input{
margin-top: 5px;
width: 500px;
}
#spinner{
margin-top: 10px;
margin-bottom: 10px;
}
i.close.icon::before {
cursor: pointer;
position: absolute;
font-size: 20px;
color: black;
left: -33px;
top: 48px;
}
anon-chat-container{
margin-top: 20px;
display: flex;
justify-content: center;
text-align: center;
}
#module-text{
margin-top: 30px;
}
.ui.feed>.event:target {
background-color: #eaf3ff;
}
img.inline-image {
word-wrap: break-word;
max-width: 90%;
max-height: 20em;
border:1px solid black;
}
img.inline-image.spoiler {
filter: blur(44px);
};
#img {
word-wrap: break-word;
max-width: 90%;
max-height: 20em;
border:1px solid black;
}
.blur {
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(12px);
}
.content {
overflow: hidden;
}
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
<link rel="icon" href="img/favicon.ico">
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/pact-lang-api@4.1.2/pact-lang-api-global.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/anchorme@2.1.2/dist/browser/anchorme.min.js"></script>
<script>
const host = `https://api.chainweb.com/chainweb/0.0/mainnet01/chain/1/pact`;
var creationTime = () => Math.round((new Date).getTime() / 1000) - 15;
const getLastTen = async (server) => {
const res = await Pact.fetch.local({
pactCode: `(free.anon-chat.query-all)`,
meta: Pact.lang.mkMeta("", "", 0.0001, 60000, creationTime(), 600)
}, server)
const all = res.result.data
all.sort((b, a) => a.bh.int - b.bh.int);
const lastTen = all.slice(0)
return lastTen
}
function citeBlock(blockId) {
const textNode = document.getElementById('user-input');
const text = textNode.value;
if (text.length == 0) textNode.value += '@' + blockId + ' ';
else if (text[text.length - 1] == ' ') textNode.value += '@' + blockId + ' ';
else textNode.value += ' @' + blockId + ' ';
updateCharCount(textNode);
}
const createFeedItem = (blockId, messageId, user, href) => {
var feedItem = document.createElement("div");
feedItem.className = "event";
feedItem.setAttribute("id", "feed-item-"+messageId);
feedItem.innerHTML =
`<div class="label">
<a href="javascript:citeBlock('${messageId}')" title="Cite message">↩</button> <a href="${href}" target="_blank" title="Open block ${blockId} in explorer">🧱</a>
</div>
<div class="content">
${user}
</div>`
return feedItem;
}
const MaximumCharacterCount = 1023;
const MinimumCharacterCount = 9;
function updateCharCount (el) {
const count = el.value.length;
if (count > MaximumCharacterCount) {
el.value = el.value.substr(0, MaximumCharacterCount);
}
var msg = '';
if (count < MinimumCharacterCount) {
msg = 'Your message is too short.';
} else if (count < (MaximumCharacterCount - MinimumCharacterCount) / 2 + MinimumCharacterCount) {
msg = 'You are allowed lots more.';
} else {
const left = MaximumCharacterCount - count;
msg = 'You are allowed ' + left + ' more.';
}
document.getElementById('user-input-char-count').innerHTML = count;
document.getElementById('user-input-char-count-message').innerHTML = msg;
return true;
}
const checkText = (text) => {
const profs = [
]
if (text.length > MaximumCharacterCount || profs.includes(text) || text === "" || text.length < MinimumCharacterCount) {
return true
} else {
return false
}
}
var tagsToReplace = {
'&': '&',
'<': '<',
'>': '>',
'\n': '<br/>'
};
function replaceTag(tag) {
return tagsToReplace[tag] || tag;
}
function safe_tags_replace(str) {
return str.replace(/[&<>\n]/g, replaceTag);
}
function preprocessMessages(str) {
str = safe_tags_replace(str);
str = anchorme({
input: str,
extensions: [
// an extension for mentions
{
test: /@([\d_])+/gi,
transform: string =>
`<a href="#feed-item-${escape(string.substr(1))}">${string}</a>`
}
],
options: {
attributes: {
target: "_blank"
},
exclude: true,
specialTransform: [{
test: /^https:\/\/i\.imgur\.com/,
transform: string =>
`<div><a class="blur" onclick="spoiler(this)" target="_blank"><img src="${string}" class="inline-image" alt="image"/></a></div>`
},
{
test: /./,
transform: string =>
`<a href="${string}" target="_blank">${string}</a>`
}]
}
});
return str;
}
const addFeed = async () => {
let colors = ["orange", "yellow", "olive", "green", "teal", "blue", "violet", "purple", "pink", "brown", "grey"];
//separate first 10 from last 10
let line = document.createElement("div");
line.classList = "ui section divider";
document.getElementById("feed-container").appendChild(line);
const lastTen = await getLastTen(host);
// lastTen.push({
// bh: {int:13},
// message: "@1560592_2"
// })
blockCounts = {};
lastTen.map((x, i) => {
if (blockCounts[x.bh.int] === undefined) {
blockCounts[x.bh.int] = 1;
} else blockCounts[x.bh.int] += 1;
const cnt = blockCounts[x.bh.int];
let feed = createFeedItem(x.bh.int, x.bh.int + '_' + cnt, preprocessMessages(x.message), `https://explorer.chainweb.com/mainnet/chain/1/height/${x.bh.int}` );
document.getElementById("feed-container").appendChild(feed);
let line = document.createElement("div");
line.classList = "ui fitted divider";
document.getElementById("feed-container").appendChild(line);
})
}
window.addEventListener('load', async function (event) {
await addFeed();
document.getElementById("pay-gas").addEventListener('click', async function () {
let user = document.getElementById("user-input").value;
if (checkText(user)) {
alert("Please keep messages between 8 and 1024 characters.")
} else {
payGas(user);
}
}, false);
}, false);
const payGas = async (user) => {
try {
const kp = Pact.crypto.genKeyPair();
const tx = await Pact.fetch.send(
{
networkId: "mainnet01",
pactCode: `(free.anon-chat.chat ${JSON.stringify(user)})`,
keyPairs: [
{
publicKey: kp.publicKey,
secretKey: kp.secretKey,
clist: [
//capability to use gas station
{
name: `free.anon-chat-gas-stationV2.GAS_PAYER`,
args: ["hi", {int: 1}, 1.0]
}
]
}],
meta: Pact.lang.mkMeta
(
"chat-gas-payerV2",
"1",
0.000000000001,
800,
creationTime(),
28800
)
}, host);
document.getElementById("requestKey").classList.remove("hidden")
document.getElementById("header-text").textContent = "Transaction sent to Kadena Mainnet";
document.getElementById("spinner").classList.add("active")
document.getElementById("content-text").textContent = "Please wait, this box will update once the transaction is confirmed in about 30 seconds."
document.getElementById("header-two-text").textContent = "Curious how interacting with a blockchain can be so simple?";
document.getElementById("content-two-text").textContent = "With most blockchains you need an account, a wallet, and some crypto in order to interact with them. Kadena's solution to this onboarding problem is gas stations; an account that exists only to fund gas payments on behalf of other users."
document.getElementById("content-three-text").textContent = "Thanks to gas stations, interacting with Kadena can be as simple as filling out a web form."
try {
let hello = await Pact.fetch.listen({"listen": tx.requestKeys[0]}, host);
if (hello.result.status !== "success"){
document.getElementById("header-text").textContent = "ERROR! INVESTIGATE BELOW";
document.getElementById("content-text").textContent = JSON.stringify(hello);
document.getElementById("spinner").classList.remove("active")
document.getElementById("header-two-text").textContent = "";
document.getElementById("content-two-text").textContent = "";
document.getElementById("content-three-text").textContent = "";
document.getElementById("link-text").textContent = "Block Exporer Link";
document.getElementById("link-text").href = "https://explorer.chainweb.com/mainnet/tx/" + tx.requestKeys[0];
}
else {
document.getElementById("header-text").textContent = "Success!";
document.getElementById("content-text").textContent = JSON.stringify(hello.result.data) + " has been added to the Memory Wall.";
document.getElementById("spinner").classList.remove("active")
document.getElementById("header-two-text").textContent = "";
document.getElementById("content-two-text").textContent = "";
document.getElementById("content-three-text").textContent = "";
document.getElementById("link-text").textContent = "View transaction in Block Explorer";
document.getElementById("link-text").href = "https://explorer.chainweb.com/mainnet/tx/" + tx.requestKeys[0];
}
} catch(e){
console.log(e)
document.getElementById("header-text").textContent = "Waiting Timed out, but your tx was sent. Look up Below";
document.getElementById("content-text").textContent = tx.requestKeys[0];
document.getElementById("spinner").classList.remove("active")
document.getElementById("header-two-text").textContent = "";
document.getElementById("content-two-text").textContent = "";
document.getElementById("content-three-text").textContent = "";
document.getElementById("link-text").textContent = "View transaction in Block Explorer";
document.getElementById("link-text").href = "https://explorer.chainweb.com/mainnet/tx/" + tx.requestKeys[0];
}
} catch(e){
document.getElementById("requestKey").classList.remove("hidden")
document.getElementById("header-text").textContent = "Transaction was Rejected";
document.getElementById("spinner").classList.remove("active")
document.getElementById("header-two-text").textContent = "";
document.getElementById("content-two-text").textContent = "";
document.getElementById("content-three-text").textContent = "";
document.getElementById("content-text").textContent = "Transaction was not sent to Blockchain. Check your keys or metadata"
}
}
const openModule = async function(){
try {
const response = await Pact.fetch.local({
pactCode: `(describe-module "chat-anon")`,
meta: Pact.lang.mkMeta("", "", 0.0001, 6000, creationTime(), 600)
}, host)
const result = response.result;
let text = result.data.code
document.getElementById("module-text").classList.add("active")
document.getElementById("module-name").innerText = result.data.message;
document.getElementById("module-code").innerText = text;
} catch(e){
console.log(e)
}
}
const closeModule = () => {
document.getElementById("module-text").classList.remove("active")
}
</script>
</head>
<body>
<div id="main">
<div id=anon-chat-container>
<div id="module-text" class="ui modal" >
<i id="module-close" class="close icon" onClick="closeModule()"></i>
<div class="header" id="module-name"></div>
<p class="content" id="module-code"></p>
</div>
</div>
<div class="ui raised very padded text container segment" id="container">
<h2 class="ui header" >Welcome to the Anonymous Kadena chat</h2>
<h3>Send your message anonymously through a gas station</h3>
<form class="ui form" id="input" onsubmit="return false">
<textarea placeholder="Your message" id="user-input" onkeyup="updateCharCount(this);" maxlength="1023" style="min-height:100px" rows="3"></textarea>
<button class="ui black right floated button" id="pay-gas">
Send
</button>
</form>
<div class="ui">
<br/>You've typed <span id="user-input-char-count">0</span> character(s).
<span id='user-input-char-count-message'>You are allowed lots more.</span>
</div>
<div class="ui">
Images from <em>i.imgur.com</em> domain are allowed and will automatically inline.
</div>
<div class="ui message hidden" id="requestKey">
<div id="header-text" class="header"></div>
<p id="content-text"></p>
<div id="spinner" class="ui centered inline loader"></div>
<div id="header-two-text" class="header"></div>
<p id="content-two-text"></p>
<p id="content-three-text"></p>
<a href="" id="link-text"></a>
</div>
<div class="ui large feed" id="feed-container">
<div class="event" id="feed-item">
</div>
</div>
</div>
</div>
</body>
<script>
function spoiler(elem) {
elem.classList.toggle('blur');
}
</script>
<script>
updateCharCount(document.getElementById('user-input'));
</script>
</html>