Remove YouTube Share Identifier

Remove the "si" parameter from YouTube share links.

当前为 2025-04-07 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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,
	});
})();