Last active
October 24, 2023 05:42
-
-
Save eramdam/07e0060d0f6dc40dd480058dad226d24 to your computer and use it in GitHub Desktop.
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 Click header to scroll to the top | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description try to take over the world! | |
// @author Damien Erambert (Eramdam) | |
// @match https://cohost.org/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=cohost.org | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const header = document.querySelector('#app > div > header'); | |
if (header) { | |
header.addEventListener('click', () => { | |
const isOnFollowing = window.location.href.includes('/rc/project/following'); | |
const scrollableElement = isOnFollowing ? document.querySelector('#app > div > header + div > .styled-scrollbars-light > ul + div + div > div + div') : document.documentElement; | |
if (!scrollableElement) { | |
return; | |
} | |
if (scrollableElement.scrollTop > 10) { | |
scrollableElement.scrollTo({ | |
top: 0, | |
behavior: "smooth" | |
}) | |
} | |
}) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment