YouTube Time Parameter Remover

Remove the &t=*s parameter from YouTube URLs

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         YouTube Time Parameter Remover
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Remove the &t=*s parameter from YouTube URLs
// @author       Rehan Ahmad
// @match        https://www.youtube.com/*
// @icon         https://raw.githubusercontent.com/r280822a/YouTube-Time-Parameter-Remover/refs/heads/main/icon/icon.png
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';

    function cleanURL() {
        const url = new URL(window.location.href);
        const params = url.searchParams;

        // If 't' parameter exists, remove it
        if (params.has('t')) {
            params.delete('t');
            const cleanUrl = url.origin + url.pathname + '?' + params.toString();

            // Replace the URL without reloading the page
            window.history.replaceState({}, '', cleanUrl);
            console.log('Replaced timestamp parameter in URL');
        }
    }

    // Run on page load
    window.addEventListener('load', cleanURL);

    // Detect URL changes
    let lastUrl = location.href;
    new MutationObserver(() => {
        const currentUrl = location.href;
        if (currentUrl !== lastUrl) {
            lastUrl = currentUrl;
            cleanURL();
        }
    }).observe(document, { subtree: true, childList: true });
})();