AcFun滚轮调音量

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

目前為 2022-10-18 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         AcFun滚轮调音量
// @namespace    https://github.com/TitanRGB
// @version      2.0
// @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;
// 待界面加载完成
window.onload = () => {
    // 当滚动滚轮, 模拟按下↑↓
    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");