Skip to content

Instantly share code, notes, and snippets.

@rmnmjw
Created November 23, 2023 18:41
Show Gist options
  • Save rmnmjw/b41c312a0156a13cb385ef5ba7e6cb6e to your computer and use it in GitHub Desktop.
Save rmnmjw/b41c312a0156a13cb385ef5ba7e6cb6e to your computer and use it in GitHub Desktop.
change media playback rate with + and - on any website
// ==UserScript==
// @name media playbackRate + / -
// @namespace Violentmonkey Scripts
// @match *://*/*
// @grant none
// @version 1.0
// @author -
// @description 17.3.2023, 18:04:04
// ==/UserScript==
{
const d = document.createElement('div');
d.style.zIndex = 999999;
d.style.border = '1px solid black';
d.style.background = 'white';
d.style.color = 'black';
d.style.fontSize = '2em';
d.style.position = 'fixed';
d.style.top = '0';
d.style.right = '0';
d.style.display = 'none';
document.body.appendChild(d);
let to = -1;
const show = (v) => {
clearTimeout(to);
d.innerHTML = v.toFixed(1) + 'x';
d.style.display = 'block';
to = setTimeout(() => {
d.style.display = 'none';
}, 300);
}
let down_control = false;
document.addEventListener('keyup', (e) => {
if (e.key === 'Control') {
down_control = false;
}
});
document.addEventListener('keydown', (e) => {
if (e.key === 'Control') {
down_control = true;
return;
}
if (down_control) {
return;
}
if (document.activeElement.tagName.toLowerCase() === 'textarea') {
return;
}
if (document.activeElement.tagName.toLowerCase() === 'input') {
return;
}
if (e.key !== '+' && e.key !== '-') {
return;
}
const change = e.key === '+' ? 0.1 : -0.1;
[...document.querySelectorAll('video'), ...document.querySelectorAll('audio')]
.forEach((el) => {
el.playbackRate += change;
show(el.playbackRate);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment