Expand Subreddit Header

Expand subreddit header on Reddit

当前为 2015-09-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Expand Subreddit Header
  3. // @version 0.3
  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. // ==/UserScript==
  11.  
  12. var css = document.createElement("style");
  13. css.type = "text/css";
  14. css.innerHTML =
  15. "#sr-header-area .flat-list > li { white-space: initial !important; } " +
  16. "#sr-header-area .dropdown.srdrop { padding-left: 0 !important; }" +
  17. ".sr-list { display: inline !important; visibility: hidden; } " +
  18. "#sr-header-area { height: initial !important; } " +
  19. "#sr-header-area > .width-clip { position: initial !important; padding-left: 5px !important; } " +
  20. "#sr-more-link { position: initial !important; } " +
  21. ".dropdown.srdrop { display: none !important; }";
  22.  
  23. document.head.appendChild(css);
  24.  
  25. document.addEventListener("DOMContentLoaded", function() {
  26. var list = document.querySelectorAll('.sr-list')[0].children[2];
  27. var subs = list.children;
  28. subs[0].innerHTML = '<span class="separator">-</span>' + subs[0].innerHTML;
  29. var sorted = Array.prototype.slice.call(subs).sort(function(a, b) {
  30. return a.lastChild.textContent.toLowerCase() > b.lastChild.textContent.toLowerCase() ? 1 : -1;
  31. });
  32.  
  33. var firstSeparator = sorted[0].getElementsByClassName('separator')[0];
  34. if (firstSeparator) firstSeparator.remove();
  35.  
  36. sorted.forEach(function(node) {
  37. list.appendChild(node);
  38. });
  39. list.parentNode.style.visibility = 'visible';
  40. });