Last active
July 30, 2025 15:32
-
-
Save PiN73/89432800b84c9e5c13c7c4abba314600 to your computer and use it in GitHub Desktop.
Яндекс Музыка: плей/пауза по клавише пробел [скрипт для Tampermonkey]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Яндекс Музыка ⏵/⏸ [пробел] | |
// @version 2025-05-13 | |
// @description play/pause yandex music with space key | |
// @match https://music.yandex.ru/* | |
// @match https://music.yandex.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=music.yandex.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict' | |
const isSpace = event => { | |
return event.code === 'Space' | |
|| event.key === ' ' | |
|| event.keyCode === 32 | |
} | |
const shouldSkip = event => { | |
const el = event.target | |
return event.defaultPrevented | |
|| el.isContentEditable | |
|| el.tagName == 'INPUT' && el.type != 'range' | |
|| el.tagName == 'TEXTAREA' | |
|| el.tagName == 'SELECT' | |
|| el.tagName == 'VIDEO' | |
|| el.tagName == 'AUDIO' | |
} | |
document.addEventListener('keydown', event => { | |
if (isSpace(event) && !shouldSkip(event)) { | |
const player = document.querySelector('[aria-labelledby="player-region"]') | |
const button = | |
player.querySelector('button[aria-label="Playback"]') || | |
player.querySelector('button[aria-label="Воспроизведение"]') || | |
player.querySelector('button[aria-label="Pause"]') || | |
player.querySelector('button[aria-label="Пауза"]') | |
button.click() | |
event.preventDefault() | |
} | |
}) | |
const isEscape = event => { | |
return event.code === 'Escape' | |
|| event.key === 'Escape' | |
|| event.keyCode === 27 | |
} | |
document.addEventListener('keydown', event => { | |
if (isEscape(event)) { | |
event.target.blur() | |
} | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment