Greasy Fork is available in English.

Kick Volume Wheel Control

Use the mouse wheel to adjust the volume. Middle-click to mute or unmute the player. Volume slider always visible.

// ==UserScript==
// @name         Kick Volume Wheel Control
// @namespace    https://github.com/pabli24
// @version      1.0.1
// @description  Use the mouse wheel to adjust the volume. Middle-click to mute or unmute the player. Volume slider always visible.
// @author       Pabli
// @license      MIT
// @match        https://kick.com/*
// @icon         data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+DQo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmVyc2lvbj0iMS4wIiB3aWR0aD0iNTAwIiBoZWlnaHQ9IjUwMCIgdmlld0JveD0iMCAwIDc1IDc1Ij4NCjxwYXRoIGQ9Ik0zOS4zODksMTMuNzY5IEwyMi4yMzUsMjguNjA2IEw2LDI4LjYwNiBMNiw0Ny42OTkgTDIxLjk4OSw0Ny42OTkgTDM5LjM4OSw2Mi43NSBMMzkuMzg5LDEzLjc2OXoiIHN0eWxlPSJzdHJva2U6IzUzZmMxODtzdHJva2Utd2lkdGg6NTtzdHJva2UtbGluZWpvaW46cm91bmQ7ZmlsbDojNTNmYzE4OyIvPg0KPHBhdGggZD0iTTQ4LDI3LjZhMTkuNSwxOS41IDAgMCAxIDAsMjEuNE01NS4xLDIwLjVhMzAsMzAgMCAwIDEgMCwzNS42TTYxLjYsMTRhMzguOCwzOC44IDAgMCAxIDAsNDguNiIgc3R5bGU9ImZpbGw6bm9uZTtzdHJva2U6IzUzZmMxODtzdHJva2Utd2lkdGg6NTtzdHJva2UtbGluZWNhcDpyb3VuZCIvPg0KPC9zdmc+
// @grant        none
// ==/UserScript==

(function() {
	"use strict";

function setCookie(name, value, days) {
	const date = new Date();
	date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
	document.cookie = `${name}=${value}; expires=${date.toUTCString()}; path=/`;
}

function prevent(e) {
	e.preventDefault();
	e.stopPropagation();
	e.stopImmediatePropagation();
}

const observer = new MutationObserver(mutations => {
	const video = document.getElementById("video-player");
	if (!video) return;

	const videoDiv = document.getElementById("injected-embedded-channel-player-video");
	if (videoDiv.hasAttribute("kpvolume")) return;
	videoDiv.setAttribute("kpvolume", "");

	videoDiv.addEventListener("wheel", (event) => {
		prevent(event);

		if (video.muted && videoDiv.getAttribute("kpvolume")) {
			video.muted = false;
			setTimeout(() => {
				video.volume = videoDiv.getAttribute("kpvolume");
				slider();
			}, 50)
		} else if (event.deltaY < 0) {
			video.volume = Math.min(1, video.volume + 0.01); // Increase volume
		} else if (event.deltaY > 0) {
			video.volume = Math.max(0, video.volume - 0.01); // Decrease volume
		}

		setTimeout(slider, 50);
		setTimeout(() => setCookie("volume", video.volume, 365), 3000);
	});
	videoDiv.addEventListener("mousemove", (event) => {
		setTimeout(() => {
			muteBtn();
			slider();
		}, 50)
		setTimeout(() => setCookie("volume", video.volume, 365), 3000);
	});
	videoDiv.addEventListener("mouseenter", (event) => {
		setTimeout(() => setCookie("volume", video.volume, 365), 100);
	});

	function slider() {
		const sliderFill = document.querySelector('#video-player + div span[style*="right:"]'); // style="left: 0%; right: 40%;"
		if (!sliderFill) return;
		const videoVolume = Math.round(video.volume * 100);
		sliderFill.style.right = `${100 - videoVolume}%`;

		const sliderThumb = document.querySelector('#video-player + div span[style*="transform: var(--radix-slider-thumb-transform)"]'); // left: calc(40% + 1.6px);
		const offset = 8 + (videoVolume / 100) * -16;
		sliderThumb.style.left = `calc(${videoVolume}% + ${offset}px)`;

		const sliderValuenow = document.querySelector('#video-player + div span[aria-valuenow]'); // aria-valuenow="40"
		sliderValuenow.setAttribute("aria-valuenow", videoVolume);

		const sliderP = document.querySelector('#video-player + div .group\\/volume .betterhover\\:group-hover\\/volume\\:flex');
		sliderP.setAttribute("playervolume", videoVolume + "%");
	}

	function muteBtn() {
		const muteButton = document.querySelector('#video-player + div .group\\/volume > button');
		if (!muteButton) return;
		muteButton.addEventListener("click", (event) => {
			prevent(event);
			mute();
		});
	}
	function mute() {
		if (video.muted) {
			video.muted = false;
			setTimeout(() => {
				video.volume = videoDiv.getAttribute("kpvolume");
				slider();
			}, 50)
		} else {
			videoDiv.setAttribute("kpvolume", video.volume);
			video.muted = true;
		}
	}
	videoDiv.addEventListener("mousedown", ({ button }) => {
		if (event.button === 1) {
			prevent(event);
			mute();
		}
	});
	document.addEventListener("keydown", (event) => {
		if ((event.key === 'M' || event.key === 'm') && event.target.tagName !== 'INPUT' && event.target.tagName !== 'TEXTAREA' && event.target.isContentEditable !== true) {
			prevent(event);
			mute();
		}
	});

});
observer.observe(document.body, { childList: true, subtree: true });

const styles = `
.group\\/volume .betterhover\\:group-hover\\/volume\\:flex {
	display: flex;
	align-items: center;
}
.group\\/volume .betterhover\\:group-hover\\/volume\\:flex::after {
	content: attr(playervolume);
	font-weight: 600;
	font-size: .875rem;
	line-height: 1.25rem;
	margin-left: .5rem;
	width: 4ch;
}
`
const styleSheet = document.createElement("style");
styleSheet.textContent = styles;
document.head.appendChild(styleSheet);

})();