Youtube - No scroll to top on timestamps

Prevent Youtube scrolling to top when clicking timestamps in description or comments

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Youtube - No scroll to top on timestamps
// @namespace    q1k
// @version      1.3
// @description  Prevent Youtube scrolling to top when clicking timestamps in description or comments
// @author       q1k
// @match        *://www.youtube.com/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

var seconds=0;

function timestampToSeconds(t){
    let parts = t.split(':').reverse();
    if (parts.length<2){ return false; }
    seconds = 0;
    for(let i=0; i<parts.length; i++){
        switch (i) {
            case 0: seconds += (+parts[i]); break;
            case 1: seconds += (+parts[i])*60; break;
            case 2: seconds += (+parts[i])*60*60; break;
            case 3: seconds += (+parts[i])*60*60*24; break;
        }
    }
    return Number.isInteger(seconds);
}

document.addEventListener("click", function(e){
    if(e.target.tagName=="A"){
        if(timestampToSeconds(e.target.innerText)){
            e.preventDefault();
            e.stopPropagation();
            e.stopImmediatePropagation();
            movie_player.seekTo(seconds);
            return;
        }
    } else if(e.target.closest("a#endpoint")){/*chapters*/
        if(timestampToSeconds(e.target.closest("a#endpoint").querySelector("#details #time").innerText)){
            e.preventDefault();
            e.stopPropagation();
            e.stopImmediatePropagation();
            movie_player.seekTo(seconds);
            return;
        }
    }
}, {capture: true} );