Try to search your question here, if you can't find : Ask Any Question Now ?

Javascript KeyEvent on youtube page

HomeCategory: stackoverflowJavascript KeyEvent on youtube page
Avatarwillson asked 5 months ago

I am currently coding a small browser extension, I am listening to music compilation on youtube and I thought it would be a good idea to be able to move to next/previous song on music compilation by pressing a key (talking about 3 hours video here, not playlist).

I don’t have any experience with javascript so there is plenty of stuff I don’t know about, just started to learn.

My issue here is, I am trying to get the keypressed when I am watching a youtube video, the following code work on a dummy html page I made, but not on the youtube page.

function formatSongName(element, index, array) {
    array[index] = element.replace(/</a>s+/g, "")

document.addEventListener("keypress", function (event) {
    // "+" numpad key
    if (event.keyCode == 43) {

const text = document.getElementById("eow-description").innerHTML;

const timeStampReg = /(d{2}*d{2}+d{2})/g
const timeStampMatch = text.match(timeStampReg)

const songNameReg = /</a>[sw]+/g
const songNameMatch = text.match(songNameReg)

songNameMatch.forEach(elem => console.log(elem))


I am currently using firefox console to debug, on my dummy page it’s showing the key pressed on the console log.

My idea is to get the song timestamp + title, move to next/previous timestamp when the key is pressed.

Thank you for answering.

1 Answers
Best Answer
AvatarArben answered 5 months ago
Your Answer

10 + 3 =

Popular Tags

WP Facebook Auto Publish Powered By :