Created
May 12, 2022 04:17
-
-
Save JenieX/435b012e15c3a355f0d601f210b7da0f to your computer and use it in GitHub Desktop.
Attempts to disable Reddit infinite scroll by the help of blocking the address that dynamically loads posts
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 An Attempt to Disable Reddit Infinite Scroll | |
// @namespace 1650776408 | |
// @description Attempts to disable Reddit infinite scroll by the help of blocking the address that dynamically loads posts | |
// @version 0.01 | |
// @author FlowrForWar | |
// @match https://www.reddit.com/r/* | |
// @grant none | |
// @run-at document-start | |
// @require https://greasyfork.org/scripts/12228/code/setMutationHandler.js | |
// @noframes | |
// @license MIT | |
// ==/UserScript== | |
/* | |
For this to work you need to block the the address that loads the posts dynamically | |
Add the following line as a rule in the "List of your dynamic filtering rules" of uBlock origin | |
www.reddit.com https://gateway.reddit.com/desktopapi/v1/subreddits/ xmlhttprequest block | |
See this image: https://raw.githubusercontent.com/FlowerForWar/An-Attempt-to-Disable-Reddit-Infinite-Scroll/main/ublock.png | |
*/ | |
setMutationHandler({ | |
selector: 'div', | |
processExisting: !1, | |
target: document, | |
childList: !0, | |
subtree: !0, | |
attributes: !1, | |
handler: nodes => { | |
for (let index = 0; index < nodes.length; index++) { | |
const node = nodes[index]; | |
if (node.textContent !== "Sorry, for some reason reddit can't be reached.Try again") continue; | |
// node.offsetParent.remove(); | |
// return !1; | |
const lastPost = [...document.querySelectorAll('div[data-testid="post-container"][id^="t3_"]')].pop(); | |
node.offsetParent.setAttribute('style', 'text-align: center; margin-top: 20px;'); | |
const href = `${location.origin}${location.pathname}?after=${lastPost.id}`; | |
const style = `border-radius: 4px; color: #FFF; white-space: nowrap; background-color: #E91E63; padding: 5px 20px 5px 20px; margin: 5px;`; | |
node.offsetParent.innerHTML = `<a href="${href}" style="${style}">NEXT ›</a>`; | |
return !1; | |
} | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment