GreasyFork script list beautifier

Reformat script list on GreasyFork

当前为 2014-07-02 提交的版本,查看 最新版本

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