Last active
May 14, 2018 17:16
-
-
Save creesch/783b64a28d14ea094c354c66e96e9d19 to your computer and use it in GitHub Desktop.
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 expand on scroll | |
| // @version 0.4 | |
| // @require https://raw.githubusercontent.com/vvo/in-viewport/46aa0be7cb688613213b16693d4501b61071d45e/build/in-viewport.min.js | |
| // @author Creesch | |
| // @match https://new.reddit.com/* | |
| // @grant none | |
| // @run-at document-end | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| function visible(expando) { | |
| window.requestAnimationFrame(function() { | |
| expando.click(); | |
| }); | |
| } | |
| // Function to handle incoming events. | |
| function handleEvent(e) { | |
| if(e.detail.type === 'post') { | |
| const post = e.target.closest('.Post'); | |
| const expando = post.querySelector('button[data-click-id="expando_open"]'); | |
| if(expando) { | |
| inViewport(expando, { | |
| offset: 300 | |
| }, visible); | |
| } | |
| } | |
| } | |
| // Ready the event listener | |
| document.addEventListener('reddit', handleEvent, true); | |
| // Let reddit know you are ready | |
| const data = { | |
| name: 'expand-all', // optional | |
| }; | |
| const event = new CustomEvent('reddit.ready', { detail: data }); | |
| document.dispatchEvent(event); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment