Skip to content

Instantly share code, notes, and snippets.

@cutiepoka
Created October 6, 2023 18:18
Show Gist options
  • Save cutiepoka/a9347c68bfcf29060926a8af46bb1701 to your computer and use it in GitHub Desktop.
Save cutiepoka/a9347c68bfcf29060926a8af46bb1701 to your computer and use it in GitHub Desktop.
Youtube allow ads popup blocker
// ==UserScript==
// @name youtube popup killer
// @namespace http://tampermonkey.net/
// @version 0.3
// @description try to take over the world!
// @author Selbereth
// @match https://*.youtube.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// ==/UserScript==
(function () {
window.debug = true;
if (debug) console.log("started");
setInterval(() => {
if (!!popupFind()) {
if (debug) console.log("remove popup");
const popup = popupFind()
console.log(popup)
popup.parentNode.removeChild(popup)
if (debug) console.log("resume video");
//pauseFind().click()
if (debug) console.log("done ");
}
}, 1000);
})();
function popupFind() {
return document.querySelector("body > ytd-app > ytd-popup-container");
}
function pauseFind(){
return document.querySelector("#movie_player > div.ytp-chrome-bottom > div.ytp-chrome-controls > div.ytp-left-controls > button");
}
@Eraze1102
Copy link

@ALL

i found an easy script that works, follow the instructions in this Video !!!
https://www.youtube.com/watch?v=XMRr-1sm_XQ

REALLY SUPER EASY DISABLE ALL OTHER BLOCKERS THEREFORE

@vauxious
Copy link

can you exclude the share popup? because everytime i want to share the video, the popup didn't show

@ka3ak169
Copy link

@vauxious
Friend, I made it so the "share" pop-up wouldn't disappear, but I myself used the solution that was recommended by @Eraze1102
I found it to be simpler

// ==UserScript==
// @name         youtube popup killer
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  try to take over the world!
// @author       Selbereth
// @match        https://*.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// ==/UserScript==

(function () {
  const debug = true;
  if (debug) console.log("started");
  setInterval(() => {
    try {
      if (!!popupFind()) {
        console.log('close addPopup');
        if (debug) console.log("remove popup");
        const popup = popupFind();
        console.log(popup);
        popup.parentNode.removeChild(popup);

        if (debug) console.log("resume video");
        pauseFind().click();
        if (debug) console.log("done ");
      }
    } catch (error) {
      console.error("Error in the interval:", error);
    }
  }, 1000);
})();

function popupFind() {
  const targetPopup = document.querySelector("body > ytd-app > ytd-popup-container > tp-yt-paper-dialog");
  const ignoredPopup1 = document.querySelector("body > ytd-app > ytd-popup-container > tp-yt-iron-dropdown");
  const ignoredPopup2 = document.querySelector("body > ytd-app > ytd-popup-container > tp-yt-paper-dialog");  //sharePopup

  if (ignoredPopup1 || ignoredPopup2) {
      console.log('open ignoredPopup');
      return null;
  }
  return targetPopup;
}

function pauseFind(){
  return document.querySelector("#movie_player > div.ytp-chrome-bottom > div.ytp-chrome-controls > div.ytp-left-controls > button");
}

@Eraze1102
Copy link

the solution in the Video still works, i dont know what yall mean by pop up ...

@ld79
Copy link

ld79 commented Oct 25, 2023

the solution in the Video still works, i dont know what yall mean by pop up ...

there is no vid my man, so share the secret knowledge if there is one

@ld79
Copy link

ld79 commented Oct 25, 2023

@H3mul
Copy link

H3mul commented Oct 26, 2023

Made slight adjustments to the OP submission that reacts to DOM changes directly instead of polling for popups every second (similar to @PeterFuciik's submission, uses the MutationObserver), please find here:

https://gist.github.com/H3mul/54145fbfafe89a03c2ce24fdcb66a868

@mjdaved
Copy link

mjdaved commented Nov 2, 2023

Hi, I have realized the scripts work when I use Tampermonkey in Google Chrome, but when I use Tampermonkey on Opera, it does not work as I have been an opera user for a long time. Can someone help me?

@mjdaved
Copy link

mjdaved commented Nov 2, 2023

Hi, I have realized the scripts work when I use Tampermonkey in Google Chrome, but when I use Tampermonkey on Opera, it does not work as I have been an opera user for a long time. Can someone help me?

Ok, I fixed the problem. I disabled adblock by opera and ADblock Plus and used uBlockOrigin and Tampermonkey instead. I still get side ads, but not in the video like before. If I use Opera adblock, YouTube doesn't just block you by popup; they completely block the video and make it impossible to watch.

@7modi-hue
Copy link

Can you help me with this link except ads

@7modi-hue
Copy link

@Pein1911
Copy link

Pein1911 commented Nov 8, 2023

Made slight adjustments to the OP submission that reacts to DOM changes directly instead of polling for popups every second (similar to @PeterFuciik's submission, uses the MutationObserver), please find here:

https://gist.github.com/H3mul/54145fbfafe89a03c2ce24fdcb66a868

It seems video pause everytime youtube show the popup and script run, can you fix it ?

@SpiritOfSuffering
Copy link

SpiritOfSuffering commented Nov 10, 2023

Все предложенные выше варианты больше не работают. Теперь YouTube блокирует видео проигрыватель после 3-ёх зафиксированных случаев, с использованием любого плагина напоминающего или являющемся блокировщиком рекламы. Если вы читаете это, знайте YouTube ничего не блокирует, это иллюзия. На самом деле, блокировка происходит со стороны браузера который вы используете.

Если вы хотите избежать блокировок, скачайте и используйте браузер - Vivaldi. Он основан на браузере Opera до 12 версии.

Используйте браузер - Firefox. Перед использованием, внимательно настройте вкладку настроек "Приватность и Защита". Вы всё ещё можете продолжать использовать uBlock Origin. Вот уже несколько недель я тестирую данный браузер и не испытаваю с ним проблем в отношении блокировок YouTube.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment