From 7de0fa0201e16da021ffa4f88e96b63a7ec64a1f Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 8 Apr 2022 21:31:44 +1200 Subject: [PATCH] Speed up ads. When we can't skip ads then speed them up. What it should do but currently doesn't (and if you are motivated to add this stuff then please do so, it's working fine for me as-is so I likely won't bother): * have a related config item or two * don't force x1 speed when coming out of an ad but remember what it was before speeding up --- .../auto-close-youtube-ads.user.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/auto-close-youtube-ads/auto-close-youtube-ads.user.js b/auto-close-youtube-ads/auto-close-youtube-ads.user.js index ac438af0..b8cc8943 100644 --- a/auto-close-youtube-ads/auto-close-youtube-ads.user.js +++ b/auto-close-youtube-ads/auto-close-youtube-ads.user.js @@ -226,6 +226,26 @@ function getAdLength(ad) { return time ? parseTime(time.textContent) : 0 } +function speedUp() { + const vid = document.getElementsByTagName("video") + if (vid) { + util.log('Speeding up video') + vid[0].playbackRate = 16 + } else { + util.log('Couldn\'t find video to speed up') + } +} + +function slowDown() { + const vid = document.getElementsByTagName("video") + if (vid) { + util.log('Setting video speed to 1') + vid[0].playbackRate = 1 + } else { + util.log('Couldn\'t find video to change speed') + } +} + function waitForAds() { DONT_SKIP = false TICKS.push( @@ -281,14 +301,17 @@ function waitForAds() { const muteIndicator = getMuteIndicator() if (!muteIndicator) return util.log('unable to determine mute state, skipping mute') muteButton.click() + speedUp() util.log('Video ad detected, muting audio') // wait for the ad to disappear before unmuting util.keepTrying(250, () => { if (!util.q(CSS.adArea)) { if (isMuted(muteIndicator)) { muteButton.click() + slowDown() util.log('Video ad ended, unmuting audio') } else { + slowDown() util.log('Video ad ended, audio already unmuted') } return true