Reddit Enhancements

Some small enhancements for reddit (RES needed)

当前为 2019-05-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Reddit Enhancements
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description Some small enhancements for reddit (RES needed)
  6. // @icon data:image/webp;base64,UklGRrwBAABXRUJQVlA4TLABAAAvP8APAK+goG0bhj/ddv/SMJC2TXr/ls8Utm2k7L/rMT7//Mfvr29tSyUrvpCacd2glC8IERWbAUJEGSIIODeWuw1wA4Bt24Ck2AvY8P+xJmiK3pIlov8TQH/fZ6mDaTGUeR8CCB1Km1QEANhxXQRnBABIK+EzX2eh06jZP7C2t0350BpX7rYGnhlqUS6bBTIzqwQAPy+jAJUh6jlVul6LsfGTQxj67QrhxzKUH/PQfqZjDs5IMC5k7Ne1ZOBLk9pNaOGoxdeaV9Lk2Swct21mI5Vvh1DApxHwojDwKfBIl3Cx7CcSXJ1OuLvcWzL3gXpH4+hZvpW2kIioP9zTiYhwK53ocsPQMnOZlmZD9hOEgvMr5HDlOYF0tinGrDKXV4ZRjU5zUD+G5vT4qMA+9J4qk5qFTdtoFnWB4QCkgi+VhE1zLuy8G87hLXhu6jv0PEe4YZPYE8luIL0ZuELNCU64RoUL9OqwjEKiXqJ3zsfSiVAxdrxDw60ALA5iB1pg3aCX54wMgDAh5ZyCEcCKOOnCqpmDutKds+gzuky6t4bnmydUur2V6Myj1GNcLI3+LwI=
  7. // @author mattiadr96@gmail.com
  8. // @match http*://*.reddit.com/*
  9. // @grant none
  10. // @noframes
  11. // ==/UserScript==
  12.  
  13. (function($) {
  14. "use strict";
  15.  
  16. // middle click to collapse
  17. $(document).on("mousedown", function(e) {
  18. if (e.button == 1) {
  19. // ignore links
  20. if ($(":hover").last().is("a")) {
  21. return;
  22. }
  23. let entry = $(":hover").filter(".entry").find("a.toggleChildren");
  24. if (entry.length > 0) {
  25. entry[0].click();
  26. }
  27. return false;
  28. }
  29. });
  30.  
  31. // click on shortlink to copy
  32. $("#shortlink-text").on("click", function(e) {
  33. document.execCommand("copy");
  34. });
  35.  
  36. // spoilers improvement
  37. /* not working
  38. $("head").append(`
  39. <style type="text/css">
  40. a[href="/s"].hover {
  41. color: #f44!important;
  42. }
  43.  
  44. a[href="/s"].hover:after {
  45. color: #FFF!important;
  46. }
  47. </style>`);
  48.  
  49. $(document).on("click", function(e) {
  50. let a = $(":hover").filter("a[href='/s']");
  51. if (a.length > 0) {
  52. e.preventDefault();
  53. a.toggleClass("hover");
  54. }
  55. });
  56. */
  57.  
  58. // color save/unsave button
  59. $(".save-button > a:contains('unsave')").css("color", "gold");
  60.  
  61. $(".save-button > a").on("click", function(e) {
  62. e.target.style.color = (e.target.text == "save") ? "gold" : "";
  63. });
  64.  
  65. // goto removeddit
  66. let a = $("<a href='#' onclick='return false;' style='font-size: 15px; display: block; margin-top: 3px;'>Removeddit</a>");
  67. a.click(function() {
  68. window.location.hostname = window.location.hostname.replace("reddit", "removeddit");
  69. return false;
  70. });
  71. $("body > div.side > div:nth-child(2) > div").append(a);
  72.  
  73. })(jQuery);