Greasy Fork

osu! download redirector

redirect download request to bloodcat

当前为 2019-07-15 提交的版本,查看 最新版本

// ==UserScript==
// @name         osu! download redirector
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  redirect download request to bloodcat
// @author       kamimi
// @match        https://osu.ppy.sh/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    window.onload = function() {
        const bloodUrl = "https://bloodcat.com/osu/s/";

        if (window.location.pathname === "/beatmapsets") {
            document.getElementsByClassName("beatmapsets__items")[0].onclick = function () {
                replaceUrl(this, "js-beatmapset-download-link", -2);
            };
        } else if (window.location.pathname === "/p/beatmaplist") {
            replaceUrl(document, "beatmap_download_link", -1);
        }

        function replaceUrl(parent, downloadClassName, pathIndex) {
            let downloadLinks = parent.getElementsByClassName(downloadClassName);
            for (let i in downloadLinks) {
                if (downloadLinks[i].href && downloadLinks[i].href.indexOf(bloodUrl) === -1) {
                    let splitUrl = downloadLinks[i].href.split("/");
                    let index;
                    if (pathIndex >= 0) {
                        index = pathIndex;
                    } else {
                        index = splitUrl.length + pathIndex;
                    }
                    let setId = splitUrl[index];
                    downloadLinks[i].href = bloodUrl + setId;
                }
            }
        }
    }
})();