Deezer Media Session Support

Deezer Media Session Support for Chrome

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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.8
// @run-at      document-idle
// @noframes
// ==/UserScript==

(function (dzPlayer, _){
    navigator.mediaSession.setActionHandler('previoustrack', function() {
        if (!dzPlayer.isRadio() || _.noLimit){
            dzPlayer.control.prevSong();
        }
    });

    navigator.mediaSession.setActionHandler('nexttrack', function() {
        dzPlayer.radioSkipCounter = ~~_.noLimit || dzPlayer.radioSkipCounter; // unlimited skips
        dzPlayer.control.nextSong();
    });

    navigator.mediaSession.setActionHandler('play', function() {
        dzPlayer.control.play();
        if (_.pausets + _.pauseConst > +new Date()){
            _.pauseTimeout = setTimeout(function(){
                dzPlayer.radioSkipCounter = ~~_.noLimit || dzPlayer.radioSkipCounter; // unlimited skips
                dzPlayer.control.nextSong();
                _.pauseTimeout = 0;
            }, _.pauseConst)
        }
    });

    navigator.mediaSession.setActionHandler('pause', function() {
        if (_.pauseTimeout){
            clearTimeout(_.pauseTimeout);
            _.pauseTimeout = 0;
            if (!dzPlayer.isRadio() || _.noLimit){
                dzPlayer.control.prevSong();
            }
        } else {
            dzPlayer.control.pause();
        }
        _.pausets = +new Date();
    });

    navigator.mediaSession.setActionHandler('seekbackward', function() {
        dzPlayer.control.seek(Math.max(dzPlayer.getPosition() - _.seekConst, 0) / dzPlayer.getDuration());
    });

    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, {
    seekConst:30,
    noLimit:true,
    pausets:0,
    pauseConst: 333
});