Skip to content

Instantly share code, notes, and snippets.

@broquaint
Last active September 25, 2020 22:59
Show Gist options
  • Select an option

  • Save broquaint/52c14900f45bee3816997e48ebdabee4 to your computer and use it in GitHub Desktop.

Select an option

Save broquaint/52c14900f45bee3816997e48ebdabee4 to your computer and use it in GitHub Desktop.
Greasemonkey userscript to visually divide scrolled in content on Reddit
// ==UserScript==
// @name Reddit - Visually divide scrolled in content
// @version 1
// @grant none
// @include https://www.reddit.com/*
// ==/UserScript==
const dividerCls = 'gm-section-divider',
dividerStyle = `
.${dividerCls} {
text-align: center;
border-top: solid 1px black;
border-bottom: solid 1px black;
margin-bottom: 7px;
font-weight: bold;
}
`;
const sheet = document.head.appendChild(document.createElement('style')).sheet;
sheet.insertRule(dividerStyle, 0);
var count = 1;
function addMarker() {
// Get the div containing posts.
const posts = document.querySelector('.scrollerItem').parentNode.parentNode.parentNode,
lastKid = posts.childNodes[posts.childNodes.length - 1];
// Add a divider which shows the number of sections added.
if(!lastKid.classList.contains(dividerCls)) {
const div = document.createElement('div');
div.className = dividerCls;
div.textContent = count++;
posts.appendChild(div);
}
}
setInterval(addMarker, 1000);
@blairdow
Copy link

this works great, thanks! i added a background color to the css and a border radius of 4px so i could see the divider in dark mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment