Remove Adblock Notifications

Kills YouTube's new Anti-Adblock Popups

  1. // ==UserScript==
  2. // @name Remove Adblock Notifications
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Kills YouTube's new Anti-Adblock Popups
  6. // @author PoppingXanax
  7. // @license MIT
  8. // @match https://www.youtube.com/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.  
  15. // Configuration
  16. const DEBUG_MODE = true;
  17. const DOMAINS_TO_CHECK = ['*.youtube-nocookie.com/*'];
  18. const JSON_PATHS_TO_REMOVE = [
  19. 'playerResponse.adPlacements',
  20. 'playerResponse.playerAds',
  21. 'adPlacements',
  22. 'playerAds',
  23. 'playerConfig',
  24. 'auxiliaryUi.messageRenderers.enforcementMessageViewModel'
  25. ];
  26.  
  27. let unpauseCounter = 0;
  28.  
  29. // Disable YouTube's adblock detection flag
  30. window.__ytplayer_adblockDetected = false;
  31.  
  32. // Helper Functions
  33. function debugLog(message) {
  34. if (DEBUG_MODE) console.log(`Remove Adblock Notifications: ${message}`);
  35. }
  36.  
  37. function triggerUnpause() {
  38. const keyEvent = new KeyboardEvent("keydown", {
  39. key: "k",
  40. code: "KeyK",
  41. keyCode: 75,
  42. which: 75,
  43. bubbles: true,
  44. cancelable: true,
  45. view: window
  46. });
  47. document.dispatchEvent(keyEvent);
  48. unpauseCounter = 0;
  49. debugLog("Unpaused video using 'k' key");
  50. }
  51. function processAdblockPopup() {
  52. const adblockPopup = document.querySelector("body > ytd-app > ytd-popup-container > tp-yt-paper-dialog");
  53. const videoMain = document.querySelector("#movie_player > video.html5-main-video");
  54. const videoAlt = document.querySelector("#movie_player > .html5-video-container > video");
  55. if (adblockPopup) {
  56. debugLog("Adblock popup detected, removing...");
  57. adblockPopup.remove();
  58. unpauseCounter = 2;
  59. console.log("Removed Adblock popup.");
  60. } else {
  61. console.log("No Adblock popup detected.");
  62. }
  63. if (unpauseCounter > 0) {
  64. if (videoMain && videoMain.paused) triggerUnpause();
  65. else if (videoAlt && videoAlt.paused) triggerUnpause();
  66. else unpauseCounter--;
  67. }
  68. }
  69.  
  70. function cleanJsonPaths(domains, paths) {
  71. if (!domains.includes(window.location.hostname)) return;
  72.  
  73. paths.forEach(path => {
  74. let targetObject = window;
  75. path.split('.').forEach(part => {
  76. if (targetObject.hasOwnProperty(part)) {
  77. targetObject = targetObject[part];
  78. } else {
  79. return;
  80. }
  81. });
  82. targetObject = undefined;
  83. });
  84. }
  85.  
  86. // Initialization
  87. debugLog("Script initialized");
  88.  
  89. setInterval(processAdblockPopup, 1000);
  90.  
  91. cleanJsonPaths(DOMAINS_TO_CHECK, JSON_PATHS_TO_REMOVE);
  92.  
  93. const domObserver = new MutationObserver(() => {
  94. cleanJsonPaths(DOMAINS_TO_CHECK, JSON_PATHS_TO_REMOVE);
  95. });
  96.  
  97. domObserver.observe(document.body, { childList: true, subtree: true });
  98.  
  99. })();