Last active
December 7, 2018 02:51
-
-
Save RickyCook/72fc3a971a638b10864d98ffe3fc2ffd to your computer and use it in GitHub Desktop.
A TamperMonkey script that hides the Reddit post list "underlay" when you open a post thread
This file contains hidden or 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 RedditHider | |
// @namespace https://www.reddit.com | |
// @version 0.2 | |
// @description Hide Reddit main page when a thread is opened | |
// @author Ricky Cook | |
// @include https://www.reddit.com/* | |
// @grant none | |
// @updateURL https://gist.githubusercontent.com/RickyCook/72fc3a971a638b10864d98ffe3fc2ffd/raw/main.js | |
// ==/UserScript== | |
(function() { | |
var toggleEls = [] | |
function isOverlay() { | |
return document.location.pathname.startsWith('/r/') | |
} | |
function underlayEls() { | |
var wrapper = document.getElementsByClassName('m-commentspage')[0] | |
if (!wrapper) return toggleEls | |
return Array.from(wrapper.parentElement.children).filter(function(el) { | |
if (el === wrapper) return false | |
if (el.tagName.toUpperCase() !== 'DIV') return false | |
return true | |
}) | |
} | |
function ensureState(hidden) { | |
toggleEls = underlayEls() | |
for (var el of toggleEls) { | |
el.style.visibility = hidden ? 'hidden' : null | |
} | |
} | |
var lastPath = null, lastHidden = null | |
setInterval(function() { | |
if (document.location.pathname === lastPath) return | |
console.log('changed location') | |
lastPath = document.location.pathname | |
ensureState(isOverlay()) | |
}, 100) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment