Remove YouTube Share Identifier

Remove the "si" parameter from YouTube share links.

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

  1. // ==UserScript==
  2. // @name Remove YouTube Share Identifier
  3. // @name:vi Xóa Định Danh Chia Sẻ YouTube
  4. // @namespace https://greasyfork.org/en/users/1240674-anhkhoakz
  5. // @version 1.0.0
  6. // @match *://*.youtube.com/watch*
  7. // @license GPLv3; https://www.gnu.org/licenses/gpl-3.0.html#license-text
  8. // @icon https://i.imgur.com/f1OgZDI.png
  9. // @grant none
  10. // @description Remove the "si" parameter from YouTube share links.
  11. // @description:vi Xóa tham số "SI" khỏi các liên kết chia sẻ YouTube.
  12. // @author anhkhoakz; https://www.anhkhoakz.dev/
  13. // ==/UserScript==
  14.  
  15. (() => {
  16. "use strict";
  17.  
  18. /**
  19. * Observes mutations in the DOM and processes added nodes.
  20. * @param {MutationRecord[]} mutationsList - List of mutations observed.
  21. */
  22. const observer = new MutationObserver((mutationsList) => {
  23. /**
  24. * Filters added nodes to find "YT-COPY-LINK-RENDERER" elements.
  25. * @type {HTMLElement[]}
  26. */
  27. const filtered = mutationsList
  28. .filter(
  29. (x) =>
  30. x.addedNodes[0] &&
  31. /** @type {HTMLElement} */ (x.addedNodes[0]).tagName ===
  32. "YT-COPY-LINK-RENDERER"
  33. )
  34. .map((x) => /** @type {HTMLElement} */ (x.addedNodes[0]));
  35.  
  36. if (!filtered.length) {
  37. return;
  38. }
  39.  
  40. /** @type {HTMLInputElement | null} */
  41. const url_field = filtered[0].querySelector("input#share-url");
  42. if (!url_field) {
  43. return;
  44. }
  45.  
  46. /**
  47. * Splits and filters the URL to remove the "si" parameter.
  48. * @type {string[]}
  49. */
  50. const split = url_field.value
  51. .split(/[?&]/)
  52. .filter((x) => !x.includes("si="));
  53. url_field.value =
  54. split.length > 1 ? `${split[0]}?${split.slice(1).join("&")}` : split[0];
  55.  
  56. let last_value = url_field.value;
  57.  
  58. /**
  59. * Updates the URL field value by removing the "si" parameter.
  60. */
  61. const update_url = () => {
  62. if (!url_field) {
  63. return;
  64. }
  65. if (url_field.value === last_value) {
  66. return;
  67. }
  68. const split = url_field.value
  69. .split(/[?&]/)
  70. .filter((/** @type {string} */ x) => !x.includes("si="));
  71. url_field.value =
  72. split.length > 1 ? `${split[0]}?${split.slice(1).join("&")}` : split[0];
  73. last_value = url_field.value;
  74. window.requestAnimationFrame(update_url);
  75. };
  76. window.requestAnimationFrame(update_url);
  77. });
  78.  
  79. observer.observe(document.documentElement, {
  80. childList: true,
  81. subtree: true,
  82. });
  83. })();