Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up ads. #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions auto-close-youtube-ads/auto-close-youtube-ads.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down