ScoreSaber Downloader

Adds a download button to Score Saber song pages

目前為 2020-04-01 提交的版本,檢視 最新版本

// ==UserScript==
// @name         ScoreSaber Downloader
// @version      1.0.1
// @description  Adds a download button to Score Saber song pages
// @author       bhackel
// @match        https://scoresaber.com/leaderboard/*
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// @connect      beatsaver.com
// @namespace https://gf.qytechs.cn/en/users/324178-bhackel
// ==/UserScript==

(function() {
    'use strict';

    // Create button with text, function, and classes
    var button = document.createElement('Button');
    button.className = "bhackel-button button is-dark has-background-grey-dark";
    button.onclick = request;
    button.innerHTML = "OneClick Download";

    // Add the button to the page
    var div = document.getElementsByClassName("box has-shadow")[0]
    div.appendChild(button);

    // Obtain the song hash from the page
    var id = div.children[4].innerText
    var url = "https://beatsaver.com/api/maps/by-hash/" + id;

    // Setup for Beat Saver API call
    function error(rspObj) {
        console.error("There was an error downloading the song: " + rspObj.status + " " + rspObj.statusText);
    }

    function request() {
        GM_xmlhttpRequest ({
            method:         "GET",
            url:            url,
            responseType:   "json",
            onload:         process_response,
            onabort:        error,
            onerror:        error,
            ontimeout:      error
        });
    }

    function process_response(rspObj) {
        // Check for invalid responses
        if (rspObj.status != 200 && rspObj.status != 304) {
            error(rspObj);
            return;
        }

        // Create a OneClick URL from the API response
        var oneclick_url = 'beatsaver://' + rspObj.response.key

        // Open the URL
        window.location.href = oneclick_url
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址