Reddit Enhancements

Some small enhancements for reddit (RES needed)

  1. // ==UserScript==
  2. // @name Reddit Enhancements
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.9
  5. // @description Some small enhancements for reddit (RES needed)
  6. // @license MIT
  7. // @icon data:image/webp;base64,UklGRrwBAABXRUJQVlA4TLABAAAvP8APAK+goG0bhj/ddv/SMJC2TXr/ls8Utm2k7L/rMT7//Mfvr29tSyUrvpCacd2glC8IERWbAUJEGSIIODeWuw1wA4Bt24Ck2AvY8P+xJmiK3pIlov8TQH/fZ6mDaTGUeR8CCB1Km1QEANhxXQRnBABIK+EzX2eh06jZP7C2t0350BpX7rYGnhlqUS6bBTIzqwQAPy+jAJUh6jlVul6LsfGTQxj67QrhxzKUH/PQfqZjDs5IMC5k7Ne1ZOBLk9pNaOGoxdeaV9Lk2Swct21mI5Vvh1DApxHwojDwKfBIl3Cx7CcSXJ1OuLvcWzL3gXpH4+hZvpW2kIioP9zTiYhwK53ocsPQMnOZlmZD9hOEgvMr5HDlOYF0tinGrDKXV4ZRjU5zUD+G5vT4qMA+9J4qk5qFTdtoFnWB4QCkgi+VhE1zLuy8G87hLXhu6jv0PEe4YZPYE8luIL0ZuELNCU64RoUL9OqwjEKiXqJ3zsfSiVAxdrxDw60ALA5iB1pg3aCX54wMgDAh5ZyCEcCKOOnCqpmDutKds+gzuky6t4bnmydUur2V6Myj1GNcLI3+LwI=
  8. // @author mattiadr96@gmail.com
  9. // @match http*://*.reddit.com/*
  10. // @grant GM_setClipboard
  11. // @noframes
  12. // ==/UserScript==
  13.  
  14. (function($) {
  15. "use strict";
  16.  
  17. // middle click to collapse
  18. $(document).on("mousedown", function(e) {
  19. if (e.button == 1) {
  20. // ignore links
  21. if ($(":hover").last().is("a")) {
  22. return;
  23. }
  24. let entry = $(":hover").filter(".entry").find("a.toggleChildren");
  25. if (entry.length > 0) {
  26. entry[0].click();
  27. }
  28. return false;
  29. }
  30. });
  31.  
  32. // share button override
  33. $(document).on("mousedown", function(e) {
  34. if (e.button == 0) {
  35. let el = $(":hover").last();
  36. if (el.hasClass("post-sharing-button")) {
  37. let link = el.parent().prev().children().attr("href");
  38. let url = "https://redd.it/" + link.match(/comments\/(\w+)\//)[1];
  39. GM_setClipboard(url);
  40. el.css("color", "rgb(255, 69, 0)");
  41. setTimeout(function() {
  42. el.css("color", "");
  43. }, 1000);
  44. }
  45. }
  46. });
  47.  
  48. let style = document.createElement('style');
  49. style.innerHTML = `
  50. .post-sharing {
  51. display: none!important;
  52. }
  53. `;
  54. document.head.appendChild(style);
  55.  
  56. // click on shortlink to copy
  57. $("#shortlink-text").on("click", function(e) {
  58. document.execCommand("copy");
  59. });
  60.  
  61. // spoilers improvement
  62. /* not working
  63. $("head").append(`
  64. <style type="text/css">
  65. a[href="/s"].hover {
  66. color: #f44!important;
  67. }
  68.  
  69. a[href="/s"].hover:after {
  70. color: #FFF!important;
  71. }
  72. </style>`);
  73.  
  74. $(document).on("click", function(e) {
  75. let a = $(":hover").filter("a[href='/s']");
  76. if (a.length > 0) {
  77. e.preventDefault();
  78. a.toggleClass("hover");
  79. }
  80. });
  81. */
  82.  
  83. // color save/unsave button
  84. $(".save-button > a:contains('unsave')").css("color", "gold");
  85.  
  86. $(".save-button > a").on("click", function(e) {
  87. e.target.style.color = (e.target.text == "save") ? "gold" : "";
  88. });
  89.  
  90. // goto unddit
  91. let a = $("<a href='#' onclick='return false;' style='font-size: 15px; display: block; margin-top: 3px;'>Unddit</a>");
  92. a.click(function() {
  93. window.location.hostname = window.location.hostname.replace("reddit", "unddit");
  94. return false;
  95. });
  96. $("body > div.side > div:nth-child(2) > div").append(a);
  97.  
  98. // auto-reload res
  99. let retry_reload = 30;
  100. let interval = setInterval(function() {
  101. $("#alert_message > input[type=button]").click();
  102. if (--retry_reload <= 0) {
  103. clearInterval(interval);
  104. }
  105. }, 100);
  106.  
  107. })(jQuery);