-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.htm
172 lines (167 loc) · 7.06 KB
/
index.htm
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Picker : Steem comment winner </title>
<meta name="description" content="steem comment picker to choose random winner for your contests and challenges">
<meta property="og:title" content="steem comment picker">
<meta property="og:site_name" content="pick.esteem.ws">
<meta property="og:description" content="steem comment picker to choose random winner for your contests and challenges">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/steem/dist/steem.min.js"></script>
<script src="./files/clipboard.min.js"></script>
<script type="text/javascript">
function getRandom(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
var author;var handle;
function loadpost(author,permlink, type){
steem.api.setOptions({ url: 'https://api.steemit.com' });
steem.api.getContentReplies(author, permlink, function(err, result) {
//console.log(err, result);
if (err) {
$("#count").html('Error occured! Try again!');
}
if (result) {
$("#count").html('Amount of unique commenters: '+result.length);
if (type === 'random') {
var rnd = getRandom(0, result.length);
$("#loader").fadeOut();
$("#source").html('Winner: \n'+result[rnd].author+'\n\nComment: \n'+result[rnd].body);
$("#links").html('https://steemit.com'+result[rnd].url);
$(".clipbtn").fadeIn();
$('#source').fadeIn();
$('#links').fadeIn();
} else if (type === 'voted') {
var max = 0;
var ind = 0;
for (var i = result.length - 1; i >= 0; i--) {
if (result[i].net_votes > max) {
max = result[i].net_votes;
ind = i;
}
}
$("#loader").fadeOut();
$("#source").html('Winner: \n'+result[ind].author+'\n\nComment: \n'+result[ind].body);
$("#links").html('https://steemit.com'+result[ind].url);
$(".clipbtn").fadeIn();
$('#source').fadeIn();
$('#links').fadeIn();
} else if (type === 'engaged') {
var max = 0;
var ind = 0;
for (var i = result.length - 1; i >= 0; i--) {
if (result[i].children > max) {
max = result[i].children;
ind = i;
}
}
$("#loader").fadeOut();
$("#source").html('Winner: \n'+result[ind].author+'\n\nComment: \n'+result[ind].body);
$("#links").html('https://steemit.com'+result[ind].url);
$(".clipbtn").fadeIn();
$('#source').fadeIn();
$('#links').fadeIn();
} else if (type === 'earned') {
var max = 0;
var ind = 0;
for (var i = result.length - 1; i >= 0; i--) {
if (Number(result[i].net_rshares) > max) {
max = Number(result[i].net_rshares);
ind = i;
}
}
$("#loader").fadeOut();
$("#source").html('Winner: \n'+result[ind].author+'\n\nComment: \n'+result[ind].body);
$("#links").html('https://steemit.com'+result[ind].url);
$(".clipbtn").fadeIn();
$('#source').fadeIn();
$('#links').fadeIn();
}
}
});
}
function openlinks(argument) {
var valu = $('#links').val();
window.open(valu, '_blank');
}
$(document).ready(function() {
new Clipboard('.clipbtn');
$("#permlink").submit(function(event) {
event.preventDefault();
$("#loader").fadeIn();
var handle = $("#permlinkstr").val();
if (handle.startsWith("@")){handle=handle.substr(1);}
handle = handle.split("/");
var author = handle[0];
var permlink = handle[1];
loadpost(author,permlink, 'random');
});
$("#submitbutton2").click(function(event){
event.preventDefault();
$("#loader").fadeIn();
var handle = $("#permlinkstr").val();
if (handle.startsWith("@")){handle=handle.substr(1);}
handle = handle.split("/");
var author = handle[0];
var permlink = handle[1];
loadpost(author,permlink, 'voted');
});
$("#submitbutton3").click(function(event){
event.preventDefault();
$("#loader").fadeIn();
var handle = $("#permlinkstr").val();
if (handle.startsWith("@")){handle=handle.substr(1);}
handle = handle.split("/");
var author = handle[0];
var permlink = handle[1];
loadpost(author,permlink, 'engaged');
});
$("#submitbutton4").click(function(event){
event.preventDefault();
$("#loader").fadeIn();
var handle = $("#permlinkstr").val();
if (handle.startsWith("@")){handle=handle.substr(1);}
handle = handle.split("/");
var author = handle[0];
var permlink = handle[1];
loadpost(author,permlink, 'earned');
});
$("#openlink").click(function(event){
openlinks();
});
});
</script>
<style type="text/css">
body {height:100%;text-align:center;}
#outerContainer {height:100%;width:80%;margin:0 auto;}
.logo {text-align:center;clear:both;margin:0 auto;height:100px;}
a {text-decoration:none;font-weight:bold;color:rgb(26, 80, 153);}
#permlinkstr {text-align:center;border : solid 2px #1e3e60;border-radius : 3px;moz-border-radius : 3px;font-size : 20px;color : #000; padding : 1px 17px; background-color : #fff; width:80%;}
#submitbutton, #submitbutton2, #submitbutton3, #submitbutton4, .clipbtn {border : solid 2px #ffffff;border-radius : 3px;moz-border-radius : 3px;font-size : 20px;color : #ffffff; padding : 1px 17px; background-color : #1e3e60;}
h1,h2,h3,h4,h5 {color:#1e3e60;}
#source {width:100%;display:none;height:100%;padding:5px;border-radius:3px;border:3px solid #1e3e60;}
#links {width:100%;display:none;height:100%;padding:5px;border-radius:3px;border:3px solid #1e3e60;}
pre,#log {white-space: pre-wrap;white-space: -moz-pre-wrap; white-space: -o-pre-wrap;}
#loader {display:none;}
.clipbtn {display:none;}
textarea {height:auto;}
</style>
</head><body>
<div id="outerContainer">
<a href="https://pick.esteem.ws"><img src="./files/logo.png" class="logo"></a><br><br>
<form id="permlink">
<input type="text" id="permlinkstr" name="permlink" value="good-karma/day-1-steem-advent-calendar-2017-win-prize-everyday-93dc41e1c99f4" placeholder="author/permlink"><br>
<input type="submit" id="submitbutton" value="Pick random winner">
<input type="submit" id="submitbutton2" value="Top voted">
<input type="submit" id="submitbutton3" value="Top engaged">
<input type="submit" id="submitbutton4" value="Top earned">
</form><br>
<span id='count'></span><br>
<textarea class="markup" id="source" rows="15"></textarea>
<textarea class="markup" id="links" rows="1"></textarea>
<div id="loader"><img src="./files/loader.gif"></div>
<button class="clipbtn" data-clipboard-target="#links">Copy link to clipboard</button>
<button class="clipbtn" id="openlink">Open comment</button>
</div>
</body></html>