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 the same youtube video's embed so you can keep your adblocker on. Take that, Google!

目前為 2023-10-19 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Youtube adblock replace with embed
  3. // @namespace http://tampermonkey.net/
  4. // @version 1
  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 the same youtube video's embed so you can keep your adblocker on. Take that, Google!
  6. // @author Dildoer the Cocknight
  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. 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>`
  29.  
  30. }
  31. }
  32.  
  33. // Set up a timer to periodically check for URL changes
  34. setInterval(watchURLChange, 250);