Youtube - Advertisement Hide

Выключает рекламу или звук в рекламе на ресурсе Youtube

  1. // ==UserScript==
  2. // @name Youtube - Advertisement Hide
  3. // @namespace scriptomatika
  4. // @author mouse-karaganda
  5. // @description Выключает рекламу или звук в рекламе на ресурсе Youtube
  6. // @license MIT
  7. // @include https://*.youtube.com/*
  8. // @require https://greasyfork.org/scripts/379902-include-tools/code/Include%20Tools.js
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=www.youtube.com
  10. // @version 1.5
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. let console = window.console;
  16. let $ = window.jQuery;
  17. let $$ = window.__krokodil;
  18.  
  19. $$.renderStyle(
  20. '',
  21. ''
  22. );
  23.  
  24. window.greasyMovieVolumeOn = false;
  25.  
  26. /**
  27. * Выключает звук на внутренней рекламе
  28. */
  29. let muteInternalAdverts = function() {
  30. let button;
  31.  
  32. if (button = $$.get(`.ytp-ad-overlay-slot .ytp-ad-overlay-close-button`)) {
  33. $$.fireEvent(button, 'click');
  34. }
  35. if (button = $$.get(`.video-ads .ytp-ad-skip-button-container`)) {
  36. $$.fireEvent(button, 'click');
  37. }
  38. // Сравнивать по строковому значению title - ужасно.
  39. // Но другого способа нет, потому что не меняются другие атрибуты
  40. if (button = $$.get(`.ytp-ad-preview-container`)) {
  41. if (button = $$.get(`#movie_player .ytp-mute-button[title^="Отключение звука"]`)) {
  42. $$.fireEvent(button, 'click');
  43. }
  44. window.greasyMovieVolumeOn = false;
  45. } else {
  46. if (!window.greasyMovieVolumeOn) {
  47. if (button = $$.get(`#movie_player .ytp-mute-button[title^="Включить звук"]`)) {
  48. $$.fireEvent(button, 'click');
  49. }
  50. window.greasyMovieVolumeOn = true;
  51. }
  52. }
  53. };
  54.  
  55. if (false) {
  56. let muteTimer = setInterval(muteInternalAdverts, 80);
  57. }
  58.  
  59. (function() {
  60. let nowOpenedAdvert = false;
  61.  
  62. let gete = (param) => document.querySelector(param);
  63.  
  64. let skipper = () => {
  65. let vide = gete('#movie_player video');
  66. if (vide) {
  67. let info = {
  68. duration: vide.duration,
  69. buffered: vide.buffered
  70. };
  71. console.log('ytscript :: skipper movie_player = ', info);
  72. //vide.play();
  73. vide.currentTime += 3600;
  74. }
  75. };
  76. //skipper();
  77.  
  78. let advertCatcher = () => {
  79. let advertTitle = gete('.ytp-ad-player-overlay-layout div[aria-label="Реклама"]');
  80. //nowOpenedAdvert = !!advertTitle;
  81. if (advertTitle) {
  82. console.log('ytscript :: advertTitle = ', advertTitle);
  83. skipper();
  84. }
  85. };
  86.  
  87. setInterval(advertCatcher, 50);
  88. return;
  89.  
  90. let holder = () => {
  91. let btnSkip = document.querySelector('.video-ads button[id^="skip-button"]');
  92. if (btnSkip) {
  93. btnSkip.click();
  94. }
  95. };
  96. setTimeout(holder, 100);
  97. })();
  98.  
  99. console.log('Youtube - Advertisement Hide 💬 1.5');
  100. })();