Last active
September 25, 2020 22:59
-
-
Save broquaint/52c14900f45bee3816997e48ebdabee4 to your computer and use it in GitHub Desktop.
Greasemonkey userscript to visually divide scrolled in content on Reddit
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 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.