Last active
May 3, 2019 18:53
-
-
Save Ghostlyr/8cd78999afcdfc0d03a952d84ad48872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var login = 'Archie'; | |
var requests = []; | |
var page = 1; | |
var csrftoken = getCookie('csrftoken'); | |
var stats_type = 'current_month'; | |
var has_next = true; | |
window.getData = function () | |
{ | |
$.ajax({ | |
url: '/projects/' + window.project_id + '/statistics/' + stats_type + '/', | |
type: 'POST', | |
async: true, | |
data: { | |
page: page, | |
csrfmiddlewaretoken: csrftoken, | |
}, | |
dataType: 'json', | |
success: function (data) { | |
if (data.has_next) { | |
_(data.voters).each(function (voter) { | |
requests.push({ | |
nick_minecraft: voter.nick_minecraft.toLowerCase(), | |
votes_qty: voter.votes_qty, | |
last_vote_date: voter.last_vote_date, | |
}); | |
}); | |
page++; | |
getData(); | |
} else { | |
countData(); | |
} | |
}, | |
}); | |
console.log("Collecting data: " + requests.length); | |
} | |
window.countData = function () { | |
var count = 0; | |
requests.forEach(function (i) { | |
if (i.nick_minecraft.includes(login.toLowerCase())) { | |
count += i.votes_qty; | |
} | |
}); | |
// console.log(requests); | |
alert('Total votes from ' + login + ': ' + count); | |
} | |
getData(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment