Fix Skip YouTube Ads Bug in Brave

For personal use only.

  1. // ==UserScript==
  2. // @name Fix Skip YouTube Ads Bug in Brave
  3. // @namespace Violentmonkey Scripts
  4. // @match https://www.youtube.com/*
  5. // @version 0.0.002
  6. // @author -
  7. // @license MIT
  8. // @run-at document-start
  9. // @grant none
  10. // @unwrap
  11. // @allFrames true
  12. // @inject-into page
  13. // @description For personal use only.
  14. // ==/UserScript==
  15.  
  16.  
  17. (() => {
  18.  
  19. let cid = 0;
  20.  
  21. const [setInterval_, clearInterval_, setTimeout_, clearTimeout_] = [setInterval, clearInterval, setTimeout, clearTimeout];
  22.  
  23. const Promise = (async () => { })().constructor;
  24.  
  25. let md1 = '';
  26. let md2 = 0;
  27. let qt = 0;
  28.  
  29. let wd1 = 0;
  30. let wd2 = 0;
  31.  
  32. const timerFn = () => {
  33.  
  34. const mps = [...document.querySelectorAll('#movie_player')].filter(e => !e.closest('[hidden]'));
  35. if (mps.length !== 1) return;
  36.  
  37. const media = mps[0].querySelectorAll('audio, video');
  38. if (media.length !== 1) return;
  39. const md = media[0];
  40.  
  41. if (Number.isFinite(md.currentTime) && md.currentTime > wd1 && md.currentTime > 0.1) {
  42. wd1 = md.currentTime;
  43. wd2++;
  44. } else if (Number.isFinite(md.currentTime) && md.currentTime > 0.1) {
  45.  
  46. } else {
  47. wd1 = 0;
  48. wd2 = 0;
  49. }
  50.  
  51. if (wd2 >= 3) {
  52. clearInterval_(cid);
  53. cid = 0;
  54. }
  55.  
  56. if (Number.isFinite(md.currentTime) && md.currentTime < 0.0001 && md.duration > 5 && (qt ? md.duration < qt + 5 : true)) {
  57. const t = `${md.currentTime}${md.duration}${md.src}`;
  58. if (md1 === t) md2++;
  59. else {
  60. md1 = t;
  61. md2 = 0;
  62. }
  63.  
  64. } else if (md2 > 0) {
  65. md1 = '';
  66. md2 = 0;
  67. }
  68.  
  69. if (md2 >= 3) {
  70. md.currentTime = md.duration;
  71. }
  72.  
  73. };
  74.  
  75. const triggerFn = async (m) => {
  76.  
  77. cid && clearInterval_(cid);
  78. cid = 0;
  79. if (m !== null) qt = +m;
  80. md1 = '';
  81. md2 = 0;
  82. wd1 = 0;
  83. wd2 = 0;
  84.  
  85. const conditionCheck = () => {
  86.  
  87. const mps = [...document.querySelectorAll('#movie_player')].filter(e => !e.closest('[hidden]'));
  88. if (mps.length !== 1) return false;
  89.  
  90. const media = mps[0].querySelectorAll('audio, video');
  91. if (media.length !== 1) return false;
  92.  
  93. return true;
  94. }
  95.  
  96. let tryCount = 8;
  97. while (r = !conditionCheck()) {
  98. await new Promise(r => setTimeout_(r), 80);
  99. if (--tryCount <= 0) break;
  100. }
  101.  
  102. if (!cid && !r) cid = setInterval_(timerFn, 250);
  103.  
  104. }
  105.  
  106. document.addEventListener('yt-page-data-fetched', (evt) => {
  107. const pageFetchedDataLocal = evt.detail;
  108. const m = pageFetchedDataLocal?.pageData?.playerResponse?.videoDetails?.lengthSeconds;
  109. triggerFn(m);
  110. }, false);
  111.  
  112. document.addEventListener('durationchange', (evt) => {
  113. if (evt.target instanceof HTMLMediaElement) {
  114. triggerFn();
  115. }
  116. }, true);
  117.  
  118. })();
  119.  
  120.  

QingJ © 2025

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