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.
当前为
// ==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);
})();