Remove Youtube Block

I'm not going to uninstall adblocker, Youtube. Never.

目前为 2023-11-11 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Remove Youtube Block
  3. // @version 1.3
  4. // @description I'm not going to uninstall adblocker, Youtube. Never.
  5. // @author Misnomer
  6. // @match https://www.youtube.com/*
  7. // @license MIT
  8. // @namespace https://greasyfork.org/users/1215479
  9. // ==/UserScript==
  10.  
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const IFRAME_ID = 'embedded-youtube-' + Math.random().toString(36).substring(7);
  16.  
  17. function embedYouTubeIframe() {
  18. const isExistIframe = document.getElementById(IFRAME_ID);
  19. const playerDiv = document.getElementById('player');
  20.  
  21. if (!playerDiv) return;
  22.  
  23. if (isExistIframe) {
  24. clearInterval(intervalId);
  25. return;
  26. }
  27.  
  28. const currentUrl = window.location.href;
  29.  
  30. if (currentUrl.includes('/watch')) {
  31. const videoId = currentUrl.match(/v=([^&]+)/)[1];
  32. const embedUrl = `https://www.youtube.com/embed/${videoId}`;
  33. const playerWidth = playerDiv.clientWidth;
  34. const playerHeight = playerDiv.clientHeight;
  35.  
  36. const iframe = document.createElement('iframe');
  37. iframe.id = IFRAME_ID;
  38. iframe.src = embedUrl;
  39. iframe.width = playerWidth + 'px';
  40. iframe.height = playerHeight + 'px';
  41. iframe.style.border = 'none';
  42.  
  43. const wrapperDiv = document.createElement('div');
  44. wrapperDiv.style.width = playerWidth + 'px';
  45. wrapperDiv.style.height = playerHeight + 'px';
  46. wrapperDiv.appendChild(iframe);
  47.  
  48. playerDiv.innerHTML = '';
  49. playerDiv.appendChild(wrapperDiv);
  50. }
  51. }
  52.  
  53. const intervalId = setInterval(embedYouTubeIframe, 1000); //Trying to make it seemless but this might cause performance issue the lower the value.
  54.  
  55. })();