Deezer List All Releases

Lists ALL releases at the artist page, not just hand picked ones by deezer.

当前为 2025-03-19 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Deezer List All Releases
// @description Lists ALL releases at the artist page, not just hand picked ones by deezer.
// @author      bertigert
// @version     1.0.1
// @icon        https://www.google.com/s2/favicons?sz=64&domain=deezer.com
// @namespace   Violentmonkey Scripts
// @match       https://www.deezer.com/*
// @grant       none
// ==/UserScript==


(function() {
    function log(...args) {
        console.log("[Display All Songs]", ...args);
    }
    function error(...args) {
        console.error("[Display All Songs]", ...args);
    }
    function debug(...args) {
        console.debug("[Display All Songs]", ...args);
    }

    const orig_fetch = window.fetch;

    window.history.pushState = new Proxy(window.history.pushState, {
        apply: (target, thisArg, argArray) => {
            if (location.pathname.includes("/artist/")) {
                artist_main();
            } else {
                log("Unhooking");
                window.fetch = orig_fetch;
            }
            return target.apply(thisArg, argArray);
        },
    });
    window.addEventListener("popstate", (e) => {
        if (location.pathname.includes("/artist/")) {
            artist_main();
        } else {
            log("Unhooking");
            window.fetch = orig_fetch;
        }
    });

    if (location.pathname.includes("/artist/")) {
        artist_main();
    }

    async function artist_main() {
        if (window.fetch != orig_fetch) { // already patched bc last page was artist
            return;
        }

        log("Hooking fetch");

        window.fetch = (...args) => {
            try {
                if (args[0] !== "https://pipe.deezer.com/api" ||
                    args[1].method !== "POST" ||
                    typeof args[1].body !== "string" ||
                    // check if the 2nd trace (after filtering out traces which were made using window.fetch (deezers script dont do that, so they must be user made and we ignore that) is in the web-app script (thats the way normal deezer scripts fetch data)
                    !(new Error()).stack.split("\n").filter(l=>!l.includes("window.fetch"))[1]?.includes("app-web")
                ) {
                    return orig_fetch.apply(window, args);
                }
                const operation_name = args[1].body.match(/"operationName":\s*"(.*?)"/);
                if (operation_name && operation_name[1] === "ArtistDiscographyByType") {
                    debug('Catched original artist page fetch call');
                    args[1].body = args[1].body.replace(/"subType":\s*"(.*?)"/, '"subType": null')
                                                .replace(/"mode":\s*"(.*?)"/, '"mode": "ALL"');
                }

                return orig_fetch.apply(window, args);
            } catch (e) {
                error("Error in fetch hook:", e);
                return orig_fetch.apply(window, args);
            }
        }
    }
})();