// ==UserScript== // @name Deezer Media Session Support // @namespace http://tampermonkey.net/ // @description Deezer Media Session Support for Chrome // @include http://*.deezer.com/* // @include https://*.deezer.com/* // @version 1.0.7 // @run-at document-idle // @noframes // @downloadURL none // ==/UserScript== (function (dzPlayer, prevSongId, seekConst, noLimit, pausets){ navigator.mediaSession.setActionHandler('previoustrack', null); navigator.mediaSession.setActionHandler('previoustrack', function() { if (!dzPlayer.isRadio() || noLimit){ dzPlayer.control.prevSong(); } }); navigator.mediaSession.setActionHandler('nexttrack', null); navigator.mediaSession.setActionHandler('nexttrack', function() { dzPlayer.radioSkipCounter = ~~noLimit || dzPlayer.radioSkipCounter; // unlimited skips dzPlayer.control.nextSong(); }); navigator.mediaSession.setActionHandler('play', null); navigator.mediaSession.setActionHandler('play', function() { dzPlayer.control.play(); if (pausets + 333 > +new Date()){ dzPlayer.radioSkipCounter = ~~noLimit || dzPlayer.radioSkipCounter; // unlimited skips dzPlayer.control.nextSong(); } }); navigator.mediaSession.setActionHandler('pause', null); navigator.mediaSession.setActionHandler('pause', function() { dzPlayer.control.pause(); pausets = +new Date(); }); navigator.mediaSession.setActionHandler('seekbackward', null); navigator.mediaSession.setActionHandler('seekbackward', function() { dzPlayer.control.seek(Math.max(dzPlayer.getPosition() - seekConst, 0) / dzPlayer.getDuration()); }); navigator.mediaSession.setActionHandler('seekforward', null); navigator.mediaSession.setActionHandler('seekforward', function() { dzPlayer.control.seek(Math.min(dzPlayer.getPosition() + seekConst, dzPlayer.getDuration()) / dzPlayer.getDuration()); }); // block deezer from overriding userscript actions MediaSession.prototype.setActionHandler = function(){}; //(a,b){console.log(a,b); }; })(dzPlayer, 0, 30, true, {});