Greasy Fork 支持简体中文。

GreasyFork script list beautifier

Reformat script list on GreasyFork

  1. // ==UserScript==
  2. // @name GreasyFork script list beautifier
  3. // @namespace http://websocket.bplaced.net
  4. // @version 1.4.1
  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('Fans');
  36. $theadtr.append($th);
  37. $th = $('<td style="font-weight: bold" width="8%"></td>');
  38. $th.html('Created');
  39. $theadtr.append($th);
  40. $th = $('<td style="font-weight: bold" width="8%"></td>');
  41. $th.html('Updated');
  42. $theadtr.append($th);
  43. $tbody.append($theadtr);
  44. $(this).find('li').each(function() {
  45. var $scriptlink = $(this).find('article h2 a');
  46. var $scriptdesc = $(this).find('article h2 .description');
  47. $tr = $('<tr></tr>');
  48. $td = $('<td></td>');
  49. $td.append($scriptlink);
  50. $td.append('<br/>');
  51. $td.append($scriptdesc);
  52. $tr.append($td);
  53. $(this).find('article dl dd').each(function() {
  54. $td = $('<td></td>');
  55. $td.html($(this).html());
  56. $tr.append($td);
  57. });
  58. $tbody.append($tr);
  59. });
  60. $table.append($tbody);
  61. $(this).replaceWith($table);
  62. //$(this).hide();
  63. });
  64. $('.total').click(function() {
  65. // sort total column
  66. var $rowArray = [];
  67. var totalArray = [];
  68. var $tbody = $(this).parent().parent().parent();
  69. $tbody.find('tr').each(function(index) {
  70. if(index > 0) {
  71. $rowArray.push($(this));
  72. var total = parseInt($(this).find('td').eq(3).text(), 10);
  73. totalArray.push(total);
  74. }
  75. });
  76. for(i=0; i<totalArray.length-1; i++) {
  77. for(j=i+1; j<totalArray.length; j++) {
  78. if(totalArray[i] < totalArray[j]) {
  79. var help = totalArray[i];
  80. var helpTR = $rowArray[i];
  81. totalArray[i] = totalArray[j];
  82. $rowArray[i] = $rowArray[j];
  83. totalArray[j] = help;
  84. $rowArray[j] = helpTR;
  85. }
  86. }
  87. }
  88. for(i=0; i<totalArray.length; i++) {
  89. $tbody.append($rowArray[i]);
  90. }
  91. });
  92.  
  93. $('.title').click(function() {
  94. // sort title column
  95. var $rowArray = [];
  96. var titleArray = [];
  97. var $tbody = $(this).parent().parent().parent();
  98. $tbody.find('tr').each(function(index) {
  99. if(index > 0) {
  100. $rowArray.push($(this));
  101. var title = $(this).find('td').eq(0).text();
  102. titleArray.push(title);
  103. }
  104. });
  105. for(i=0; i<titleArray.length-1; i++) {
  106. for(j=i+1; j<titleArray.length; j++) {
  107. if(titleArray[i] > titleArray[j]) {
  108. var help = titleArray[i];
  109. var helpTR = $rowArray[i];
  110. titleArray[i] = titleArray[j];
  111. $rowArray[i] = $rowArray[j];
  112. titleArray[j] = help;
  113. $rowArray[j] = helpTR;
  114. }
  115. }
  116. }
  117. for(i=0; i<titleArray.length; i++) {
  118. $tbody.append($rowArray[i]);
  119. }
  120. });
  121. }
  122. }, false);