Skip to content

Instantly share code, notes, and snippets.

@kiliman
Last active October 27, 2023 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiliman/93c836fa8d43bb5085448ead2a261ccc to your computer and use it in GitHub Desktop.
Save kiliman/93c836fa8d43bb5085448ead2a261ccc to your computer and use it in GitHub Desktop.
TamperMonkey script to fix Twitter scroll handling on replies
// ==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