Add Link To Remove Old/Crowded Reddit Posts

Add a link on Reddit tab bar to remove posts on front page or subreddit which are older than N hours or has more than N number of comments.

目前为 2017-02-04 提交的版本。查看 最新版本

// ==UserScript==
// @name        Add Link To Remove Old/Crowded Reddit Posts
// @namespace   AddLinkToRemoveOldCrowdedRedditPosts
// @description Add a link on Reddit tab bar to remove posts on front page or subreddit which are older than N hours or has more than N number of comments.
// @include     https://www.reddit.com/*
// @version     1
// @author      jcunews
// @grant       none
// ==/UserScript==

(function() {
  //*** settings start ***
  var maxAge      = 10;   //in hours
  var maxComments = 500;
  //*** settings end ***

  //remove the posts
  function removePosts() {
    var posts = document.querySelectorAll(".content > .spacer > .sitetable > .thing");
    var time = (new Date()).valueOf(), maxAgeMs = maxAge*3600000, i, postTime, comments, link;
    for (i = posts.length-1; i >= 0; i--) {
      //get post's time
      postTime = parseInt(posts[i].getAttribute("data-timestamp"));
      //get post's number of comments
      comments = parseInt(posts[i].querySelector(".comments").textContent.match(/\d+/)[0]);
      //main decision
      if (((time-postTime) > maxAgeMs) || (comments > maxComments)) {
        //click "hide" link
        link = posts[i].querySelector(".hide-button a");
        if (link) {
          link.click();
        }
      }
    }
  }
  
  //add the link
  var tabmenu = document.querySelector("#header-bottom-left .tabmenu"), link;
  if (!tabmenu) return;
  link = document.createElement("A");
  link.textContent = "Remove Old/Crowded";
  link.style.marginLeft = "3ex"
  link.href = "javascript:void(0)";
  link.onclick = removePosts;
  tabmenu.appendChild(link);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址