Skip to content

Instantly share code, notes, and snippets.

@poezn poezn/gist:4278379

Created Dec 13, 2012
Embed
What would you like to do?
Bookmarklet that converts the contents of a <table> to CSV and appends it to a textarea after the table
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
You can’t perform that action at this time.