-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
182 lines (124 loc) · 7.23 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<h1 id="UserHeader"></h1>
<title>Community Disperser!</title>
<ul id="UserSteemData"><h1>User Information:</h1></ul>
<h1 id="NodeData"></h1>
<center>
<style>
#result_zone strong {
color: white;
background-color: black;
padding: 2px;
}
body {
border-style: double;
}
#credits {
color: white;
background-color: green;
margin: 5px;
}
#NodeData {
margin: 20px;
background-color: green;
}
</style>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="https://cdn.steemjs.com/lib/latest/steem.min.js"></script>
</head>
<body>
<img src="./steemthirdparty.png"></img>
<h1>Community Disperser!</h1>
<p>The username list does not need @ symbols for usernames also remove any spaces and use , to seperate them.</p>
<h2>Example:</h2>
<p>giftedgaia,papa-pepper,good-karma,winstonwolfe</p>
<form action="/" method="post" id="userlist_form">
<input type="text" name="message" id="message" placeholder="Users to send to..." size="50" autofocus />
<input type="text" name="amount" id="amount" placeholder="The amount of steem to send to every user..." size="40" autofocus />
<input type="text" name="memo" id="memo" placeholder="The memo to include with every transfer..." size="40" autofocus />
<input type="submit" id="send_message" value="Send" />
</form>
<section id="result_zone">
</section>
</center>
<br/>
<br/>
<p id="credits">Big appreciation to Fabien @adcpm for the steem js library: https://www.npmjs.com/package/steem</p>
<script>
// The username and activekey is requested, stored in the var username and displayed in the title
var username = prompt('What\'s your username?');
//steem activekey is requested and stored in var activekey this means it is only local cache and when this page is cache cleared the activekey is gone.
var activekey = prompt('What\'s your active key?');
document.title = username + ' - ' + document.title;
//Set the websocket to be used for the script.
steem.config.set('websocket','wss://steemd.steemit.com');
//Ping the node for the latest block, this help verify connectivity.
steem.api.streamBlockAsync(function(err, t) {
$('#NodeData').replaceWith("<p id='NodeData'>Current block time is: " + t.timestamp + " The Node you are on is: wss://steemd.steemit.com" + "</p>");
})
//Check the steem username provided and pull its info if it is real, otherwise drop and error on the screen about it.
steem.api.getAccounts([username], function(err, response){
if(response[0] != null) {
$('#UserSteemData').append('<li>' + "Username: " + response[0].name + '</li>');
$('#UserSteemData').append('<li>' + "Memo Key: " + response[0].memo_key + '</li>');
$('#UserSteemData').append('<li>' + "Steem Balance: " + response[0].balance + '</li>');
}
else {
$('#result_zone').prepend('<p><em>' + "That is not a valid username, please use your steem username. " + err + '</em></p>');
};
});
// When the form is fired, the results are validated and then displayed on the page.
$('#userlist_form').submit(function () {
//Message is the list of users that will be sent to, it is a comma seperated list with no spaces.
var message = $('#message').val();
//amount is the amount of steem to send to every user.
var amount = $('#amount').val();
//memo is the message to attach to the transaction.
var memo = $('#memo').val();
//because it is possible to send both sbd and steem we need to specify that we want to send steem in the transaction.
var TOKEN = " STEEM";
//here we display on the screen all of the input that was just fired in an uncompressed format.
//this is likely extreneous and can be removed in the future, but it is good for debugging for the time being.
insertMessage(username, message, amount, memo);
// Empties the input forms and puts the focus back on the message input field.
$('#amount').val('');
$('#memo').val('');
$('#message').val('').focus();
//here we set up our list of users and split it based on the commas.
var userdispersallist = message.split(',');
//here we iterate over the list of users and perform our needed ops.
$.each(userdispersallist, function (index, value){
/*steem.broadcast.transfer(activekey, username, "steemstars-gtc", "1.000 STEEM", "testing", function(err, result) {
console.log(err, result);
});*/
//first we need to check if each of these user name are real steem usernames and if they are not feed back what ones are not.
steem.api.lookupAccountNames([value], function(err, lookupresult) {
console.log(err, lookupresult);
//once we get a response on the user we can move on and fire the transaction.
if(lookupresult[0] != null ) {
steem.broadcast.transfer(activekey, username, value, amount.concat(TOKEN), memo, function(err, transferresult)
{
console.log(activekey, username, value, amount.concat(TOKEN), memo);
console.log(transferresult, err);
//drop all of the info on each transaction into the window so that we can see the results.
$('#result_zone').prepend('<p><em>' + value + " " + transferresult + err + '</em></p>');
});
}
else{
$('#result_zone').prepend('<p><em>' + "Something went wrong, likely this username is not real: " + value + err + '</em></p>');
};
});
});
// Blocks 'classic' sending of the form
return false;
});
//Adds a message to the page
function insertMessage(username, message, amount, memo) {
$('#result_zone').prepend('<p><strong>' + username + '</strong> ' + message + " " + amount + " " + memo + '</p>');
};
</script>
</body>
</html>