Advertisement Hide - Youtube

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

  1. // ==UserScript==
  2. // @name Advertisement Hide - Youtube
  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. // @version 1.4
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function(unsafeWindow) {
  14. let console = unsafeWindow.console;
  15. let $ = unsafeWindow.jQuery;
  16. let $$ = unsafeWindow.__krokodil;
  17.  
  18. $$.renderStyle(
  19. '',
  20. ''
  21. );
  22.  
  23. unsafeWindow.greasyMovieVolumeOn = false;
  24.  
  25. /**
  26. * Выключает звук на внутренней рекламе
  27. */
  28. let muteInternalAdverts = function() {
  29. let button;
  30.  
  31. if (button = $$.get(`.ytp-ad-overlay-slot .ytp-ad-overlay-close-button`)) {
  32. $$.fireEvent(button, 'click');
  33. }
  34. if (button = $$.get(`.video-ads .ytp-ad-skip-button-container`)) {
  35. $$.fireEvent(button, 'click');
  36. }
  37. // Сравнивать по строковому значению title - ужасно.
  38. // Но другого способа нет, потому что не меняются другие атрибуты
  39. if (button = $$.get(`.ytp-ad-preview-container`)) {
  40. if (button = $$.get(`#movie_player .ytp-mute-button[title^="Отключение звука"]`)) {
  41. $$.fireEvent(button, 'click');
  42. }
  43. unsafeWindow.greasyMovieVolumeOn = false;
  44. } else {
  45. if (!unsafeWindow.greasyMovieVolumeOn) {
  46. if (button = $$.get(`#movie_player .ytp-mute-button[title^="Включить звук"]`)) {
  47. $$.fireEvent(button, 'click');
  48. }
  49. unsafeWindow.greasyMovieVolumeOn = true;
  50. }
  51. }
  52. };
  53.  
  54. let muteTimer = setInterval(muteInternalAdverts, 80);
  55. console.log('Advertisement Hide - Youtube');
  56. })(typeof unsafeWindow === 'object' ? unsafeWindow : window);