Greasy Fork is available in English.

Add A Link To Hide All Reddit Posts

Add a link to hide all Reddit posts listed in currently logged-on user's page tab (Overview, Submitted, Downvoted, etc.). This script will auto-navigate to the next page (if any) and will continue hiding any hideable posts until the last page.

  1. // ==UserScript==
  2. // @name Add A Link To Hide All Reddit Posts
  3. // @namespace AddALinkToHideAllRedditPosts
  4. // @version 1.0.1
  5. // @description Add a link to hide all Reddit posts listed in currently logged-on user's page tab (Overview, Submitted, Downvoted, etc.). This script will auto-navigate to the next page (if any) and will continue hiding any hideable posts until the last page.
  6. // @author jcunews
  7. // @include *://*.reddit.com/user/*/*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. var hideLinks = document.querySelectorAll('.thing .hide-button a'), linkIndex = 0, hidePostsInProgress = false;
  12. if (hideLinks.length) {
  13. var rActionsTrigger = r.actions.trigger;
  14. r.actions.trigger = function(name, object) {
  15. if (hidePostsInProgress && (name === "legacy:change-state")) {
  16. var oldPostCallback = object.post_callback;
  17. object.post_callback = function(){
  18. var result, nextLink;
  19. if (oldPostCallback) {
  20. result = oldPostCallback.apply(this, arguments);
  21. }
  22. if (hidePostsInProgress) {
  23. if (++linkIndex < hideLinks.length) {
  24. hideLinks[linkIndex].click();
  25. } else {
  26. nextLink = document.querySelector(".nav-buttons .next-button a");
  27. if (nextLink) {
  28. nextLink.click();
  29. } else {
  30. hidePostsInProgress = false;
  31. delete sessionStorage.hidePostsInProgress;
  32. }
  33. }
  34. return result;
  35. }
  36. };
  37. }
  38. return rActionsTrigger.apply(this, arguments);
  39. };
  40. var menuArea = document.querySelector(".menuarea > .spacer");
  41. var link = document.createElement("A");
  42. link.textContent = "Hide All Posts";
  43. link.style.marginLeft = "2ex";
  44. link.href = "#";
  45. link.onclick = function() {
  46. if (!hidePostsInProgress) {
  47. hidePostsInProgress = true;
  48. sessionStorage.hidePostsInProgress = 1;
  49. hideLinks[0].click();
  50. }
  51. return false;
  52. };
  53. menuArea.appendChild(link);
  54. if (hidePostsInProgress = sessionStorage.hidePostsInProgress) {
  55. hideLinks[0].click();
  56. }
  57. } else {
  58. hidePostsInProgress = false;
  59. delete sessionStorage.hidePostsInProgress;
  60. }