Skip to content

Instantly share code, notes, and snippets.

@Rulexec
Created July 26, 2014 19:39
Show Gist options
  • Save Rulexec/b8d84f74693b34128b98 to your computer and use it in GitHub Desktop.
Save Rulexec/b8d84f74693b34128b98 to your computer and use it in GitHub Desktop.
// by Alexander Ruliov
// vk.com/alexander_ruliov
var jq = document.createElement('script');
jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// wait here
jQuery.noConflict();
(function(){
var posts = jQuery('tr.sortableTable-row', jQuery('table.sortableTable')[0]).map(function(){
return {
id: jQuery(this).attr('data-action-value'),
title: jQuery('.sortableTable-row-title h2', this).text()
};
}).toArray();
var left = posts.length;
var now = new Date().getTime(),
dayAgo = now - 1000 * 60 * 60 * 24;
var results = [];
posts.forEach(function(x){
jQuery.ajax('/me/stats/' + x.id + '/' + dayAgo + '/' + now, {
dataType: 'text',
success: function(data) {
var result = JSON.parse(data.slice(data.indexOf('{')));
var stats = result.payload.value;
var total = stats.reduce(function(acc, el) {
return acc + el.loggedInViews + el.loggedOutViews;
}, 0);
results.push({
post: x,
total: total
});
left--;
if (left === 0) {
showStats();
}
}
});
});
function showStats() {
results.sort(function(a, b) {
return b.total - a.total;
});
var grandTotal = 0;
results.forEach(function(x) {
console.log(x.post.title + ' — ' + x.total);
grandTotal += x.total;
});
console.log('GrAND TOTAL: ' + grandTotal);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment