reddit.com - Sort by Top Quicker (past hour/24 hours/week/month/year/all time).

All the 'sort by top' options are made available for single clicking. And it actually looks good too.

  1. // ==UserScript==
  2. // @name reddit.com - Sort by Top Quicker (past hour/24 hours/week/month/year/all time).
  3. // @namespace a-pav
  4. // @description All the 'sort by top' options are made available for single clicking. And it actually looks good too.
  5. // @match *://*.reddit.com/*
  6. // @exclude-match *://*.reddit.com/search?*
  7. // @exclude-match *://*.reddit.com/r/*/search?*
  8. // @match *://reddit.com/*
  9. // @exclude-match *://reddit.com/search?*
  10. // @exclude-match *://reddit.com/r/*/search?*
  11. // @version 1.0
  12. // @run-at document-end
  13. // @author a-pav
  14. // @icon https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-76x76.png
  15. // ==/UserScript==
  16.  
  17. // operates on old design.
  18. var top_a = document.querySelector('ul.tabmenu>li>a[href*="/top/"');
  19. if (top_a === null) {
  20. return
  21. }
  22.  
  23. var view = ""
  24.  
  25. if (window.location.pathname.includes("/top/")) { // we are on a */top/* url
  26. const re = /hour\b|24|week|month|year|all/;
  27. var view = document.querySelector("div.menuarea>div>div.dropdown.lightdrop>span").innerText;
  28. if (re.test(view)) {
  29. view = view.match(re)[0]
  30. }
  31. }
  32.  
  33. function isView(txt) {
  34. return txt === view;
  35. }
  36.  
  37. var html = `
  38. <li class='${isView("hour") ? 'selected' : ''}'>
  39. <a class='choice' href='${top_a.href}?sort=top&t=hour'>-1h</a>
  40. </li>
  41. <li class='${isView("24") ? 'selected' : ''}'>
  42. <a class="choice" href='${top_a.href}?sort=top&t=day'>-24h</a>
  43. </li>
  44. <li class='${isView("week") ? 'selected' : ''}'>
  45. <a class="choice" href='${top_a.href}?sort=top&t=week'>-W</a>
  46. </li>
  47. <li class='${isView("month") ? 'selected' : ''}'>
  48. <a class="choice" href='${top_a.href}?sort=top&t=month'>-M</a>
  49. </li>
  50. <li class='${isView("year") ? 'selected' : ''}'>
  51. <a class="choice" href='${top_a.href}?sort=top&t=year'>-Y</a>
  52. </li>
  53. <li class='${isView("all") ? 'selected' : ''}'>
  54. <a class="choice" href='${top_a.href}?sort=top&t=all'>-A</a>
  55. </li>
  56. `;
  57.  
  58. top_a.parentElement.insertAdjacentHTML("afterend", html);