Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
Javascript shortcut to change playback speed not working properly

I have a super simple video playback speed extension. It should increase playback speed by 0.25 when Shift + MouseWheelUp is done and decrease by 0.25 when Shift + MouseWheelDown is done.

When I test it (on YouTube or any other video site with a HTML video tag) I get the following problems:

  • The playback speed doesn't increment by 0.25 everytime I do the events. Instead, the speed increases/decreases by a random amount way above 0.25.
  • Specifically on Odysee.com, I get the "Cannot read properties of null (reading 'playbackRate')" even though I am pressing shift when the page has the video element loaded.

I put the code below. Feel free to copy everything and test yourself.

Why are these problems happening and how can I fix them?

manifest:

{
    "manifest_version": 2,
    "name": "Playback Speed Controller",
    "version": "1.0",
    "description": "Change playback speed using Shift + Scroll Up/Down.",
    "icons": {
        "48": "icons/playback-speed-controller-48.png"
    },
    "content_scripts": [
        {
            "matches": [
                "https://odysee.com/*",
                "http://odysee.com/*",
                "https://www.youtube.com/*"
            ],
            "js": [
                "playspeed.js"
            ],
            "run_at": "document_end"
        }
    ]
}

playspeed.js

vid = document.querySelector('video');

document.addEventListener('keydown', changeSpeed);

function changeSpeed(ke) {
    if (ke.shiftKey) {
        document.addEventListener('wheel', function (se) {
            if (se.deltaY < 0) {
                increaseSpeed();
            } else if (se.deltaY > 0) {
                decreaseSpeed();
            }
        })
    }
}

function decreaseSpeed() {
    vid.playbackRate -= 0.25;
}

function increaseSpeed() {
    vid.playbackRate += 0.25;
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You're adding a new wheel listener each time the shiftKey is pressed so all these past listeners run forever and get triggered on a wheel scroll and apply their changes to the rate.

The solution is to remove keydown and use one global wheel listener that checks the shiftKey:

document.addEventListener('wheel', e => {
  if (e.shiftKey) {
    vid.playbackRate -= Math.sign(e.deltaY) * .25;
  }
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda