GreasyFork script list beautifier

Reformat script list on GreasyFork

Verze ze dne 01. 07. 2014. Zobrazit nejnovější verzi.

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