Global Media Playback Speed Control

Control playback speed for any media on a webpage using keyboard shortcuts.

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 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.

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

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

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

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

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

// ==UserScript==
// @name         Global Media Playback Speed Control
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Control playback speed for any media on a webpage using keyboard shortcuts.
// @author       Your Name
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Adjust speed increment value
    const speedStep = 0.1;

    // Listen for keydown events
    document.addEventListener('keydown', function(event) {
        if (event.target.tagName.toLowerCase() !== 'input' && event.target.tagName.toLowerCase() !== 'textarea') {
            let mediaElements = document.querySelectorAll('video, audio');

            if (event.key === '[') {
                mediaElements.forEach(media => {
                    media.playbackRate = Math.max(0.1, media.playbackRate - speedStep);
                    console.log(`Playback speed decreased to: ${media.playbackRate}`);
                });
            } else if (event.key === ']') {
                mediaElements.forEach(media => {
                    media.playbackRate += speedStep;
                    console.log(`Playback speed increased to: ${media.playbackRate}`);
                });
            }
        }
    });

})();