Remove YouTube Share Identifier

Remove the "si" parameter from YouTube share links.

目前為 2025-04-07 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            Remove YouTube Share Identifier
// @name:vi         Xóa Định Danh Chia Sẻ YouTube
// @namespace       https://greasyfork.org/en/users/1240674-anhkhoakz
// @version         1.0.0
// @match           *://*.youtube.com/watch*
// @license         GPLv3; https://www.gnu.org/licenses/gpl-3.0.html#license-text
// @icon            https://i.imgur.com/f1OgZDI.png
// @grant           none
// @description     Remove the "si" parameter from YouTube share links.
// @description:vi  Xóa tham số "SI" khỏi các liên kết chia sẻ YouTube.
// @author          anhkhoakz; https://www.anhkhoakz.dev/
// ==/UserScript==

(() => {
	"use strict";

	/**
	 * Observes mutations in the DOM and processes added nodes.
	 * @param {MutationRecord[]} mutationsList - List of mutations observed.
	 */
	const observer = new MutationObserver((mutationsList) => {
		/**
		 * Filters added nodes to find "YT-COPY-LINK-RENDERER" elements.
		 * @type {HTMLElement[]}
		 */
		const filtered = mutationsList
			.filter(
				(x) =>
					x.addedNodes[0] &&
					/** @type {HTMLElement} */ (x.addedNodes[0]).tagName ===
						"YT-COPY-LINK-RENDERER"
			)
			.map((x) => /** @type {HTMLElement} */ (x.addedNodes[0]));

		if (!filtered.length) {
			return;
		}

		/** @type {HTMLInputElement | null} */
		const url_field = filtered[0].querySelector("input#share-url");
		if (!url_field) {
			return;
		}

		/**
		 * Splits and filters the URL to remove the "si" parameter.
		 * @type {string[]}
		 */
		const split = url_field.value
			.split(/[?&]/)
			.filter((x) => !x.includes("si="));
		url_field.value =
			split.length > 1 ? `${split[0]}?${split.slice(1).join("&")}` : split[0];

		let last_value = url_field.value;

		/**
		 * Updates the URL field value by removing the "si" parameter.
		 */
		const update_url = () => {
			if (!url_field) {
				return;
			}
			if (url_field.value === last_value) {
				return;
			}
			const split = url_field.value
				.split(/[?&]/)
				.filter((/** @type {string} */ x) => !x.includes("si="));
			url_field.value =
				split.length > 1 ? `${split[0]}?${split.slice(1).join("&")}` : split[0];
			last_value = url_field.value;
			window.requestAnimationFrame(update_url);
		};
		window.requestAnimationFrame(update_url);
	});

	observer.observe(document.documentElement, {
		childList: true,
		subtree: true,
	});
})();