Greasy Fork is available in English.
Automatically clicks 'Ok' when the 'Video paused. Continue watching?' dialog pops up and pauses your videos.
< Feedback op Youtube 'Video paused. Continue watching?' Auto confirmer
Updated code:
(function main() {
'use strict';
console.log('Unpause autoconfirmer started.');
setInterval(function() {
for (let node of document.querySelectorAll('.ytd-popup-container[role="dialog"]:not([style*="display: none"])'))
if (node.style.display !== 'none' && node.textContent.contains('Video paused.')) {
let btn = node.querySelector('#confirm-button');
if (btn) btn.click();
}
}, 500);
})();
Seems like main issue with your code is not even in repeated arrays, but not checking is dialog actually visible. YouTube just hides it after confirmation and in the result your script keeps pressing confirm button every 10ms which creates flood of messages "Thank you for confirmation." in the bottom-left corner.
node.textContent.contains threw an error in my environment.
(function main() {
'use strict';
console.log('Unpause autoconfirmer started.');
setInterval(function() {
for (let node of document.querySelectorAll('.ytd-popup-container[role="dialog"]:not([style*="display: none"])'))
if (node.style.display !== 'none' && node.textContent.includes('Video paused.')) {
let btn = node.querySelector('#confirm-button');
if (btn) btn.click();
}
}, 500);
})();
@Vannius Correct. Made mistake. Should be 'includes'. Thank you for the correction.
Stumbled upon this myself today when music stopped and message popped up again. Probably the most stupid part is that I actually checked which function I can use there from console and still wrote the wrong one in the script. I think I'll somehow swap these two around even if my life will depend on it. >_<
I used a somewhat more convoluted solution:
(() => {
'use strict';
console.log('Unpause autoconfirmer started.');
let interval = setInterval(() => {
document.querySelectorAll('#confirm-button').forEach((btn) => {
if (btn && btn.parentComponent.textContent.includes('Video paused.')) {
clearInterval(interval);
setInterval(() => {
if (btn.parentComponent.style.display !== 'none') btn.click();
}, 100);
}
});
}, 100);
})();
but then I discovered a much simpler method:
(() => {
'use strict';
setInterval(() => {
window._lact = Date.now();
}, 300000);
})();
@Azlehria said: I used a somewhat more convoluted solution:
(() => { 'use strict'; console.log('Unpause autoconfirmer started.'); let interval = setInterval(() => { document.querySelectorAll('#confirm-button').forEach((btn) => { if (btn && btn.parentComponent.textContent.includes('Video paused.')) { clearInterval(interval); setInterval(() => { if (btn.parentComponent.style.display !== 'none') btn.click(); }, 100); } }); }, 100); })();
but then I discovered a much simpler method:
(() => { 'use strict'; setInterval(() => { window._lact = Date.now(); }, 300000); })();
The latter is the best solution because of the lower cpu consumption and it doesn't fail if your youtube isn't in english which is the cause of your scripts not running in my system.
And if you just try to block www.youtube.com/manifest.json
It's work like a charm on uBlock Origin ||www.youtube.com/manifest.json$other,domain=www.youtube.com,important
content: {"starturl":"\/","gcmuservisibleonly":true,"display":"standalone","gcmsenderid":"402845223712","name":"YouTube"}
Good intention, but horrible execution
Today I woke up after browser with this masterpiece were running in background for hours and found out that YouTube tab ate completely ungodly chunk of RAM and entire PC operating from SWAP. I'm not sure it's due to this script, but it never happened to me before it, so it must be. When I were looking at it befor installing it, it felt like something is off, but I decided to leave it as-is since it wasn't malicious off. Apparently, that were a bad idea. :neutral:
Ok, the most important part: who told you it's a good idea to call any function which returns live array of nodes every 10ms? Why would you even need to run it this fast? 100~500 ms is way WAY more than enought to catch this pop-up before it stayed up for too long.
Second: Why keep running that same function again and again from within a loop? Well, beside the fact it doesn't guarantee you returning stuff in the same order even though in practice it usually do. Anyway, it's extremely inefficient to do it again and again. Just save result into a variable and re-use it from there. Something like this:
Also, I changed it to this on my side:
But it may not work in very old versions of some browsers due to presence of arrow function, let operator and for...of loop.