Created
November 27, 2021 17:08
-
-
Save vic4key/d55fd7f21e45768477bfbad1b63d6b0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Reddit - Hide More Posts Section | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author Vic P. @ https://vic.onl/ | |
// @match https://www.reddit.com/r/*/comments/* | |
// @icon https://www.google.com/s2/favicons?domain=reddit.com | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js | |
// @run-at document-start | |
// @grant none | |
// ==/UserScript== | |
let log = (...args) => console.log(`%cReddit -`, 'font-weight: bold; color: yellow;', ...args) | |
let reddit_find_and_hide_more_posts = function() { | |
try { | |
$("div").each((i, e) => { | |
if (e.textContent.startsWith("More posts") && e.firstChild.nodeName == "DIV") { | |
throw e; | |
} | |
}); | |
} catch (e) { | |
$(`.${e.className}`).hide("slow"); | |
return e; | |
} | |
return null; | |
} | |
window.onload = function () { | |
let retry = 0; | |
let timer = setInterval(() => { | |
log("finding more posts section..."); | |
let target = reddit_find_and_hide_more_posts(); | |
if (target != null) { | |
log(`found and hidden the section '${target.textContent}'`); | |
log(target); | |
clearInterval(timer); | |
} | |
if (++retry >= 5) { | |
log("timeout, finding stopped, seems no more posts section"); | |
clearInterval(timer); | |
} | |
}, 1000); | |
}; | |
(function() { | |
'use strict'; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment