Skip to content

Instantly share code, notes, and snippets.

@misterdai
Created September 19, 2012 13:59
Show Gist options
  • Save misterdai/3749835 to your computer and use it in GitHub Desktop.
Save misterdai/3749835 to your computer and use it in GitHub Desktop.
Bookmarklet do remove blank code lines and turn comments into tooltips.
javascript:(function(){$('.gist .line br').each(function(){if($(this).siblings().length==0){$(this).parent().remove();}});$('.c, .cm, .c1, .cs','.gist').each(function(){var el=$(this);var parent=el.parent();if(el.siblings().length > 0){var comment=parent.attr('data-comment');comment=(typeof comment==='undefined')%3F'':(comment+'\n');parent.attr('data-comment',comment+el.text());el.remove();}else{var nextParent=parent.next();var comment=parent.attr('data-comment');comment=(typeof comment==='undefined')%3F'':(comment+'\n');nextParent.attr('data-comment',comment+el.text());parent.remove();}});$('html > head').append('<style>*[data-comment] {position:relative; background-color:%23dfd;} *[data-comment]:hover {background-color: %23efe;} *[data-comment]:after, *[data-comment]:before {content:""; opacity:0; z-index:999;} *[data-comment]:hover:after, *[data-comment]:focus:after {opacity:0.94; display:block; content:attr(data-comment); position:absolute; bottom:25px; padding:3px; background:%23efe; border:2px solid %23afa; border-radius:7px;}</style>');})();
$('.gist .line br').each(function() {
if ($(this).siblings().length == 0) {
$(this).parent().remove();
}
});
$('.c, .cm, .c1, .cs','.gist').each(function() {
var el = $(this);
var parent = el.parent();
// check for siblings
if (el.siblings().length > 0) {
// Just in case you somehow have multiple comments per line
var comment = parent.attr('data-comment');
comment = (typeof comment === 'undefined') ? '' : (comment + '\n');
parent.attr('data-comment', comment + el.text());
el.remove();
} else {
var nextParent = parent.next();
var comment = parent.attr('data-comment');
comment = (typeof comment === 'undefined') ? '' : (comment + '\n');
nextParent.attr('data-comment', comment + el.text());
parent.remove();
}
});
$('html > head').append('<style>*[data-comment] {position:relative; background-color:#dfd;} *[data-comment]:hover {background-color: #efe;} *[data-comment]:after, *[data-comment]:before {content:""; opacity:0; z-index:999;} *[data-comment]:hover:after, *[data-comment]:focus:after {opacity:0.94; display:block; content:attr(data-comment); position:absolute; bottom:25px; padding:3px; background:#efe; border:2px solid #afa; border-radius:7px;}</style>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment