Bookmarklet Remove YouTube adblocking popups

Table of Contents

Bookmarklet Remove YouTube adblocking popups

After a while, Youtube displays a popup asking users to turn off the ad blocker.
Today I encountered a situation where Youtube went one step further and did not allow this popup to be turned off at all. So I had the idea to quickly create a Bookmarklet to turn off this popup

image

Test

function getElementByXpath(path) {
  return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}

console.log( getElementByXpath("/html/body/ytd-app/ytd-popup-container") );

var t1=getElementByXpath("/html/body/ytd-app/ytd-popup-container");

t1.remove()

Update Auto Play after remove popup

// create a new keyboard event and set the key to "Key K"
// Key K is Youtube shortcut to play/pause video
const event = new KeyboardEvent('keydown', {
  key: 'K',
  code: 'KeyK',
  which: 75,
  keyCode: 75,
});

// dispatch the event on some DOM element
document.getElementById('movie_player').dispatchEvent(event);

Make Bookmarklet

javascript:(function(){
    function getElementByXpath(path) {
  return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
var t1=getElementByXpath("/html/body/ytd-app/ytd-popup-container");
t1.remove();
const event = new KeyboardEvent('keydown', {
  key: 'K',
  code: 'KeyK',
  which: 75,
  keyCode: 75,
});
document.getElementById('movie_player').dispatchEvent(event);
})();

How to add Bookmarklet

  1. Bookmark any link
  2. Edit the Bookmark, change URL to Bookmarklet script
  3. Enjoy the result

When Youtube show popup, you only need to click on the bookmark to remove it!

image

Leave a Reply

Your email address will not be published. Required fields are marked *