This repository has been archived by the owner on May 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.html
682 lines (378 loc) · 15.1 KB
/
publish.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
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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
<!DOCTYPE html>
<html>
<head>
<!-- Standard Meta -->
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<!-- Site Properties -->
<link rel="icon" type="image/x-icon" href="/assets/img/favicon.ico">
<title>Publish to Steem</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.css" />
<link rel="stylesheet" href="/assets/css/custom.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/components/visibility.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/components/sidebar.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/components/transition.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.8.6/showdown.min.js"></script>
<script src="/assets/scripts/timeago.js"></script>
<script src="https://cdn.steemjs.com/lib/latest/steem.min.js"></script>
<script src="https://steemit.github.io/sc2-angular/sc2.min.js"></script>
<link href="https://cdn.quilljs.com/1.3.5/quill.snow.css" rel="stylesheet">
<!-- Include the Quill library -->
<script src="https://cdn.quilljs.com/1.3.5/quill.js"></script>
</head>
<body>
<div id="navbar"></div>
<br/><br/>
<br/><br/>
<br/><br/>
<div class="ui container">
<div class="ui feed">
<div class="event">
<div class="label">
<img id="account_img" src="">
</div>
<div class="content">
<div class="summary">
<a id="user_account"></a>
<div class="date">
Publish
</div>
<div class="ui active inline tiny loader" id="spinner"></div>
</div>
</div>
</div>
</div>
<div class="ui dropdown">
<i class="sidebar icon"></i>
<div class="text">View</div>
<i class="dropdown icon"></i>
<div class="menu">
<a class="item" id="account_btn">
<i class="user icon"></i>
Account
</a>
<a class="item" id="wallet_btn">
<i class="dollar icon"></i>
Wallet
</a>
</div>
</div>
</div>
<br/>
<div class="ui divider"></div>
<br/><br/>
<div class="ui stackable grid container">
<div class="row">
<div class="ten wide column">
<!-- top questions -->
<div class="ui container">
<div style="" id="overview">
<div class="ui raised segment">
<a class="ui red ribbon label">Prepare your post</a>
<br/>
<br/>
<form id="form" class="ui form">
<div class="field">
<label>Enter title of your post</label>
<input type="text" id="post-title" placeholder="Enter title of post">
</div>
<div class="field">
<div id="editor">
<br/>
<br/>
<br/>
<br/>
<h1> Just another awesome post...</h1>
<br/>
<br/>
<br/>
<br/>
</div>
</div>
<div class="two fields">
<div class="four wide field">
<div class="field">
<label>Default category</label>
<input placeholder="peerquery" readonly="" type="text">
</div>
</div>
<div class="twelve wide field">
<div class="field">
<label>Relevant tags(only alpha-numeric characters)</label>
<input type="text" id="post-tags" placeholder="proposal contest question quiz gig">
</div>
</div>
</div>
<div class="ui button" tabindex="0" onClick="publish()">Publish</div>
</form>
<br/>
</div>
</div>
</div>
</div>
<!-- end of top questions -->
<div class="six wide right floated column">
<!-- Top earners -->
<div class="ui container">
<div class="ui segment">
<div class="ui top attached label" id="title"></div>
<a class="ui orange right ribbon label" id="lastpost" target="_blank">Previous post</a>
<div class="ui active centered inline loader" id="spinner2" style=""></div>
<br/>
<div id="lastpost-div" style="display:none">
<div class="ui pointing below label">
<span id="lastpost_time" class="timeago"></span> in
<a class="ui red horizontal label" id="lastpost_tag" target="_blank"></a>
</div>
<div class="ui segment">
<br/>
<p id="body"></p>
<div class="ui top right attached label">Summary</div>
</div>
<div class="ui mini three statistics">
<div class="ui mini statistic">
<div class="value">
<span id="votes"></span>
</div>
<div class="label">
Votes
</div>
</div>
<div class="ui mini statistic">
<div class="value">
<span id="earned"></span>
</div>
<div class="label">
Earned
</div>
</div>
<div class="ui mini statistic">
<div class="value">
<span id="responses"></span>
</div>
<div class="label">
Talks
</div>
</div>
</div>
<div class="ui segment" id="comment-div" style="display:none">
<br/>
<p id="comment"></p>
<div class="ui top right attached label">Top Comment with <span id="responses_votes"></span></div>
<a class="ui image label" id="responder_href" target="_blank">
<img src="" id="responder_img">
<span id="top_responder"></span>
</a>
</div>
</div>
</div>
</div>
<!-- end of top earners -->
</div>
</div>
</div>
<br/><br/>
<div id="footer"></div>
<script>
//
$("#navbar").load("/navbar.html"); //load the footer!!!
$("#footer").load("/footer.html"); //load the footer!!!
var converter = new showdown.Converter();
steem.api.setOptions({ url: 'https://api.steemit.com' });
var toolbarOptions = [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block', 'link', 'image'],
[{ 'header': 1 }, { 'header': 2 }], // custom button values
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
[{ 'script': 'sub'}, { 'script': 'super' }], // superscript/subscript
[{ 'indent': '-1'}, { 'indent': '+1' }], // outdent/indent
[{ 'direction': 'rtl' }], // text direction
[{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
[{ 'font': [] }],
[{ 'align': [] }],
['clean'] // remove formatting button
];
var quill = new Quill('#editor', {
modules: {
toolbar: toolbarOptions
},
placeholder: 'Prepare your post here...',
theme: 'snow'
});
var toolbar = quill.getModule('toolbar');
toolbar.addHandler('image', function() {
var range = this.quill.getSelection();
var value = prompt('What is the image URL');
this.quill.insertEmbed(range.index, 'image', value, Quill.sources.USER);
});
//get the Cookie: SC2A
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
if (readCookie("SC2A") == null) window.location.href = "/";
//var authString = document.cookie.substring(15);
//if (authString.indexOf(';') > -1) authString = authString.substr(0, authString.indexOf(';'));
var aInfo = readCookie("SC2A");
aInfo = window.atob(aInfo);
aInfo = JSON.parse(aInfo);
//console.log(authInfo);
var aToken = aInfo.access_token;
sc2.setAccessToken(aToken);
//expiresIn = authInfo.expires_in;
var author = aInfo.username;
$(document).ready(function(){
//console.log(author);
author = author;
document.getElementById("account_btn").href = "/@" + author;
document.getElementById("wallet_btn").href = "/@" + author + "/wallet";
document.getElementById("user_account").innerText = author.toUpperCase();
document.getElementById("user_account").href = "/@" + author;
document.getElementById("account_img").src = "https://img.busy.org/@" + author;
document.getElementById("spinner").style.display = "none";
steem.api.getDiscussionsByAuthorBeforeDate(author, null, new Date().toISOString().split('.')[0], 1 , function(err, result) {
//console.log(result);
var result = result[0];
document.getElementById("earned").innerText = "$" + Math.max(Number(result.pending_payout_value.split(' ')[0]), Number(result.total_payout_value.split(' ')[0]) + Number(result.curator_payout_value.split(' ')[0])).toFixed().toLocaleString();
document.getElementById("responses").innerText = result.children;
document.getElementById("votes").innerText = result.net_votes.toLocaleString();
document.getElementById("title").innerText = result.title;
document.getElementById("lastpost_tag").href = "/tag/" + result.parent_permlink;
document.getElementById("lastpost_tag").innerText = result.category;
document.getElementById("lastpost_time").title = result.created;
var md = result.body;
var html = converter.makeHtml(md);
var tmp = document.createElement('div');
tmp.innerHTML = html;
var summary = tmp.innerText.replace(/\W+/g, " ");
summary = summary.substr(0, 200) + " ...";
document.getElementById("body").innerText = summary;
document.getElementById('lastpost').href = "/" + result.category + "/@" + result.author + "/" + result.permlink;
steem.api.getContentReplies(result.author, result.permlink, function(err, result) {
//console.log(err, result);
if (result[0] !== undefined || null) {
var newarray = result.sort(function(a, b){
return b.net_votes - a.net_votes;
})
document.getElementById('responses_votes').innerText = newarray[0].net_votes.toLocaleString() + " votes!";
//console.log(newarray);
var md = newarray[0].body;
var html = converter.makeHtml(md);
var tmp = document.createElement('div');
tmp.innerHTML = html;
var summary = tmp.innerText.replace(/\W+/g, " ");
summary = summary.substr(0, 250) + " ...";
document.getElementById("comment").innerText = summary;
document.getElementById("responder_img").src = "https://img.busy.org/@" + newarray[0].author;
document.getElementById("responder_href").href = "/@" + newarray[0].author;
document.getElementById("top_responder").innerText = newarray[0].author + "(" + steem.formatter.reputation(newarray[0].author_reputation) + ")";
document.getElementById("spinner2").style.display = "none";
document.getElementById("lastpost-div").style.display = "block";
document.getElementById("comment-div").style.display = "block";
}
document.getElementById("spinner2").style.display = "none";
document.getElementById("lastpost-div").style.display = "block";
});
timeAgo();
});
});
function publish() {
//alert(quill.root.innerHTML);
//publish function goes here
var qTitle = document.getElementById('post-title').value;
if (qTitle == "") { alert('Enter title'); document.getElementById('post-title').focus(); return };
var qBody = quill.root.innerHTML;
if (qBody == "<p><br></p>") { alert('Enter post body'); return; };
var qAuthor = author;
var qCategory = "peerquery";
var qlink = qTitle.replace(/\W+/g, " ");
var qPermlk = qlink.replace(/\s+/g, '-');
var qPlink = qPermlk.toLowerCase();
var qPermlink = qPlink.replace(/^[^a-z\d]*|[^a-z\d]*$/gi, '');
var tagStr = document.getElementById('post-tags').value;
if (tagStr == "") { alert("Enter atleast one tag"); document.getElementById('post-tags').focus(); return;} ;
var tagStrg = tagStr.toLowerCase();
//var tagStrng = tagStrg.replace(/^[^a-z\d]*|[^a-z\d]*$/gi, '');
var tagString = tagStrg.replace(/\W+/g, " ");
var tags = tagString.split(" ", 3);
tags.unshift(qCategory);
document.getElementById('form').className = "ui loading form";
var n = qTitle.length;
if(n == 1) { alert("Please enter a longer title!"); document.getElementById('form').className = "ui form"; return; };
function test_permlink() {
//console.log("working");
steem.api.getContent(author, qPermlink, function(err, result) {
//console.log(err, result);
n = n -1;
//console.log(n);
if (result.author != "") {
//if(n == 1) { alert("Please change the title"); document.getElementById('form').className = "ui form"; return; };
var qTtle= qTitle.substr(0, n);
qlink = qTtle.replace(/\W+/g, " ");
qPermlk = qlink.replace(/\s+/g, '-');
qPlink = qPermlk.toLowerCase();
qPermlink = qPlink.replace(/^[^a-z\d]*|[^a-z\d]*$/gi, '');
test_permlink();
return;
} else {
//console.log(qCategory, qAuthor, qPermlink, qTitle, qBody, tags);
do_publish(qCategory, qAuthor, qPermlink, qTitle, qBody, tags);
}
});
}
test_permlink();
}
/*
function check_permlink(author, permlink) {
steem.api.getContent(author, permlink, function(err, result) {
//console.log(err, result);
if (result.author == "") {
return false;
} else {
return true;
}
});
}
*/
function do_publish(qCategory, qAuthor, qPermlink, qTitle, qBody, tags) {
sc2.comment(
'', // author, leave blank for new post
qCategory, // first tag
qAuthor, // username
qPermlink, // permlink
qTitle, // Title
qBody, // Body of post
// json metadata (additional tags, app name, etc)
{ tags: tags, app: 'peerquery' },
function (err, result) {
if (err) {
nErr = JSON.stringify(err.error_description);
//console.log(nErr);
if (nErr.indexOf("The comment is archived") > -1)
return alert("Post with the same permlink already exists and is archived, please change your permlink.");
if (nErr.indexOf("You may only post once every 5") > -1)
return alert("You may only post once every five minutes!");
return;
//throw err;
alert('Failure! ' + err);
document.getElementById('form').className = "ui form";
} else {
console.log('Success!');
window.location.href = qCategory + "/@" + author + "/" + qPermlink;
}
});
}
</script>
</body>
</html>