巴哈姆特动画疯滚轮控制音量大小

巴哈姆特动画疯播放器中透过滚轮控制音量大小功能

  1. // ==UserScript==
  2. // @name Video Volume Control with Mouse Wheel in ani.gamer.com.tw
  3. // @name:zh-TW 巴哈姆特動畫瘋滾輪控制音量大小
  4. // @name:zh-CN 巴哈姆特动画疯滚轮控制音量大小
  5. // @namespace JTRKON
  6. // @author JTRKON
  7. // @version 1.2
  8. // @description Control the volume of video elements using mouse wheel
  9. // @description:zh-TW 巴哈姆特動畫瘋播放器中透過滾輪控制音量大小功能
  10. // @description:zh-CN 巴哈姆特动画疯播放器中透过滚轮控制音量大小功能
  11. // @match http://ani.gamer.com.tw/animeVideo.php*
  12. // @match https://ani.gamer.com.tw/animeVideo.php*
  13. // @grant none
  14. // @license MIT
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. "use strict";
  19.  
  20. // 創建音量顯示元素
  21. var volumeDisplay = document.createElement("div");
  22. volumeDisplay.classList.add("volume-display");
  23. volumeDisplay.style.display = "none";
  24. volumeDisplay.style.position = "fixed";
  25. volumeDisplay.style.top = "50%";
  26. volumeDisplay.style.left = "50%";
  27. volumeDisplay.style.transform = "translate(-50%, -50%)";
  28. volumeDisplay.style.background = "rgba(0, 0, 0, 0.5)";
  29. volumeDisplay.style.color = "#fff";
  30. volumeDisplay.style.padding = "5px 10px";
  31. volumeDisplay.style.fontFamily = "Arial, sans-serif";
  32. volumeDisplay.style.fontSize = "16px";
  33. volumeDisplay.style.zIndex = "99999";
  34.  
  35. var volumeTimeout;
  36.  
  37. // 監聽滾輪事件,根據滾輪方向調整音量
  38. document.addEventListener("wheel", function (event) {
  39. /*if (event.cancelable) {
  40. event.preventDefault();
  41. }*/
  42. var video = document.querySelector("video");
  43.  
  44. if (video) {
  45. if (
  46. document.body.classList.contains("fullscreen") ||
  47. document.fullscreenElement === video.parentElement ||
  48. document.getElementById("Web_fullscreen_style") !== null
  49. ) {
  50. var volume = video.volume;
  51. if (!video.parentElement.querySelector(".volume-display")) {
  52. video.parentElement.appendChild(volumeDisplay);
  53. }
  54. if (event.deltaY < 0) {
  55. volume += 0.02;
  56. } else {
  57. volume -= 0.02;
  58. }
  59.  
  60. // 限制音量在有效範圍內
  61. volume = Math.max(0, Math.min(1, volume));
  62.  
  63. video.volume = volume;
  64.  
  65. // 更新音量顯示
  66. volumeDisplay.textContent =
  67. "Volume: " + (video.volume * 100).toFixed(0) + "%";
  68. volumeDisplay.style.display = "block";
  69.  
  70. // 清除之前的計時器
  71. clearTimeout(volumeTimeout);
  72.  
  73. // 設置計時器,2秒後隱藏音量顯示
  74. volumeTimeout = setTimeout(function () {
  75. volumeDisplay.style.display = "none";
  76. }, 2000);
  77. }
  78. }
  79. });
  80. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址