Skip to content

Instantly share code, notes, and snippets.

@eramdam
Last active October 24, 2023 05:42
Show Gist options
  • Save eramdam/07e0060d0f6dc40dd480058dad226d24 to your computer and use it in GitHub Desktop.
Save eramdam/07e0060d0f6dc40dd480058dad226d24 to your computer and use it in GitHub Desktop.
// ==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