Created
December 13, 2012 18:07
-
-
Save poezn/4278379 to your computer and use it in GitHub Desktop.
Bookmarklet that converts the contents of a <table> to CSV and appends it to a textarea after the table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:javascript:%20(function()%20{if%20(%27undefined%27==typeof%20jQuery)%20{script%20=%20document.createElement(%20%27script%27%20);script.src%20=%20%27http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js%27;script.onload=tables2CSV;document.body.appendChild(script);}else%20{tables2CSV();}function%20tables2CSV()%20{$(%27table%27).each(function()%20{var%20$table%20=%20$(this);$(%27<textarea/>%27).css(%27border%27,%20$table.css(%27border%27)).css(%27width%27,%20$table.width()).html($.map($table.find(%27tr%27),%20function(tr)%20{return%20$.map($(tr).find(%27th,%20td%27),%20function(e)%20{return%20%27%22%27%20+%20$(e).text().trim().replace(%27%22%27,%20%27%22%22%27)%20+%20%27%22%27}).join(%27,%27)}).join(%27\n%27)).insertAfter($table);});}})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment