Skip to content

Instantly share code, notes, and snippets.

@fine-simple
Created July 1, 2025 19:51
Show Gist options
  • Select an option

  • Save fine-simple/1590f54444510f4f115530ec5c091c2c to your computer and use it in GitHub Desktop.

Select an option

Save fine-simple/1590f54444510f4f115530ec5c091c2c to your computer and use it in GitHub Desktop.
Youtube Music User Script for controlling volume and seeking using keyboard arrow keys
// ==UserScript==
// @name Youtube Music (YTM) Keyboard controls
// @namespace http://tampermonkey.net/
// @version 2025-07-01
// @description Seek and control volume using keyboard arrows in YouTube Music.
// @author You
// @match https://music.youtube.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// ==/UserScript==
const keyEventRight = new KeyboardEvent("keydown", { key: "ArrowRight" });
const keyEventLeft = new KeyboardEvent("keydown", { key: "ArrowLeft" });
(function () {
"use strict";
window.addEventListener("keydown", e => {
const progressBar = document.querySelector("#progress-bar");
const volumeSlider = document.querySelector("#volume-slider");
if (document.activeElement === progressBar || document.activeElement === volumeSlider) {
return; // Ignore key events if the progress bar or volume slider is focused
}
switch (e.key) {
case "ArrowRight":
progressBar
.dispatchEvent(keyEventRight);
break;
case "ArrowLeft":
progressBar
.dispatchEvent(keyEventLeft);
break;
case "ArrowUp":
volumeSlider
.dispatchEvent(keyEventRight);
break;
case "ArrowDown":
volumeSlider
.dispatchEvent(keyEventLeft);
break;
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment