Deezer Media Session Support

Deezer Media Session Support for Chrome

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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
});