Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!