MyShows: sort serials

Sort serials in alphabetic order on myshows.me

当前为 2015-12-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MyShows: sort serials
  3. // @namespace https://github.com/powerman/userjs-myshows
  4. // @description Sort serials in alphabetic order on myshows.me
  5. // @include http://myshows.me/profile/
  6. // @include https://myshows.me/profile/
  7. // @match http://myshows.me/profile/
  8. // @match https://myshows.me/profile/
  9. // @version 3.2
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. window.addEventListener('load', function(){
  14. 'use strict';
  15.  
  16. function sort_shows(){
  17. // sort lists at right panel
  18. $('ul.firmList').html(function(){
  19. return $(this).children().sort(function(a,b){
  20. return $(a).text() < $(b).text() ? -1 : 1;
  21. });
  22. });
  23. // sort main content
  24. $('main').html(function(){
  25. return $(this).children(':first-child').nextUntil('h2').andSelf().add(
  26. $(this).find('h2').map(function(){
  27. return $(this).nextUntil('h2').andSelf();
  28. }).sort(function(a,b){
  29. return a.first().find('a').text() < b.first().find('a').text() ? -1 : 1;
  30. }).map(function(){
  31. return this.map(function(){
  32. // .add() above re-order
  33. // added items if they're
  34. // jQuery/DOM objects, map
  35. // them to strings to
  36. // keep current order
  37. return this.outerHTML;
  38. }).get();
  39. })
  40. ).get();
  41. });
  42. // ... and move AD to the end
  43. $('main hr').prevUntil('.seasonBlock, p, h2, h1').andSelf().remove().appendTo('main');
  44. }
  45.  
  46. var rate_handler = jQuery._data($('.rate-episode').get(0)).events.click[0].handler;
  47. sort_shows();
  48. $('.rate-episode').bind('click', rate_handler);
  49. // from document.ready handler
  50. $('div.seasonBlock').each(function () {
  51. siteSeasonBlock = new SeasonBlock();
  52. siteSeasonBlock.init($(this));
  53. });
  54.  
  55. }, false);