Youtube adblock replace with embed

I like to do a little trolling on youtube. This lets you keep adblocker on and simply replaces the video html with an iframe of it's own embed. Take that, Google!

  1. // ==UserScript==
  2. // @name Youtube adblock replace with embed
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description I like to do a little trolling on youtube. This lets you keep adblocker on and simply replaces the video html with an iframe of it's own embed. Take that, Google!
  6. // @author You
  7. // @match https://www.youtube.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. const checkElementInterval = setInterval(function() {
  13. const targetNode = document.querySelector('#title.ytd-watch-metadata h1 yt-formatted-string');
  14.  
  15. if (targetNode !== null) {
  16. clearInterval(checkElementInterval); // Clear the interval
  17. console.log('Element loaded');
  18. document.querySelector('#player').innerHTML = `<iframe style="width: 100%; height: 65vh;" src="https://www.youtube.com/embed/${location.href.split('?v=')[1].split('&')[0]}?autoplay=1&auto_play=1"></iframe>`
  19. }
  20. }, 500);
  21.  
  22. let currentURL = window.location.href;
  23.  
  24. function watchURLChange() {
  25. if (window.location.href !== currentURL) {
  26. console.log('URL changed');
  27. currentURL = window.location.href;
  28. if(location.href.includes("youtube.com/watch")){
  29. document.querySelector('#player').innerHTML = `<iframe style="width: 100%; height: 65vh;" src="https://www.youtube.com/embed/${location.href.split('?v=')[1].split('&')[0]}?autoplay=1&auto_play=1"></iframe>`
  30. } else {
  31. document.querySelector('#player').innerHTML = ""
  32. }
  33. }
  34. }
  35.  
  36. // Set up a timer to periodically check for URL changes
  37. setInterval(watchURLChange, 250);