Youtube “Video Resume” hack
code, webdev, dev, youtube, hack
October 14th 2019 (2 months ago)

The problem

I like listening music from Youtube, however for some time, they did this funny thing, with pausing of video every ~2h or so – music stops playing, you need to go to the browser page with youtube opened and click “Yes” to let it resume – I understand the reasoning behind this, however this is really annoying and it always stops in a worst possible moment.

The solution

Simple script (that propably can be written more “quality”-like way, but I don’t need it to be idiotproof to be useful), to be put in console:
const clock = setInterval(() => {
  [...document.querySelectorAll('yt-formatted-string')].filter(({innerHTML}) => ['Yes', 'No thanks'].includes(innerHTML) ).forEach((el) => {
    el.click();
  });
}, 1500);

The explanation

Since youtube is built the way it is (at least for now), you know, that a button with “Video Resume” popup will have an option called “Yes”(for english browser/user), and this will be a yt-formatted-string element, so, find all of them on given page and click’em – every 1.5 seconds. Since when video is finished and new is loaded, the page does not refresh, this will work until you turn it off yourself(or refresh the page).

This propably could by upgraded to have a check if a popup is visible, but it actually doesnt have to -> since when you click “Yes”, the popup for “Video Resuming” stays in DOM, only the visibility/position flag changes.