Youtube Embed NoCookie

Change any embedded youtube videos with the no-cookie version

  1. // ==UserScript==
  2. // @name Youtube Embed NoCookie
  3. // @namespace s
  4. // @description Change any embedded youtube videos with the no-cookie version
  5. // @include *
  6. // @exclude https://www.youtube.com/*
  7. // @version 1
  8. // @grant none
  9. // ==/UserScript==
  10. function func(item) {
  11. src = item.getAttribute('src');
  12. fixed = src.replace(/youtube.com\/embed/, 'youtube-nocookie.com/embed');
  13. if (src != fixed) {
  14. item.setAttribute('src', fixed);
  15. }
  16. }
  17. function updateiframes(m) {
  18. iframes = document.getElementsByTagName('iframe');
  19. for (var i = 0; i < iframes.length; i = i + 1) func(iframes[i]);
  20. }
  21.  
  22. // Observe mutations
  23. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
  24. if (MutationObserver) {
  25. var body = document.getElementsByTagName('body') [0];
  26. var mutationObserver = new MutationObserver(updateiframes);
  27. mutationObserver.observe(body, {
  28. childList: true,
  29. subtree: true
  30. });
  31. }
  32.  
  33. updateiframes(0);