WordPress - Sort My Favorites

Sort WordPress favorites alphabetically.

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

  1. // ==UserScript==
  2. // @name WordPress - Sort My Favorites
  3. // @version 0.2
  4. // @author Tim Berneman
  5. // @copyright Tim Berneman (c) 2015
  6. // @namespace wordpress_sort_my_favorites
  7. // @description Sort WordPress favorites alphabetically.
  8. // @include /https?:\/\/profiles\.wordpress\.org\/(.*)#content-favorites\/?/
  9. // @include https://wordpress.org/plugins/browse/favorites/
  10. // @grant none
  11. // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.js
  12. // @run-at document-end
  13. //
  14. // License: http://creativecommons.org/licenses/by-nc-sa/3.0/
  15. //
  16. // CHANGELOG:
  17. // v0.1 ~ initial release - sort favorites on profiles.wordpress.org/username#content-favorites
  18. // v0.2 ~ added more code - sort favorites on wordpress.org/plugins/browse/favorites/ as well
  19. //
  20. // ==/UserScript==
  21.  
  22. $(document).ready(function() {
  23. // For profiles.wordpress.org/username#content-favorites
  24. var sorted = $.makeArray($('#content-favorites .favorite-plugins ul li')).sort(function(a,b){
  25. return ( $(a).children('h3').text().trim() < $(b).children('h3').text().trim() ) ? -1 : 1;
  26. });
  27. $('#content-favorites .favorite-plugins ul').html(sorted);
  28. // For wordpress.org/plugins/browse/favorites
  29. var sorted = $.makeArray($('#the-list .plugin-card')).sort(function(a,b){
  30. return ( $(a).attr('class') < $(b).attr('class') ) ? -1 : 1;
  31. });
  32. $('#the-list').html(sorted);
  33. });