KAT - Sort Translators

Groups translators by language (only sorts by default)

  1. // ==UserScript==
  2. // @name KAT - Sort Translators
  3. // @namespace SortTranslators
  4. // @version 2.02
  5. // @description Groups translators by language (only sorts by default)
  6. // @include https://*kat.cr/people/translators/
  7. // ==/UserScript==
  8.  
  9. var info = [];
  10. $('.firstColl:first > ul > li').each(function()
  11. {
  12. var all = $(this).html();
  13. var span = $(this).children("span");
  14. $(span).remove();
  15. var language = $(this).html();
  16. info.push({"html":all, "lang":language});
  17. $(this).remove();
  18. });
  19.  
  20. var columnLimit = info.length;
  21. var current = 0;
  22.  
  23. $('.secondColl:first > ul > li').each(function()
  24. {
  25. var all = $(this).html();
  26. var span = $(this).children("span");
  27. $(span).remove();
  28. var language = $(this).html();
  29. info.push({"html":all, "lang":language});
  30. $(this).remove();
  31. });
  32.  
  33. info.sort(function(a, b) {
  34. return a.lang.localeCompare(b.lang);;
  35. });
  36.  
  37. for (i = 0; i < info.length; i++)
  38. {
  39. if (current < columnLimit) { $('.firstColl:first > ul').append('<li>' + info[i].html + '</li>'); }
  40. else { $('.secondColl:first > ul').append('<li>' + info[i].html + '</li>'); }
  41. current++;
  42. }
  43.  
  44. info = [];
  45. $('.thirdColl:first > ul > li').each(function()
  46. {
  47. var all = $(this).html();
  48. var span = $(this).children("span");
  49. $(span).remove();
  50. var language = $(this).html();
  51. info.push({"html":all, "lang":language});
  52. $(this).remove();
  53. });
  54.  
  55. info.sort(function(a, b) {
  56. return a.lang.localeCompare(b.lang);;
  57. });
  58.  
  59. for (i = 0; i < info.length; i++)
  60. {
  61. $('.thirdColl:first > ul').append('<li>' + info[i].html + '</li>');
  62. }
  63.  
  64. var langs = [];
  65. var items = $("div[class$='Coll']:lt(2) > ul > li").contents().filter(function() { return this.nodeType === 3;});
  66. items = items.map(function() {
  67. var text = $(this).text();
  68. text = text.substring(2, text.length - 1);
  69. return text;
  70. });
  71.  
  72. function unique(array) {
  73. return $.grep(array, function(el, index) {
  74. return index === $.inArray(el, array);
  75. });
  76. }
  77.  
  78. items = unique(items);
  79.  
  80. items.sort();
  81.  
  82. $.map(items, function(val)
  83. {
  84. langs[val] = [];
  85. });
  86. langs["All"] = [];
  87.  
  88. var option = '<option value="All">All - ' + $("div[class$='Coll']:lt(2) > ul > li").length + ' translator(s)</option>';
  89.  
  90. $("div[class$='Coll']:lt(2) > ul > li").each(function()
  91. {
  92. var html = '<li><span class="badgeInline">' + $(this).contents().filter(function() { return this.nodeType != 3;}).html() + '</span></li>';
  93. var language = $(this).contents().filter(function() { return this.nodeType === 3;}).text();
  94. language = language.substring(2, language.length - 1);
  95. langs[language].push(html);
  96. });
  97. langs["All"].push($(".firstColl ul").html());
  98. langs["All"].push($(".secondColl").html());
  99.  
  100. console.log(langs);
  101. console.log("There is currently " + $("div[class$='Coll']:lt(2) > ul > li").length + " translators working on " + items.length + " languages");
  102.  
  103. for (var i=0;i<items.length;i++)
  104. {
  105. option += '<option value="'+ items[i] + '">' + items[i] + ' - ' + langs[items[i]].length + ' translator(s)</option>';
  106. }
  107. $('<hr /><select id="translatorLang">' + option + "</select>").prependTo(".firstColl");
  108.  
  109. $("#translatorLang").change(function()
  110. {
  111. var langChosen = $("#translatorLang option:selected").val();
  112. if (langChosen == "All")
  113. {
  114. $(".firstColl ul").html(langs["All"][0]);
  115. $('<div class="secondColl"><hr style="margin-bottom:27px">' + langs["All"][1] + '</p></div>').insertAfter(".firstColl");
  116. }
  117. else
  118. {
  119. $(".firstColl ul").html(langs[langChosen]);
  120. $(".secondColl").remove();
  121. }
  122. });
  123.  
  124. $(".secondColl").remove();
  125. $("#translatorLang").trigger("change");
  126.  
  127. // FORMER TRANSLATORS
  128.  
  129. var langs_former = [];
  130. var items_former = $(".thirdColl > ul > li").contents().filter(function() { return this.nodeType === 3;});
  131. items_former = items_former.map(function() {
  132. var text = $(this).text();
  133. text = text.substring(2, text.length - 1);
  134. return text;
  135. });
  136.  
  137. function unique(array) {
  138. return $.grep(array, function(el, index) {
  139. return index === $.inArray(el, array);
  140. });
  141. }
  142.  
  143. items_former = unique(items_former);
  144. items_former.sort();
  145.  
  146. $.map(items_former, function(val)
  147. {
  148. langs_former[val] = [];
  149. });
  150.  
  151. var option_former = '<option value="All">All - ' + $(".thirdColl > ul > li").length + ' translator(s)</option>';
  152.  
  153. $(".thirdColl > ul > li").each(function()
  154. {
  155. var html = '<li><span class="badgeInline">' + $(this).contents().filter(function() { return this.nodeType != 3;}).html() + '</span></li>';
  156. var language = $(this).contents().filter(function() { return this.nodeType === 3;}).text();
  157. language = language.substring(2, language.length - 1);
  158. langs_former[language].push(html);
  159. });
  160.  
  161. langs_former["All"] = $(".thirdColl ul").html();
  162.  
  163. console.log(langs_former);
  164. console.log($(".thirdColl > ul > li").length + " translators previously worked on " + items_former.length + " languages");
  165.  
  166. for (var i=0;i<items_former.length;i++)
  167. {
  168. option_former += '<option value="'+ items_former[i] + '">' + items_former[i] + ' - ' + langs_former[items_former[i]].length + ' translator(s)</option>';
  169. }
  170. $('<hr /><select id="formerTranslatorLang">' + option_former + "</select>").prependTo(".thirdColl");
  171.  
  172. $("#formerTranslatorLang").change(function()
  173. {
  174. var langChosen = $("#formerTranslatorLang option:selected").val();
  175. $(".thirdColl ul").html(langs_former[langChosen]);
  176. });
  177.  
  178. $("#formerTranslatorLang").trigger("change");