Greasy Fork镜像 支持简体中文。

Bypass Youtube Video Player Blocker

Bypass Youtube's Adblocker detector by embedding videos and playlists

  1. // ==UserScript==
  2. // @name Bypass Youtube Video Player Blocker
  3. // @version 1.5
  4. // @description Bypass Youtube's Adblocker detector by embedding videos and playlists
  5. // @author Misnomer
  6. // @match https://www.youtube.com/watch?v=*
  7. // @match https://www.youtube.com/playlist?list=*
  8. // @match https://www.youtu.be/watch?v=*
  9. // @license MIT
  10. // @namespace https://gf.qytechs.cn/users/1215479
  11. // ==/UserScript==
  12.  
  13.  
  14.  
  15. (function () {
  16. 'use strict';
  17.  
  18. class YoutubeEmbedder {
  19. constructor() {
  20. this.IFRAME_ID = '';
  21. this.URL = '';
  22. this.WIDTH = 0;
  23. this.HEIGHT = 0;
  24. this.PLAYER = null;
  25. }
  26.  
  27. uuid() {
  28. return 'embedded-youtube-' + Math.random().toString(36).substring(7);
  29. }
  30.  
  31. getVID() {
  32. return this.URL.match(/v=([^&]+)/)[1];
  33. }
  34.  
  35. setDimension() {
  36. this.HEIGHT = this.PLAYER.clientHeight;
  37. this.WIDTH = this.PLAYER.clientWidth;
  38. }
  39.  
  40. removeExistingIframe() {
  41. const embeddedIframe = document.getElementById(this.IFRAME_ID);
  42. if (embeddedIframe) embeddedIframe.remove();
  43. }
  44.  
  45. mbed() {
  46. const iframe = document.createElement('iframe');
  47.  
  48. iframe.id = this.IFRAME_ID;
  49. iframe.src = `https://www.youtube.com/embed/${this.getVID()}`;
  50. iframe.width = this.WIDTH + 'px';
  51. iframe.height = this.HEIGHT + 'px';
  52. iframe.style.border = 'none';
  53. iframe.setAttribute('allow', 'autoplay');
  54. iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
  55. iframe.addEventListener('load', function () {
  56. const iframeDocument = this.contentDocument || this.contentWindow.document;
  57. const videoElement = iframeDocument.querySelector('video');
  58. if (videoElement) videoElement.click();
  59. });
  60.  
  61. this.PLAYER.innerHTML = '';
  62. this.PLAYER.appendChild(iframe);
  63. }
  64.  
  65. update() {
  66. if (this.URL === window.location.href) return;
  67.  
  68. this.removeExistingIframe();
  69. this.IFRAME_ID = this.uuid();
  70. this.URL = window.location.href;
  71. this.mbed();
  72. }
  73.  
  74. start() {
  75. this.PLAYER = document.querySelector('#player');
  76.  
  77. if(this.PLAYER) {
  78. this.setDimension();
  79. setInterval(() => this.update(), 1000);
  80. }
  81. else {
  82. setTimeout(() => this.start(), 1000);
  83. }
  84. }
  85.  
  86. }
  87.  
  88. const youtubeEmbedder = new YoutubeEmbedder();
  89. youtubeEmbedder.start();
  90.  
  91. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址