Last active
October 27, 2023 15:34
-
-
Save kiliman/93c836fa8d43bb5085448ead2a261ccc to your computer and use it in GitHub Desktop.
TamperMonkey script to fix Twitter scroll handling on replies
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 Twitter Scroll Restore | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author @kiliman | |
// @match https://twitter.com/* | |
// @icon https://www.google.com/s2/favicons?domain=twitter.com | |
// @grant none | |
// ==/UserScript== | |
;(function () { | |
'use strict' | |
const scrollMap = new Map() | |
addEventListener('scroll', () => { | |
if (document.location.href.endsWith('/home')) return | |
scrollMap.set(document.location.href, window.scrollY) | |
}) | |
addEventListener('popstate', () => { | |
if (document.location.href.endsWith('/home')) return | |
const scrollY = scrollMap.get(document.location.href) ?? 0 | |
setTimeout(() => window.scrollTo(0, scrollY), 100) | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment