Skip to content

Instantly share code, notes, and snippets.

@aaronmccall
Created November 14, 2012 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronmccall/4072798 to your computer and use it in GitHub Desktop.
Save aaronmccall/4072798 to your computer and use it in GitHub Desktop.
Fitocracy helpers
var Totp = (function ($, _) {
var body = $(document.body),
btn = $('<button type="button" class="pill-btn red-btn" id="top_of_the_props">Top Proppers</button>'),
counts = {},
pub = {},
names = [],
template = "",
url = 'https://www.fitocracy.com/notifications/?start=0&end=1000000',
key, count, list, renderer;
// Set up the template and its renderer
template += '<li>' +
'<p class="notification-content">' +
'<a href="https://www.fitocracy.com/profile/<%= name %>/">' +
'<%= name %> has propped you <%= count %> times.' +
'</a>' +
'</p><br />' +
'</li>';
renderer = _.template(template);
function process_item() {
var li = $(this),
text = li.text().replace(/^\s+/g, '').replace(/\s+$/g, '');
if (!!~text.indexOf('props')) {
propper = text.split(' ').shift();
if (!counts[propper]) {
counts[propper] = 0;
names.push(propper);
}
counts[propper] += 1;
}
}
pub.init = function () {
btn.css({
position: "absolute",
top: "18px",
right: "50px"
});
body.prepend(btn);
btn.on('click', function (e) {
var $orig_modal = $('#view-all-notifications'),
$modal = $orig_modal.clone(true),
$modal_h2 = $modal.find('h2'),
$modal_content = $modal.find('.modal_contents');
$modal.attr('id','top_proppers').css('height', '400px');
$orig_modal.after($modal);
$modal_h2.text('Proper Proppers');
$modal_content.empty();
$modal_content.append('<p style="text-align:center;"><img src="https://s3.amazonaws.com/static.fitocracy.com/site_media/images/ajax-loader.gif" /></p>');
$modal.show();
$modal.center(0);
e.preventDefault();
$.get(url, function (list_html) {
btn.find('img').remove();
var list = $(list_html),
$ul = $('<ul/>'),
proppers = [];
list.each(process_item);
// Sort names by prop count in descending order
names.sort(function (a, b) {
if (counts[a] && counts[b]) return counts[b] - counts[a];
return 0;
});
names.slice(0, 20).forEach(function (name) {
proppers.push(renderer({name: name, count: counts[name]}));
});
$ul.html(proppers.join("\n"));
$modal_content.empty();
$modal_content.append($ul);
});
});
};
return pub;
})(window.jQuery, window._);

Make a new empty bookmark/favorite and paste this in the address/url field:

javascript:(function($){ $ && $('.stream_item').not('[data-ag-type="workout"]').remove() })(window.jQuery);

@aaronmccall
Copy link
Author

javascript:(function($){ $ && $('.stream_item').not('[data-ag-type="workout"]').remove() })(window.jQuery);) is the relevant part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment