update inline doc

This commit is contained in:
Araxeus
2021-04-16 22:37:34 +03:00
parent 40968d573c
commit c0ec1bc5cf

View File

@ -4,14 +4,14 @@ module.exports = () => {
firstTooltip(); firstTooltip();
} }
function firstTooltip () { function firstTooltip() {
const videoStream = document.querySelector(".video-stream"); const videoStream = document.querySelector(".video-stream");
if (videoStream) { if (videoStream) {
setTooltip(Math.round(parseFloat(videoStream.volume) * 100)); setTooltip(Math.round(parseFloat(videoStream.volume) * 100));
} else { } else {
setTimeout(firstTooltip, 500); // try again in 500 milliseconds setTimeout(firstTooltip, 500); // try again in 500 milliseconds
} }
} }
function setupPlaybarOnwheel() { function setupPlaybarOnwheel() {
//add onwheel event to play bar //add onwheel event to play bar
@ -22,8 +22,8 @@ function setupPlaybarOnwheel() {
} }
} }
let newVolume; //the last volume set by changeVolume() is stored here
let newVolume; //used to determine if volume-slider was manually moved
function changeVolume(increase) { function changeVolume(increase) {
//need to change both the slider and the actual volume //need to change both the slider and the actual volume
@ -41,20 +41,20 @@ function changeVolume(increase) {
setTooltip(newVolume) setTooltip(newVolume)
} }
//observer sets the tooltip when volume is manually changed //update the volume tooltip when volume-slider is manually changed
function setupObserver() { function setupObserver() {
const observer = new MutationObserver((mutations) => { const observer = new MutationObserver((mutations) => {
for (const mutation of mutations) { for (const mutation of mutations) {
//this checks that the new volume was manually set (without the new changeVolume() function) //this checks that volume-slider was manually set
if (mutation.oldValue !== mutation.target.value if (mutation.oldValue !== mutation.target.value
&& (!newVolume || Math.abs(newVolume - mutation.target.value) > 4)) { && (!newVolume || Math.abs(newVolume - mutation.target.value) > 4)) {
//if diff>4 -> it was manually set, so update tooltip accordingly //diff>4 means it was manually set, so update tooltip accordingly
setTooltip(mutation.target.value); setTooltip(mutation.target.value);
} }
} }
}); });
//observing only changes in value of volume-slider //observing only changes in 'value' of volume-slider
observer.observe(document.querySelector("#volume-slider"), { observer.observe(document.querySelector("#volume-slider"), {
attributeFilter: ["value"], attributeFilter: ["value"],
attributeOldValue: true, attributeOldValue: true,