Skip to content

Instantly share code, notes, and snippets.

@MaxXx1313
Created August 5, 2019 09:11
Show Gist options
  • Save MaxXx1313/06f5851a26e000864dd2d9c954e670ae to your computer and use it in GitHub Desktop.
Save MaxXx1313/06f5851a26e000864dd2d9c954e670ae to your computer and use it in GitHub Desktop.
Enable global media keys in vk.com (tampermonkey)
// ==UserScript==
// @name Enable global media keys in vk.com
// @namespace http://github.com/MaxXx1313
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://vk.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
navigator.mediaSession.setActionHandler('previoustrack', function() {
document.querySelector('[accesskey="j"]').click();
});
navigator.mediaSession.setActionHandler('nexttrack', function() {
document.querySelector('[accesskey="l"]').click();
});
navigator.mediaSession.setActionHandler('playpause', function() {
document.querySelector('[accesskey="k"]').click();
});
navigator.mediaSession.setActionHandler('play', function() {
document.querySelector('[accesskey="k"]').click();
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment