Kick.com Mouse audio controls

Kick.com Mouse audio controls (middle click: mute | scroll: adjust volume)

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Kick.com Mouse audio controls
// @namespace    Sky3
// @version      1.0
// @description  Kick.com Mouse audio controls (middle click: mute | scroll: adjust volume)
// @author       Sky3
// @match        https://kick.com/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let prevScrollDate = 0;

    function addHandlers() {
        const videoElement = document.getElementById('video-player');
        videoElement.addEventListener('mousedown', (event) => {
          if (event.button == 1) {
              videoElement.muted = !videoElement.muted;
              event.preventDefault();
              event.stopPropagation();
          }
        });

        videoElement.addEventListener('wheel', (event) => {
            if (videoElement.muted) return;

            event.preventDefault();
            event.stopPropagation();

            const shouldIncrease = event.deltaY < 0;
            const volume = videoElement.volume;

            if ((volume == 0 && !shouldIncrease) || (volume == 1 && shouldIncrease)) return;

            const now = Date.now(), since = now - prevScrollDate
            const step = (shouldIncrease ? 1 : -1) * (since < 50 ? 4 : 1) * .01

            videoElement.volume += step;

            prevScrollDate = now
        });
    }

    setTimeout(() => {
        addHandlers();
    }, 2000);
})();