GreasyFork script list beautifier

Reformat script list on GreasyFork

目前为 2014-07-01 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name GreasyFork script list beautifier
  3. // @namespace http://websocket.bplaced.net
  4. // @version 1.1.1
  5. // @description Reformat script list on GreasyFork
  6. // @match https://greasyfork.org/users/*
  7. // @match https://greasyfork.org/scripts*
  8. // @copyright 2014, Thomas Theiner
  9. // ==/UserScript==
  10.  
  11. window.addEventListener('load', function() {
  12. if(unsafeWindow.jQuery) {
  13. $ = unsafeWindow.jQuery;
  14. $('section .script-list, body > .script-list').each(function() {
  15. $table = $('<table border="0" width="89%"></table>');
  16. $tbody = $('<tbody></tbody>');
  17. $thead = $('<thead></thead>');
  18. $theadtr = $('<tr></tr>');
  19. $th = $('<td style="font-weight: bold" width="60%"></td>');
  20. $th.html('<span class="title" style="cursor: pointer;">Title</span>');
  21. $theadtr.append($th);
  22. $th = $('<td style="font-weight: bold" width="8%"></td>');
  23. $th.html('Author');
  24. $theadtr.append($th);
  25. $th = $('<td style="font-weight: bold" width="8%"></td>');
  26. $th.html('Daily');
  27. $theadtr.append($th);
  28. $th = $('<td style="font-weight: bold" width="8%"></td>');
  29. $th.html('<span class="total" style="cursor: pointer;">Total</span>');
  30. $theadtr.append($th);
  31. $th = $('<td style="font-weight: bold" width="8%"></td>');
  32. $th.html('Created');
  33. $theadtr.append($th);
  34. $th = $('<td style="font-weight: bold" width="8%"></td>');
  35. $th.html('Updated');
  36. $theadtr.append($th);
  37. $tbody.append($theadtr);
  38. $(this).find('li').each(function() {
  39. var $scriptlink = $(this).find('article h2 a');
  40. var $scriptdesc = $(this).find('article h2 .description');
  41. $tr = $('<tr></tr>');
  42. $td = $('<td></td>');
  43. $td.append($scriptlink);
  44. $td.append('<br/>');
  45. $td.append($scriptdesc);
  46. $tr.append($td);
  47. $(this).find('article dl dd').each(function() {
  48. $td = $('<td></td>');
  49. $td.html($(this).html());
  50. $tr.append($td);
  51. });
  52. $tbody.append($tr);
  53. });
  54. $table.append($tbody);
  55. $(this).replaceWith($table);
  56. //$(this).hide();
  57. });
  58. $('.total').click(function() {
  59. // sort total column
  60. var $rowArray = [];
  61. var totalArray = [];
  62. var $tbody = $(this).parent().parent().parent();
  63. $tbody.find('tr').each(function(index) {
  64. if(index > 0) {
  65. $rowArray.push($(this));
  66. var total = parseInt($(this).find('td').eq(3).text(), 10);
  67. totalArray.push(total);
  68. }
  69. });
  70. for(i=0; i<totalArray.length-1; i++) {
  71. for(j=i+1; j<totalArray.length; j++) {
  72. if(totalArray[i] < totalArray[j]) {
  73. var help = totalArray[i];
  74. var helpTR = $rowArray[i];
  75. totalArray[i] = totalArray[j];
  76. $rowArray[i] = $rowArray[j];
  77. totalArray[j] = help;
  78. $rowArray[j] = helpTR;
  79. }
  80. }
  81. }
  82. for(i=0; i<totalArray.length; i++) {
  83. $tbody.append($rowArray[i]);
  84. }
  85. });
  86.  
  87. $('.title').click(function() {
  88. // sort title column
  89. var $rowArray = [];
  90. var titleArray = [];
  91. var $tbody = $(this).parent().parent().parent();
  92. $tbody.find('tr').each(function(index) {
  93. if(index > 0) {
  94. $rowArray.push($(this));
  95. var title = $(this).find('td').eq(0).text();
  96. titleArray.push(title);
  97. }
  98. });
  99. for(i=0; i<titleArray.length-1; i++) {
  100. for(j=i+1; j<titleArray.length; j++) {
  101. if(titleArray[i] > titleArray[j]) {
  102. var help = titleArray[i];
  103. var helpTR = $rowArray[i];
  104. titleArray[i] = titleArray[j];
  105. $rowArray[i] = $rowArray[j];
  106. titleArray[j] = help;
  107. $rowArray[j] = helpTR;
  108. }
  109. }
  110. }
  111. for(i=0; i<titleArray.length; i++) {
  112. $tbody.append($rowArray[i]);
  113. }
  114. });
  115. }
  116. }, false);