Skip to content

Instantly share code, notes, and snippets.

@andershaig
Created September 3, 2013 19:07
Show Gist options
  • Save andershaig/6428204 to your computer and use it in GitHub Desktop.
Save andershaig/6428204 to your computer and use it in GitHub Desktop.
Stories Plugin to JS Object
var storiesToJSON = function (callback) {
var data = { "stories": [] };
var storiesAnswers = $('.stories_recent_activity li');
storiesAnswers.each( function (i, answer) {
var story = {};
story.image_url = $(this).find('.stories_user_image img').attr('src');
story.user_name = $(this).find('.stories_answer a').text();
story.user_link = $(this).find('.stories_answer a').attr('href');
// Remove the link now to get just the answer
$(this).find('.stories_answer a').remove();
story.answer = $(this).find('.stories_answer').text().replace(':', '');
story.time_ago = $(this).find('.stories_time_ago').text();
data.stories.push(story);
});
if (callback && typeof(callback) === 'function') {
callback(data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment