Skip to content

Commit

Permalink
fix: volume loudness increase on track change
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrani committed Oct 18, 2023
1 parent 9a9fd66 commit 1c4f410
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/observers/song-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,17 @@ export default class SongTracker {
})
}

#mute() { this._video.volume = 0 }
#unMute() { this._video.volume = this.#volumePercent }

get #volumePercent() {
const volumeBarElement = document.querySelector('[data-testid="volume-bar"] > div [data-testid="progress-bar"]')
if (!volumeBarElement) return 0.65

const progressPercent = volumeBarElement.style?.cssText
if (!progressPercent) return 0.65
get #muteButton() {
return document.querySelector('[data-testid="volume-bar-toggle-mute-button"]')
}

const volume = parseFloat(progressPercent.split(/: /).at(1)) / 100
return volume
get #isMute() {
return this.#muteButton?.getAttribute('aria-label') == 'Unmute'
}

#mute() { if (!this.#isMute) this.#muteButton?.click() }
#unMute() { if (this.#isMute) this.#muteButton?.click() }

#setupListeners() {
this._video.element.addEventListener('timeupdate', this.#handleTimeUpdate)
}
Expand Down

0 comments on commit 1c4f410

Please sign in to comment.