// ==UserScript== // @name Twitter Endless Scroll // @namespace Twitter // @version 1.3 // @description Endless scrolling between image posts with mousewheel // @author NightLancerX // @match https://twitter.com/* // @match https://mobile.twitter.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com // @license CC-BY-NC-SA // @grant none // @require https://code.jquery.com/jquery-3.3.1.min.js // @run-at document-end // @noframes // @downloadURL none // ==/UserScript== (function() { 'use strict'; let nextPost; function changePost(shift){ let selector = 'img[src*="https://pbs.twimg.com/media/"]'; let posts = $(`article:has(${selector})`).toArray(); let index = posts.indexOf($(`[href='${location.pathname}']`).parents('article')[0]); if (shift<0) nextPost = [...posts[index+shift]?.querySelectorAll(selector)||[]].pop(); else nextPost = posts[index+shift]?.querySelector(selector); nextPost?.scrollIntoView(); nextPost?.click(); } $('body').on('wheel', '[aria-labelledby="modal-header"]', function(e){ e.preventDefault(); e.stopPropagation(); let left; if (e.originalEvent.deltaY < 0){ if (left = document.querySelector('[data-testid="Carousel-NavLeft"]')) left.click(); else changePost(-1); } let right; if (e.originalEvent.deltaY > 0){ if (right = document.querySelector('[data-testid="Carousel-NavRight"]')) right.click(); else changePost(+1); } }); $('body').on('click', '[aria-labelledby="modal-header"] [data-testid="swipe-to-dismiss"]', function(e){ setTimeout(()=>{ let offset = nextPost?.closest('[data-testid="cellInnerDiv"]').style.transform.match(/\d+/)?.[0]; window.scroll(0, offset); }, 500); }) })();