Expand Subreddit Header

Expand subreddit header on Reddit

当前为 2016-02-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Expand Subreddit Header
  3. // @version 0.4
  4. // @description Expand subreddit header on Reddit
  5. // @author Josh Bjelovuk
  6. // @match *://www.reddit.com/*
  7. // @grant none
  8. // @run-at document-start
  9. // @namespace https://greasyfork.org/users/11679
  10. // @contributionURL https://goo.gl/dYIygm
  11. // ==/UserScript==
  12.  
  13. var css = document.createElement("style");
  14. css.type = "text/css";
  15. css.innerHTML =
  16. "#sr-header-area .flat-list > li { white-space: initial !important; } " +
  17. "#sr-header-area .dropdown.srdrop { padding-left: 0 !important; }" +
  18. ".sr-list { display: inline !important; visibility: hidden; } " +
  19. "#sr-header-area { height: initial !important; } " +
  20. "#sr-header-area > .width-clip { position: initial !important; padding-left: 5px !important; } " +
  21. "#sr-more-link { position: initial !important; } " +
  22. ".dropdown.srdrop { display: none !important; }";
  23.  
  24. document.head.appendChild(css);
  25.  
  26. document.addEventListener("DOMContentLoaded", function() {
  27. var list = document.querySelectorAll('.sr-list')[0].children[2];
  28. var subs = list.children;
  29. subs[0].innerHTML = '<span class="separator">-</span>' + subs[0].innerHTML;
  30. var sorted = Array.prototype.slice.call(subs).sort(function(a, b) {
  31. return a.lastChild.textContent.toLowerCase() > b.lastChild.textContent.toLowerCase() ? 1 : -1;
  32. });
  33.  
  34. var firstSeparator = sorted[0].getElementsByClassName('separator')[0];
  35. if (firstSeparator) firstSeparator.remove();
  36.  
  37. sorted.forEach(function(node) {
  38. list.appendChild(node);
  39. });
  40. list.parentNode.style.visibility = 'visible';
  41. });