Suppress YouTube seconds links

When opening a video from a playlist, strip out the parameters that make it start at a time

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Suppress YouTube seconds links
// @namespace    http://tampermonkey.net/
// @description  When opening a video from a playlist, strip out the parameters that make it start at a time
// @license MIT
// @author       Igor Makarov
// @match        *://*.youtube.com/playlist*
// @match        *://*.youtube.com/feed/history*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @version 0.0.1.20241227113853
// ==/UserScript==

var hrefsCount = 0;
function modifyLinks() {
    let hrefs = document.querySelectorAll('a');
    if (hrefs.length == hrefsCount) {
        return;
    }
    hrefsCount = hrefs.length;
    hrefs.forEach(link => {
        let href = link.href
        if (!href) {
            return;
        }
        // console.log(`href: ${href}`);
        let url = new URL(href, document.location);
        if (url.searchParams && url.searchParams.has('t')) {
            url.searchParams.delete('t');
        }
        link.href = url
        // console.log(`url: ${url}`);
    });
}

document.addEventListener('DOMContentLoaded', modifyLinks)
let observer = new MutationObserver(e => { modifyLinks() })
observer.observe(document, {
    subtree: true,
    //attributes: true,
    //characterData: true,
    childList: true
})