jcunews

HideOldRedditFrontpageOldPosts.user.js

Jan 26th, 2021 (edited)
176
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Hide Old Reddit Frontpage Old Posts
  3. // @namespace    https://greasyfork.org/en/users/85671-jcunews
  4. // @version      1.0.3
  5. // @license      AGPLv3
  6. // @author       jcunews
  7. // @description  https://www.reddit.com/r/GreaseMonkey/comments/l5i3mw/request_script_that_removes_hides_stale_reddit/
  8. // @match        https://*.reddit.com/
  9. // @match        https://*.reddit.com/?*
  10. // @match        https://*.reddit.com/hot/*
  11. // @match        https://*.reddit.com/new/*
  12. // @match        https://*.reddit.com/rising/*
  13. // @match        https://*.reddit.com/controversial/*
  14. // @match        https://*.reddit.com/top/*
  15. // @match        https://*.reddit.com/gilded/*
  16. // @grant        none
  17. // ==/UserScript==
  18.  
  19. ((ele, link) => {
  20.  
  21.   var maxAgeHours = 20;
  22.   var maxUpVotes  = 100;
  23.   var maxComments = 50;
  24.  
  25.   if (!(ele = document.querySelector(".tabmenu"))) return;
  26.   ele.appendChild(link = document.createElement("A")).textContent = "[Hide Olds]";
  27.   link.style.marginLeft = "1em";
  28.   link.href = "#";
  29.   link.onclick = () => {
  30.     var now = new Date;
  31.     Array.from(document.querySelectorAll(".sitetable .thing")).forEach(
  32.       (post, index) => {
  33.         var
  34.           posttime = new Date(parseInt(post.dataset.timestamp)),
  35.           eleVotes = post.querySelector(".score.unvoted"),
  36.           comments = post.dataset.commentsCount,
  37.           eleHide = post.querySelector(".hide-button a");
  38.         if (isNaN(posttime) || !eleVotes || !comments || !eleHide) return;
  39.         if (
  40.           ((now - posttime) > maxAgeHours * 60*60*1000) ||
  41.           (parseInt(eleVotes.title) > maxUpVotes) ||
  42.           (parseInt(comments) > maxComments)
  43.         ) eleHide.click()
  44.       }
  45.     );
  46.     return false
  47.   }
  48. })()
  49.  
RAW Paste Data