Skip to content

Instantly share code, notes, and snippets.

@hughsk
Created October 28, 2011 07:36
Show Gist options
  • Save hughsk/1321817 to your computer and use it in GitHub Desktop.
Save hughsk/1321817 to your computer and use it in GitHub Desktop.
Pick up compiled LESS code using a bookmarklet!
//Bookmarklet Code
$('head style').each(function() {if ($(this).attr('id') && $(this).attr('id').indexOf('less:') > -1) {var lesscode = $(document.createElement('div'));lesscode.html($(this).text().replace(/\/\*.*?\*\//g,' ').replace(/[ ]{2,100}/g,' '));lesscode.css('padding','20px').css('font-size','10px').css('background-color','#ddd').css('font-family','monospace');$('body:last-child').append(lesscode);} });
//Legible version
$('head style').each(function() {
if ($(this).attr('id') && $(this).attr('id').indexOf('less:') > -1) {
var lesscode = $(document.createElement('div'));
//Clean up a lot of comments and white space...
lesscode.html($(this).text().
replace(/\/\*.*?\*\//g,' ').
replace(/[ ]{2,100}/g,' '));
//Format the box
lesscode.css('padding','20px').
css('font-size','10px').
css('background-color','#ddd').
css('font-family','monospace');
//Place the box at the end of the body
$('body:last-child').append(lesscode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment