Remove the "si" parameter from YouTube share links.
当前为
// ==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,
});
})();