Full subreddit menu

Displays all your subreddits in the "My subreddits" dropdown menu instead of the default list capped at 50 items.

  1. // ==UserScript==
  2. // @name Full subreddit menu
  3. // @description Displays all your subreddits in the "My subreddits" dropdown menu instead of the default list capped at 50 items.
  4. // @namespace raina
  5. // @include /^https?:\/\/(\w+\.)?reddit\.com\//
  6. // @version 1.0.1
  7. // @grant none
  8. // ==/UserScript==
  9. (function() {
  10. "use strict";
  11.  
  12. if (window.top == window.self) {
  13. var subs = JSON.parse(sessionStorage.getItem("subs"));
  14. var edit = $('.srdrop.drop-choices .bottom-option');
  15. var menu = $('.srdrop.drop-choices');
  16. var list = "";
  17.  
  18.  
  19. var renderSubs = function() {
  20. list = '<ul style="white-space: pre-line; position: relative;">';
  21. $.each(subs, function(idx, sub) {
  22. list += '<li style="display: inline-block; min-width: 23ch;"><a class="choice" href="/r/' + sub + '">' + sub + '</a></li>';
  23. });
  24. list += '<li id="subs-tools" style="display: inline-block; position: absolute; right: 0"><a id="subs-refresh" class="choice" href="#">Refresh</a> | </li>';
  25. list += '</ul>'
  26. edit.css("border", "none");
  27. edit.css("font-style", "normal");
  28. menu.css("width", 'calc(100% - 16px)');
  29. menu.html(list);
  30. menu.find('#subs-tools').append(edit);
  31. menu.find('#subs-tools a').css("display", "inline-block");
  32. menu.find('#subs-tools #subs-refresh').click(refreshSubs);
  33. };
  34.  
  35.  
  36. var refreshSubs = function(ev) {
  37. if ("init" !== ev) {
  38. ev.preventDefault();
  39. ev.stopPropagation();
  40. }
  41. $.get('/subreddits', function(response) {
  42. var responseHTML = $(response);
  43. var subGet = responseHTML.find('.subscription-box li a.title');
  44. subs = [];
  45. $.each(subGet, function(idx, el) {
  46. subs.push(el.textContent);
  47. });
  48. sessionStorage.setItem("subs", JSON.stringify(subs));
  49. renderSubs();
  50. });
  51. };
  52.  
  53.  
  54. if (subs) {
  55. renderSubs();
  56. } else {
  57. refreshSubs("init");
  58. }
  59. }
  60. }());