AcFun-ScrollVolume

AcFun滚轮调音量, change AcFun's volume by scroll.

2022-10-18 기준 버전입니다. 최신 버전을 확인하세요.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AcFun-ScrollVolume
// @namespace    https://github.com/TitanRGB
// @version      2.2
// @description  AcFun滚轮调音量, change AcFun's volume by scroll.
// @author       https://github.com/TitanRGB
// @include      *://www.acfun.cn/v/ac*
// @include      *://www.acfun.cn/bangumi/aa*
// @include      *://*.acfun.cn/v/ac*
// @include      *://*.acfun.cn/bangumi/aa*
// @include      *://acfun.cn/v/ac*
// @include      *://acfun.cn/bangumi/aa*
// @exclude      *://*.eggvod.cn/*
// @connect      www.acfun.cn
// @connect      *.acfun.cn
// @connect      acfun.cn
// @license      Mozilla Public License 2.0
// @grant        GM_xmlhttpRequest
// @grant        GM_log
// @grant        unsafeWindow
// @homepageURL       https://github.com/SynRGB/AcFunScrollVolume
// @contributionURL   https://github.com/SynRGB/AcFunScrollVolume
// ==/UserScript==
// 防止和Chrome插件版本冲突

// 一次滚轮滚动会触发两次按键, 用此变量做修正
let count_amend_singleScrollTriggeredTwoTimes = 0;
// 当滚动滚轮, 模拟按下↑↓
let scroll = function (e) {
    e = e || window.event;
    // 仅在全屏时生效
    if (document.querySelector('[data-bind-attr="screen"]') !== null) {
        // 一次滚轮滚动会触发两次按键, 用此变量做修正
        if (count_amend_singleScrollTriggeredTwoTimes === 0) {
            // 一次滚轮滚动会触发两次按键, 用此变量做修正
            count_amend_singleScrollTriggeredTwoTimes = 1;
            if (e.wheelDelta) {//////////////////////////////// Chrome
                // 向上滚动
                if (e.wheelDelta > 0) {
                    unsafeWindow.player.volume++;
                }
                // 向下滚动
                if (e.wheelDelta < 0) {
                    // pressKey(40);
                    unsafeWindow.player.volume--;
                }
            } else if (e.detail) {///////////////////////////// Firefox
                // 向上滚动
                if (e.detail > 0) {
                    unsafeWindow.player.volume++;
                }
                // 向下滚动
                if (e.detail < 0) {
                    unsafeWindow.player.volume--;
                }
            }
            // 音量显示
            try {
                document.querySelector('#volumeText').remove();
            } catch (e) {}
            let screen = document.querySelector('[data-bind-attr="screen"]');
            let volume = unsafeWindow.player.volume;
            let volumeText = document.createElement('div');
            volumeText.setAttribute('id', 'volumeText');
            volumeText.setAttribute('style', `
                    position: absolute;
                    top: 50%;
                    left: 50%;
                    transform: translate(-50%, -50%);
                    font-size: 50px;
                    color: #fff;
                    text-shadow: 0 0 10px #000;
                `);
            volumeText.innerHTML = volume.toString().substring(0, 2).replace('.', '') + "%";
            screen.appendChild(volumeText);
            setTimeout(() => {
                screen.removeChild(volumeText);
            }, 500);
        } else {
            // 一次滚轮滚动会触发两次按键, 用此变量做修正
            count_amend_singleScrollTriggeredTwoTimes = 0;
        }
    }
};
// 给页面绑定滑轮滚动事件 - Firefox
if (document.addEventListener) {
    document.addEventListener('DOMMouseScroll', scroll, false);
}
// 给页面绑定滑轮滚动事件 - Chrome, IE
window.onmousewheel = document.onmousewheel = scroll;
console.log("JS script AcFUNScrollVolume (AcFUN滚轮调音量) loaded. See more details at https://github.com/SynRGB/AcFun-ScrollVolume");