YouTube Volume and Time Mouse Controlled

Volume/Time mouse control for Youtube

اعتبارا من 20-12-2024. شاهد أحدث إصدار.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         YouTube Volume and Time Mouse Controlled
// @namespace    PoKeRGT
// @version      1.03
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @description  Volume/Time mouse control for Youtube
// @author       PoKeRGT
// @match        https://www.youtube.com/watch*
// @grant        none
// @homepageURL  https://github.com/PoKeRGT/userscripts
// @license      MIT
// ==/UserScript==

var videoElement = document.getElementById('movie_player');

function volumeControl(event) {
  if (event.deltaY > 0) { // mouse wheel up
    videoElement.setVolume(videoElement.getVolume() - 5);
  } else { // mouse wheel down
    videoElement.setVolume(videoElement.getVolume() + 5);
  }
  console.log(videoElement.getVolume());
}

function timeControl(event) {
  if (event.deltaY > 0) { // mouse wheel up
    videoElement.seekToStreamTime(videoElement.getCurrentTime() - 5);
  } else { // mouse wheel down
    videoElement.seekToStreamTime(videoElement.getCurrentTime() + 5);
  }
  console.log(videoElement.getCurrentTime());
}

document.addEventListener('wheel', function (event) {
  var rect = videoElement.getBoundingClientRect();
  if (event.clientX > rect.left && event.clientX < rect.right &&
    event.clientY > rect.top && event.clientY < rect.bottom) {
    cancelScroll(event);
    if (event.clientX < window.innerWidth / 2) { // left half of the screen
      volumeControl(event);
    }
    else { // right half of the screen
      timeControl(event);
    }
  }
}, { passive: false });

function cancelScroll(event) {
  event.preventDefault();
}