WatchSeries Host List Sorter

Sorts the host list on watchseries alphabetically

  1. // ==UserScript==
  2. // @name WatchSeries Host List Sorter
  3. // @namespace dannieboi
  4. // @version 0.3
  5. // @description Sorts the host list on watchseries alphabetically
  6. // @author dannieboi
  7. // @match http://watchseries.ag/episode/*.html
  8. // @match http://watchseries.vc/episode/*.html
  9. // @match http://watchseries.se/episode/*.html
  10. // @match http://watchseriesfree.to/episode/*.html
  11. // @match https://watchseriesfree.to/episode/*.html
  12. // @grant none
  13. // @require https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js
  14. // ==/UserScript==
  15.  
  16. $("select.kwd_search").each(function(){
  17. var $select = $(this);
  18.  
  19. var $selectOptions = $select.find("option");
  20.  
  21.  
  22. var optionValues = _.map($selectOptions.get(), function(x){
  23. return { text: x.innerText, value: x.value };
  24. });
  25.  
  26. var sortedOptionValues = _.sortBy(optionValues, "text");
  27.  
  28. $selectOptions.remove();
  29.  
  30. optionTemplate = _.template("<option value='<%= value %>'><%= text %></option>");
  31.  
  32. _.forEach(sortedOptionValues, function(x){
  33. $select.append(optionTemplate(x));
  34. });
  35. });