Remove tracker from Youtube sharing URL

This UserScript removes trackers from YouTube sharing URLs.

目前为 2023-12-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Remove tracker from Youtube sharing URL
  3. // @namespace https://github.com/shiquda/shiquda_UserScript
  4. // @supportURL https://github.com/shiquda/shiquda_UserScript/issues
  5. // @version 0.1.1
  6. // @description This UserScript removes trackers from YouTube sharing URLs.
  7. // @author shiquda
  8. // @match https://www.youtube.com/watch?v=*
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. function removeParam() {
  15. let url = document.querySelector('#share-url');
  16. if (url) {
  17. let urlObj = new URL(url.value);
  18. urlObj.searchParams.delete('si');
  19. url.value = urlObj.href;
  20. console.log(url.value);
  21. }
  22. }
  23.  
  24. const observer = new MutationObserver((mutationsList, observer) => {
  25. for (let mutation of mutationsList) {
  26. if (mutation.type === 'childList') {
  27. let url = document.querySelector('#share-url');
  28. if (url) {
  29. url.addEventListener('change', removeParam);
  30. document.querySelector('#checkboxContainer').addEventListener('click', removeParam);
  31. document.querySelector('#copy-button').addEventListener('click', removeParam)
  32. document.querySelector('#input-2').addEventListener('blur', removeParam);
  33. removeParam();
  34. }
  35. }
  36. }
  37. });
  38.  
  39. observer.observe(document, { childList: true, subtree: true });
  40. })();