Skip to content

Instantly share code, notes, and snippets.

@potch
Created July 2, 2012 20:20
Show Gist options
  • Save potch/3035455 to your computer and use it in GitHub Desktop.
Save potch/3035455 to your computer and use it in GitHub Desktop.
dotjs script to toggle collapsing comments on HN
$('body').append('<style>.collapsed{opacity:.3;}</style>');
$('body').delegate('.comment', 'click', function() {
var topComment = $(this).parents('tr').eq(1);
if (!topComment.length) return;
topComment.toggleClass('collapsed');
var initIndent = +topComment.find('img[width]').attr('width');
var currentComment = topComment.next();
var currentIndent = +currentComment.find('img[width]').attr('width');
var isCollapsed = topComment.hasClass('collapsed');
while (currentIndent > initIndent && currentComment.length) {
currentComment.toggle(!isCollapsed);
currentComment = currentComment.next();
currentIndent = +currentComment.find('img[width]').attr('width');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment