-
Notifications
You must be signed in to change notification settings - Fork 0
/
followerchecker.html
415 lines (379 loc) · 22.7 KB
/
followerchecker.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
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://github.com/steemit/steem-js/releases/download/v0.7.7/steem.min.js"></script>
<title>Follower Checker</title>
<script>
let username;
let storage_username;
let defaultHtml = '<div style="height:150px; padding-top:55px;padding-bottom:55px;"><button type="button" class="btn btn-success" style="margin:3px;">followers: 0</button><button type="button" class="btn btn-warning" style="margin:3px;">unfollowers: 0</button></div>';
window.onload = function() {
storage_username = localStorage.getItem("username");
let previous_count = localStorage.getItem("follower_count");
previous_count = previous_count === null ? 0 : previous_count;
$("#text_username").val(storage_username);
$("#past_sub").text("number of followers: " + previous_count);
steem.api.setOptions({url: 'https://api.steememory.com'});
getAccountCount();
getSteemPrice();
getVotingPowerPercent();
loadSelectBox();
};
function loadSelectBox(){
username = $("#text_username").val();
if(username === ""){
return;
}
steem.api.getDiscussionsByBlog({tag: username, limit: 20}, function(err, result) {
let text = "";
for(let i = 0; i < result.length; i++){
if(result[i].author === username){
text += '<option value="' + result[i].permlink+ '">' + result[i].title + '</option>';
}
}
if(result.length == 0) {
$("#selectPerm").html("");
$("#votingListButton").text("");
$("#votingListButton").val("");
return;
}
$("#selectPerm").html(text);
getVoting("SBD");
});
}
function getAccountCount(){
steem.api.getAccountCount(function(err, result) {
$("#steemitUser").text(result);
});
}
function getSteemPrice() {
//steem.api.getCurrentMedianHistoryPrice(function(err, result) {
// let steemPrice = parseFloat(result.base.replace(" SBD"));
steem.api.getFeedHistory(function(err, result) {//2023.10.05
let steemPrice = parseFloat(result.price_history[83].base.replace(" SBD"));//2023.10.05
$("#steemPrice").text("$" + steemPrice);
});
}
async function getFullPowerSBD() {
$("#userSP").text("");
$("#votingSBD").text("");
let username = $("#text_username").val();
//let steemPrice = await steem.api.getCurrentMedianHistoryPriceAsync();
//steemPrice = parseFloat(steemPrice.base.replace(" SBD"));
//steemPrice = parseFloat(steemPrice.base.replace(" SBD")) / steemPrice = parseFloat(steemPrice.quote.replace(" STEEM"));//2023.10.05
let result = await steem.api.getFeedHistoryAsync();//2023.10.05
let steemPrice = parseFloat(result.price_history[83].base.replace(" SBD"));//2023.10.05
let accounts = await steem.api.getAccountsAsync([username]);
if(accounts.length == 0) {return;}
let item = accounts[0];
// RSHARE
let globalProperties = await steem.api.getDynamicGlobalPropertiesAsync();
let total_vesting_shares = parseFloat(globalProperties.total_vesting_shares.replace(" VESTS", ""));
let total_vesting_fund_steem = parseFloat(globalProperties.total_vesting_fund_steem.replace(" STEEM", ""));
let sumVestingShare = parseFloat(item.vesting_shares.replace(" VESTS", "")) + parseFloat(item.received_vesting_shares.replace(" VESTS", "") - parseFloat(item.delegated_vesting_shares.replace(" VESTS", "")));
let sp = (sumVestingShare / total_vesting_shares * total_vesting_fund_steem);
let vp = item.voting_power + (10000 * ((new Date - new Date(item.last_vote_time + "Z")) / 1000) / 432000);
let votingWeight = 100;
let power = sp / (total_vesting_fund_steem / total_vesting_shares);
let voting = ((100 * vp * (100 * votingWeight) / 10000) + 49) / 50;
let rshare = power * voting;
let fund = await steem.api.getRewardFundAsync('post');
let sbd = rshare * (parseFloat(fund.reward_balance.replace(" STEEM","")) / fund.recent_claims) * steemPrice;
$("#userSP").text(sp.toFixed(2) + " SP");
$("#votingSBD").text("$" + sbd.toFixed(2));
}
function getVotingPowerPercent(){
$("#timeLeft").text(" ");
$("#votingPowerP").text(" ");
let username = $("#text_username").val();
steem.api.getAccounts([username], function(err, response){
if(response.length == 0) return;
let secondsago = (new Date - new Date(response[0].last_vote_time + "Z")) / 1000;
let vpow = response[0].voting_power + (10000 * secondsago / 432000);
let secondsLeft = (10000 - vpow) * 432000 / 10000;
vpow = Math.min(vpow / 100, 100).toFixed(2) + "%";
$("#votingPowerP").text(vpow);
if(secondsLeft > 0){
let minutesLeft = ((secondsLeft % 3600) / 60).toFixed();
let hoursLeft = Math.floor(secondsLeft / 3600);
if(minutesLeft < 10) {minutesLeft = "0" + minutesLeft};
let timeLeft = hoursLeft > 0 ? hoursLeft + ":" + minutesLeft : minutesLeft + "min";
$("#timeLeft").text(timeLeft);
}
});
getFullPowerSBD();
}
async function getSteemPower(ids){
let globalProperties = await steem.api.getDynamicGlobalPropertiesAsync();
let total_vesting_shares = parseFloat(globalProperties.total_vesting_shares.replace(" VESTS", ""));
let total_vesting_fund_steem = parseFloat(globalProperties.total_vesting_fund_steem.replace(" STEEM", ""));
console.log(total_vesting_shares + " " + total_vesting_fund_steem);
let accounts = await steem.api.getAccountsAsync(ids);
let retObj = {};
accounts.map(function(item, index){
let sumVestingShare = parseFloat(item.vesting_shares.replace(" VESTS", "")) + parseFloat(item.received_vesting_shares.replace(" VESTS", "") - parseFloat(item.delegated_vesting_shares.replace(" VESTS", "")));
let sp = (sumVestingShare / total_vesting_shares * total_vesting_fund_steem).toFixed(0);
retObj[item.name] = {"vesting_shares": item.vesting_shares.replace(" VESTS", ""),
"received_vesting_shares":item.received_vesting_shares.replace(" VESTS", ""),
"delegated_vesting_shares":item.delegated_vesting_shares.replace(" VESTS", ""),
"SP": sp};
})
return retObj;
}
async function getVoting(orderby){
let link = $("#selectPerm").val();
username = $("#text_username").val();
//let steemPrice = await steem.api.getCurrentMedianHistoryPriceAsync();
//steemPrice = parseFloat(steemPrice.base.replace(" SBD"));
//steemPrice = parseFloat(steemPrice.base.replace(" SBD")) / parseFloat(steemPrice.quote.replace(" SBD"));//2023.10.05
let result1 = await steem.api.getFeedHistoryAsync();//2023.10.05
let steemPrice = parseFloat(result1.price_history[83].base.replace(" SBD"));//2023.10.05
let fund = await steem.api.getRewardFundAsync('post');
let replies = await steem.api.getContentRepliesWithAsync({author:username, permlink:link});
replies = replies.map(function(item, index){
return item.author;
});
let result = await steem.api.getActiveVotesAsync(username, link);
let objectArray = [];
let ids = result.map(function(item, index){
return item.voter;
})
let sparray = await getSteemPower(ids);
for(let i = 0; i < result.length; i++){
let id = result[i].voter;
let sbd = steemPrice * result[i].rshares * (parseFloat(fund.reward_balance.replace(" STEEM","")) /fund.recent_claims);
let percent = result[i].percent / 100;
let time = new Date(result[i].time).getTime();
objectArray.push({ID:id, SBD: sbd, PERCENT: percent, SP: sparray[id].SP, TIME:time});
}
sortByKey(objectArray, orderby);
let text = "";
for(let i = 0; i < objectArray.length; i++){
let item = "$" + objectArray[i].SBD.toFixed(3) + " " + objectArray[i].PERCENT + "% " + objectArray[i].ID + " (" + objectArray[i].SP + ")";
if(replies.includes(objectArray[i].ID)){
text += '<button class="dropdown-item" type="button" value="' + objectArray[i].ID + '" onclick="selectChanged(this);" style="background-color:#d1ffdb;">' + item + '</button>';
}else{
text += '<button class="dropdown-item" type="button" value="' + objectArray[i].ID + '" onclick="selectChanged(this);">' + item + '</button>';
}
if(i === 0){
$("#votingListButton").text(item);
$("#votingListButton").val(objectArray[i].ID);
}
}
$("#dropdownList").html(text);
}
function selectChanged(obj){
$("#votingListButton").text($(obj).text());
$("#votingListButton").val($(obj).val());
}
function sortByKey(array, key) {
return array.sort(function(a,b) { return b[key] - a[key];});
}
async function getSteemData(){
username = $("#text_username").val();
if(username === ""){
return;
}
$("#btn_check").css("background-color", "#256873").text("Loading...").prop('disabled', true);
storage_username = localStorage.getItem("username");
if(storage_username !== username){
localStorage.removeItem("username");
localStorage.removeItem("follower_count");
localStorage.removeItem("follower_list");
$("#result").html(defaultHtml);
loadSelectBox();
getVotingPowerPercent();
}
localStorage.setItem("username", username);
const result = await steem.api.getFollowCountAsync(username);
console.log(result);
if(result.follower_count == 0) {
$("#btn_check").css("background-color", "#205894").text("Check Now").prop('disabled', false);
return;
}
let allFollower = await getAllFollower(result.follower_count);
console.log("total: " + allFollower.length);
let previous_follower_count = localStorage.getItem("follower_count");
if(previous_follower_count === null){
$("#past_sub").text("number of followers: " + allFollower.length + " (↗0 ↘0)");
}else{
const allFollowing = await getAllFollowing(result.following_count);
displayResult(allFollower, allFollowing);
}
localStorage.setItem("follower_count", allFollower.length);
localStorage.setItem("follower_list", JSON.stringify(allFollower));
$("#btn_check").css("background-color", "#205894").text("Check Now").prop('disabled', false);
}
async function getAllFollowing(total_count) {
let retArray = [];
let current_count = 0;
let startFollowing = "";
while(true) {
let options = {follower: 'supergiant', startFollowing: startFollowing, followType: 'blog', limit: 100}
let result = await steem.api.getFollowingWithAsync(options);
let followingNum = result.length;
startFollowing = result[followingNum - 1].following;
if(followingNum > 99){
result.pop();
followingNum--;
}
let array = result.map(function(item, index){
return item.following;
})
retArray = retArray.length == 0 ? array : retArray.concat(array);
if(current_count + result.length < total_count){
current_count += followingNum;
}else{
break;
}
if(followingNum === 0){
break;
}
}
return retArray;
}
async function getAllFollower(total_count) {
let retArray = [];
let current_count = 0;
let startFollower = "";
while(true) {
let options = {following: username, startFollower: startFollower, followType: 'blog', limit: 1000}
let result = await steem.api.getFollowersWithAsync(options);
let followerNum = result.length;
startFollower = result[followerNum - 1].follower;
if(followerNum > 999){
result.pop();
followerNum--;
}
let array = result.map(function(item, index){
return item.follower;
})
retArray = retArray.length == 0 ? array : retArray.concat(array);
if(current_count + result.length < total_count){
current_count += followerNum;
}else{
break;
}
if(followerNum === 0){
break;
}
}
return retArray;
}
function displayResult(followers, followings){
let previous_follower_array = JSON.parse(localStorage.getItem("follower_list"));
let new_follower_array = [];
for(let i = 0; i < followers.length; i ++){
let index = previous_follower_array.indexOf(followers[i]);
if(index === -1){
new_follower_array.push(followers[i]);
}else{
previous_follower_array.splice(index,1);
}
}
let resultHtml = "";
for(let i = 0; i < new_follower_array.length; i++){
let text = followings.indexOf(new_follower_array[i]) === -1 ? new_follower_array[i] : new_follower_array[i] + " *";
let link = '<a class="btn btn-success" style="margin:3px;" href="https://steemit.com/@' + new_follower_array[i] + '" role="button" target="_blank">' + text + '</a>';
resultHtml += link;
}
for(let i = 0; i < previous_follower_array.length; i++){
let text = followings.indexOf(previous_follower_array[i]) === -1 ? previous_follower_array[i] : previous_follower_array[i] + " *";
let link = '<a class="btn btn-warning" style="margin:3px;" href="https://steemit.com/@' + previous_follower_array[i] + '" role="button" target="_blank">' + text + '</a>';
resultHtml += link;
}
if(new_follower_array.length == 0 && previous_follower_array.length == 0){
$("#result").html(defaultHtml);
}else{
$("#result").html(resultHtml);
}
$("#past_sub").text("number of followers: " + followers.length + " (↗" + new_follower_array.length + " ↘" + previous_follower_array.length + ")");
console.log("Recent followers: " + new_follower_array.length + " Recent unfollowers: " + previous_follower_array.length);
}
function moveToPost(){
let username = $("#text_username").val();
let link = $("#selectPerm").val();
if(link === null) {
return;
}
let href="https://steemit.com/@" + username + "/" + link;
window.open(href, "_blank");
}
function moveToBlog(){
let username = $("#votingListButton").val();
if(username === null) {
return;
}
let href="https://steemit.com/@" + username;
window.open(href, "_blank");
}
</script>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="container">
<div class="d-flex" style="font-size:small;">
<div class="mr-auto p-2">
<span class="p-2" id="steemitUser" onclick="getAccountCount();"></span>
<span class="" id="steemPrice" onclick="getSteemPrice();"></span>
</div>
<div class="p-2" onclick="getVotingPowerPercent();">
<span class="p-2" id="userSP"></span>
<span id="votingSBD"></span>
<span class="p-2" id="votingPowerP"></span>
<span id="timeLeft"></span>
</div>
</div>
<div class="card text-center">
<div class="card-header">
Follower Change Checker
</div>
<div class="card-body">
<h5 class="card-title">Make sure your friends have increased or decreased</h5>
<p id="past_sub" class="card-text">number of followers</p>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" onclick='getVoting("SBD");'>Username</span>
</div>
<input type="text" id="text_username" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" style="width:95px;" for="inputGroupSelect01" onclick='getVoting("TIME");'>Post</label>
</div>
<select class="custom-select" id="selectPerm" onchange='getVoting("SBD");'>
</select>
<div class="input-group-append">
<button type="button" class="btn btn-outline-secondary" onclick="moveToPost();">Go</button>
</div>
<button type="button" id="btn_check" class="btn btn-primary btn-lg btn-block" style="background-color:#205894; border-color:#205894; margin-top:10px;" onclick="getSteemData();">Check Now</button>
</div>
<h5 class="card-title">Follower Result</h5>
<div id="result" class="alert alert-primary" role="alert">
<div style="height:150px; padding-top:55px;padding-bottom:55px;">
<button type="button" class="btn btn-success">followers</button>
<button type="button" class="btn btn-warning">unfollowers</button>
</div>
</div>
<div class="input-group mb-3">
<button class="custom-select" style="text-align:left; overflow:hidden;" type="button" id="votingListButton" data-toggle="dropdown" aria-haspopup="false" aria-expanded="false"></button>
<div id="dropdownList" class="dropdown-menu" aria-labelledby="votingListButton" style="overflow:auto; max-height:30em; width:100%"></div>
<div class="input-group-append">
<button type="button" class="btn btn-outline-secondary" onclick="moveToBlog();">Go!</button>
</div>
</div>
</div>
<div class="card-footer text-muted">
follower checker by <a style="margin:3px;" href="https://steemit.com/@supergiant" target="_blank">@supergiant</a>
</div>
</div>
</div>
</body>
</html>