Gitee CSV Formatter

Format CSV files in gitee repo.

  1. // ==UserScript==
  2. // @name Gitee CSV Formatter
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Format CSV files in gitee repo.
  6. // @author szx
  7. // @match *://gitee.com/*.csv
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. let box = document.getElementsByTagName("pre")[0];
  16. let lines = box.getElementsByClassName("line");
  17. let tb = "<table>";
  18. for (let line of lines) {
  19. let words = line.innerHTML.split(/,|;|\t/);
  20. tb += "<tr>";
  21. for (let word of words) {
  22. tb += "<td>" + word + "</td>";
  23. }
  24. tb += "</tr>";
  25. }
  26. tb += "</table>";
  27. box.innerHTML = tb;
  28.  
  29. let sty = document.createElement("style");
  30. sty.innerHTML = "table { border-collapse: collapse; border-spacing: 0; } td { max-width: 5em; padding: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } td:nth-child(1) { max-width: 16em; } tr:nth-child(odd) { background-color: #eee; } tr:nth-child(even) { background-color: #fff; }";
  31. document.head.append(sty);
  32. })();