Skip to content

Commit

Permalink
adding approved/rejected
Browse files Browse the repository at this point in the history
  • Loading branch information
SteakOverCooked authored and SteakOverCooked committed Feb 1, 2018
1 parent 926fc37 commit 84d4d27
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 21 deletions.
107 changes: 96 additions & 11 deletions js/utopian.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
'use strict';

const validId = (id) => {
id = id.trim();
let pat = /^[a-z0-9\-\.]+$/g;
return id && pat.test(id);
}

const getChromeVersion = () => {
var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
return raw ? parseInt(raw[2], 10) : false;
Expand Down Expand Up @@ -157,20 +163,80 @@ function updateModerators(api) {
},
complete: function(data) {
logit("API Finished: Moderators.");
$('img#loading-chart').hide();
$('img#loading-moderators').hide();
}
});
}

function getVP(id) {
function getModeratorStats(api) {
let api_approved = api + "&status=reviewed";
let api_rejected = api + "&status=flagged";
logit("calling " + api_approved);
$.ajax({
type: "GET",
url: api_approved,
success: function(result) {
let approved_cnt = result.total;
logit("calling " + api_rejected);
$.ajax({
type: "GET",
url: api_rejected,
success: function(result) {
let rejected_cnt = result.total;
let s = "<h4>Your Approved/Rejected Stats</h4>";
s += "<ul>";
s += "<li>Approved: <B>" + approved_cnt + "</B></li>";
s += "<li>Rejected: <B>" + rejected_cnt + "</B></li>";
s += "</ul>";
$('div#moderators_stats').html(s);
let data = [];
data.push({"status": "approved", "count": approved_cnt});
data.push({"status": "rejected", "count": rejected_cnt});
let chart = AmCharts.makeChart( "chart_moderators", {
"type": "pie",
"theme": "light",
"dataProvider": data,
"startDuration": 0,
"valueField": "count",
"titleField": "status",
"balloon":{
"fixedPosition": true
},
"export": {
"enabled": false
}
});
},
error: function(request, status, error) {
logit('Response: ' + request.responseText);
logit('Error: ' + error );
logit('Status: ' + status);
},
complete: function(data) {
logit("API Finished: Get Rejected Number.");
}
});
},
error: function(request, status, error) {
logit('Response: ' + request.responseText);
logit('Error: ' + error );
logit('Status: ' + status);
},
complete: function(data) {
logit("API Finished: Get Approved Number.");
}
});
}

function getVP(id, dom) {
let api = 'https://helloacm.com/api/steemit/account/vp/?id=' + id;
logit("calling " + api);
$.ajax({
type: "GET",
url: api,
success: function(result) {
let dom = $('div#account_vp');
dom.html("<i>Your Voting Power is</i> <B>" + result + "%</B>");
dom.html("<i>@" + id + "'s Voting Power is</i> <B>" + result + "%</B>");
if (result < 30) {
dom.css("background-color", "red");
} else if (result < 60) {
Expand All @@ -186,28 +252,27 @@ function getVP(id) {
logit('Status: ' + status);
},
complete: function(data) {
logit("API Finished: VP.");
logit("API Finished: VP + " + id);
}
});
}

function getRep(id) {
function getRep(id, dom) {
let api = 'https://helloacm.com/api/steemit/account/reputation/?id=' + id;
logit("calling " + api);
$.ajax({
type: "GET",
url: api,
success: function(result) {
let dom = $('div#account_rep');
dom.html("<i>Your Reputation is</i> <B>" + result + "</B>");
dom.html("<i>@" + id + "'s Reputation is</i> <B>" + result + "</B>");
},
error: function(request, status, error) {
logit('Response: ' + request.responseText);
logit('Error: ' + error );
logit('Status: ' + status);
},
complete: function(data) {
logit("API Finished: Reputation.");
logit("API Finished: Reputation - " + id);
}
});
}
Expand All @@ -224,29 +289,49 @@ document.addEventListener('DOMContentLoaded', function() {
if (utopian["steemit_id"]) {
let id = utopian["steemit_id"].trim();
$('input#steemit_id').val(id);
if (id != '') {
getVP(id);
getRep(id);
if (validId(id)) {
getVP(id, $("div#account_vp"));
getRep(id, $("div#account_rep"));
getModeratorStats("https://api.utopian.io/api/posts?moderator=" + id + "&skip=0&limit=1");
}
}
if (utopian["steemit_website"]) {
let website = utopian["steemit_website"].trim();
$('select#steemit_website').val(website);
}
if (utopian["friends"]) {
let friends = utopian["friends"].trim();
$('textarea#friends').val(friends);
friends = friends.split("\n");
let len = friends.length;
for (let i = 0; i < len; ++ i) {
let id = friends[i];
if (validId(id)) {
$("div#friends_vp_rep").append("<div id='account_vp_100_" + id + "' class='vpbar'><div id='account_vp_" + id + "' class='vp'> </div> </div><div id='account_rep_" + id + "'> </div>");
getRep(id, $('div#account_rep_' + id));
getVP(id, $('div#account_vp_' + id));
}
}
}
}
});
$('button#save_id_btn').click(function() {
let id = $('input#steemit_id').val().trim();
let website = $('select#steemit_website').val();
let friends = $('textarea#friends').val();
let utopian = {};
utopian['steemit_id'] = id;
utopian['steemit_website'] = website;
utopian['friends'] = friends;
chrome.storage.sync.set({
utopian_settings: utopian
}, function() {
alert('Saved.');
});
});
// utopian-io
getVP("utopian-io", $("div#account_utopian_vp"));
getRep("utopian-io", $("div#account_utopian_rep"));
// about
let manifest = chrome.runtime.getManifest();
let app_name = manifest.name + " v" + manifest.version;
Expand Down
33 changes: 23 additions & 10 deletions utopian-ext-main.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
.ext-window {width: 600px;}
textarea {width: 100%;}
img {max-width: 100%;}
#chartdiv_moderators_count, #chartdiv, #chartdiv_moderators_total_paid {width: 100%; height: 550px;}
#account_vp_100 {width: 100%; background-color: grey;}
#account_vp {color: white;}
.chart {width: 100%; height: 550px;}
.vpbar {width: 100%; background-color: grey;}
.vp {color: white;}
</style>
</head>
<body>
Expand All @@ -33,14 +33,18 @@
<li><a href="#tabs-general">General</a></li>
<li><a href="#tabs-shortcuts">Short Cuts</a></li>
<li><a href="#tabs-moderators">Moderators</a></li>
<li><a href="#tabs-chart">Chart</a></li>
<li><a href="#tabs-setting">Setting</a></li>
<li><a href="#tabs-log">Log</a></li>
</ul>
<div id="tabs-general">
<img id='loading' src='images/loading.gif' />
<div id='account_vp_100'> <div id='account_vp'> </div> </div>
<div id='account_rep'> </div>
<div id='chartdiv'> </div>
<div id='account_vp_100' class="vpbar"> <div id='account_vp' class="vp"> </div> </div>
<div id='account_rep'> </div>
<div id='account_vp_utopian_100' class="vpbar"> <div id='account_utopian_vp' class="vp"> </div> </div>
<div id='account_utopian_rep'> </div>
<div id='friends_vp_rep'> </div>
<div id='chartdiv' class="chart"> </div>
</div>
<div id="tabs-shortcuts">
<ul>
Expand All @@ -63,11 +67,16 @@
<div id="tabs-moderators">
<img id='loading-moderators' src='images/loading.gif' />
<div id="moderators"> </div>
<div id="moderators_stats"> </div>
<div id='chart_moderators' class="chart"> </div>
</div>
<div id="tabs-chart">
<img id='loading-chart' src='images/loading.gif' />
<h4>Top Moderators by total_moderated</h4>
<div id='chartdiv_moderators_count'> </div>
<div id='chartdiv_moderators_count' class="chart"> </div>
<h4>Top Moderators by total_paid_steem</h4>
<div id='chartdiv_moderators_total_paid'> </div>
</div>
<div id='chartdiv_moderators_total_paid' class="chart"> </div>
</div>
<div id="tabs-setting">
<p><h4>Your SteemId ID: </h4><input type='text' class='form-control' id='steemit_id' name='steemit_id' value=''></p>
<p>
Expand All @@ -77,7 +86,11 @@ <h4>Alt + S: </h4>
<option value='busy.org'>busy.org</option>
</select>
</p>
<p><button class='form-control' style='width:70px' id='save_id_btn'>Save</button></p>
<p>
<h4>Additional ID's (Tab General)</h4>
<textarea class="form-control" id="friends" placeholder="Enter Your Friends' IDs one ID per line" rows=10></textarea>
</p>
<p><button class='form-control' style='width: 70px' id='save_id_btn'>Save</button></p>
</div>
<div id="tabs-log">
<h4>Proudly brought to you by <a target=_blank href="https://steemit.com/@justyy">@justyy</a></h4>
Expand Down

0 comments on commit 84d4d27

Please sign in to comment.