Disable Live Connection

Disable live connection to Deezer which is used to sync things like the current playing track across devices. This for example, allows you to play on multiple devices simultaneously.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Disable Live Connection
// @description Disable live connection to Deezer which is used to sync things like the current playing track across devices. This for example, allows you to play on multiple devices simultaneously.
// @author      bertigert
// @version     1.0.0
// @icon        https://www.google.com/s2/favicons?sz=64&domain=deezer.com
// @namespace   Violentmonkey Scripts
// @match       https://www.deezer.com/us/*
// @grant       none
// run-at       document-start
// ==/UserScript==


(function() {
    "use strict";

    function debug(...args) {
        console.debug("[Disable Live Connection]", ...args);
    }
    function log(...args) {
        console.log("[Disable Live Connection]", ...args);
    }

    const original_websocket = window.WebSocket;

    const blocked_patterns = [
        /^wss?:\/\/live\.deezer\.com\/ws\/[0-9a-f]+\?version=[0-9]*$/,
    ];

    const hooked_websocket = function(url, protocols) {
        // debug("New WebSocket, URL:", url);
        const should_block = blocked_patterns.some(pattern => pattern.test(url));

        if (should_block) {
            debug(`Blocked WebSocket connection to: ${url}`);
            return {
                close: () => {},
                send: () => {},
                addEventListener: () => {},
                removeEventListener: () => {},
                readyState: 2, // this cannot be 3 since it tries to reconnect otherwise, any value other than 3 would work i think
                CONNECTING: 0,
                OPEN: 1,
                CLOSING: 2,
                CLOSED: 3
            };
        }

        return new original_websocket(url, protocols);
    };

    Object.setPrototypeOf(hooked_websocket, original_websocket);
    Object.getOwnPropertyNames(original_websocket).forEach(prop => {
        try {
            hooked_websocket[prop] = original_websocket[prop];
        } catch (e) {
        }
    });
    window.WebSocket = hooked_websocket;
})();