This commit is contained in:
Araxeus
2021-05-17 00:07:28 +03:00
parent 9c7a70e056
commit e5473cdfe4

View File

@ -31,13 +31,13 @@ function injectVolumeHud(noVid) {
if (noVid) {
const position = "top: 18px; right: 60px; z-index: 999; position: absolute;";
const mainStyle = "font-size: xx-large; padding: 10px; transition: opacity 1s";
$(".center-content.ytmusic-nav-bar").insertAdjacentHTML("beforeend",
`<span id="volumeHud" style="${position + mainStyle}"></span>`)
} else {
const position = `top: 10px; left: 10px; z-index: 999; position: absolute;`;
const mainStyle = "font-size: xxx-large; padding: 10px; transition: opacity 0.6s; webkit-text-stroke: 1px black; font-weight: 600;";
$("#song-video").insertAdjacentHTML('afterend',
`<span id="volumeHud" style="${position + mainStyle}"></span>`)
}
@ -46,20 +46,20 @@ function injectVolumeHud(noVid) {
let hudFadeTimeout;
function showVolumeHud(volume) {
let volumeHud = $("#volumeHud");
if (!volumeHud) return;
let volumeHud = $("#volumeHud");
if (!volumeHud) return;
volumeHud.textContent = volume + '%';
volumeHud.style.opacity = 1;
volumeHud.textContent = volume + '%';
volumeHud.style.opacity = 1;
if (hudFadeTimeout) {
if (hudFadeTimeout) {
clearTimeout(hudFadeTimeout);
}
hudFadeTimeout = setTimeout(() => {
volumeHud.style.opacity = 0;
hudFadeTimeout = null;
}, 2000);
hudFadeTimeout = setTimeout(() => {
volumeHud.style.opacity = 0;
hudFadeTimeout = null;
}, 2000);
}
/** Add onwheel event to video player */
@ -83,12 +83,12 @@ function saveVolume(volume, options) {
//without this function it would rewrite config 20 time when volume change by 20
let writeTimeout;
function writeOptions(options) {
if (writeTimeout) clearTimeout(writeTimeout);
if (writeTimeout) clearTimeout(writeTimeout);
writeTimeout = setTimeout(() => {
writeTimeout = setTimeout(() => {
setOptions("precise-volume", options);
writeTimeout = null;
}, 1500)
writeTimeout = null;
}, 1500)
}
/** Restore saved volume and setup tooltip */
@ -133,9 +133,9 @@ function changeVolume(toIncrease, options) {
const videoStream = $(".video-stream");
// Apply volume change if valid
const steps = (options.steps || 1) / 100;
videoStream.volume = toIncrease ?
videoStream.volume = (toIncrease ?
Math.min(videoStream.volume + steps, 1) :
Math.max(videoStream.volume - steps, 0).toFixed(2);
Math.max(videoStream.volume - steps, 0)).toFixed(2);
// Save the new volume
saveVolume(toPercent(videoStream.volume), options);
@ -152,7 +152,7 @@ function changeVolume(toIncrease, options) {
}
function setupVolumeOverride(options) {
const video = $('video');
const video = $('video');
video.addEventListener("canplay", () => {
if (typeof options.savedVolume === "number") {