Greasy Fork

osu!-download-beatmap-from-bloodcat

download osu beatmap from bloodcat

当前为 2017-09-14 提交的版本,查看 最新版本

// ==UserScript==
// @name         osu!-download-beatmap-from-bloodcat
// @namespace    http://tampermonkey.net/
// @version      0.4

// @description   download osu beatmap from bloodcat
// @author       jacky2001114(blow)
// @include      *osu.ppy.sh/b/*
// @include      *ous.ppy.sh/s/*
// @include      *bloodcat.com/osu/*
// @include      http://bloodcat.com/osu/?q=*&c=b&s=&m=
// @match        http://bloodcat.com/osu/?q=*&c=b&s=&m=
// @match        *osu.ppy.sh/b/*
// @match        *osu.ppy.sh/s/*
// @match        *bloodcat.com/osu/*
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==

(function() {

    'use strict';

    var str=location.href;

    var bool_cat = true;
    var bool_osu = true;


    var osu_b = str.indexOf("osu");
    var osu_c = str.indexOf(".sh");

    //check user is in osu/bloodcat page
    if(str.substring(osu_b,osu_c)!= "osu.ppy")
    {
        bool_osu=false;
    }
    else
    {
        bool_cat=false;
    }




    var beatmap_id="";


    //開始運行本腳本


    if(bool_osu){

        GM_setValue('OSU_enable',"true");
        var isB = str.indexOf('/b');
        var eee=str.indexOf("?");
        var fff=str.indexOf("&");

        //check /s or /b
        if(isB===-1)
        {

            // the song url is /s
            GM_setValue('beatmap_id',str.substring(21));
            //Get title
            getTitle();



        }else{


            // the song url is /b


            if(eee===-1){
                GM_setValue('beatmap_id',str.substring(21,fff));
                var id = GM_getValue('beatmap_id');
                creatButton(id);
            }else{
                GM_setValue('beatmap_id',str.substring(21,eee));
                var id = GM_getValue('beatmap_id');
                creatButton(id);
            }

        }


        //alert(id);




    }


    function creatButton(link){
        var add_html_start ="<button style='float:left;top:0;width:180px;height:43px;background-color:red;color:white;text-decoration: none;'><a href='http://bloodcat.com/osu/?q=";
        var add_html_end ="&c=b&s=&m=')>Blood Cat</a></button>";
        var div = document.createElement("div");
        div.innerHTML = add_html_start+link+add_html_end;
        document.getElementsByClassName('paddingboth')[0].append(div);

    }



    function getTitle(){
        //Get song name
        var title=document.getElementById("songinfo").getElementsByClassName("colour")[3].getElementsByTagName("a")[0].innerHTML;

        //creat a button element to bloodcat
        creatButton(title);


    }



    //script in bloodcat
    if(bool_cat)
    {
        if(GM_getValue('OSU_enable')==="true"){
            verify();
        }
        GM_setValue('OSU_enable',"false");
    }


    //check have the same beatmap in bloodcat
    function verify(){
        //get length of sets
        var set_num = document.getElementsByClassName('set').length;
        var sameBeatmap='';

        var id = GM_getValue('beatmap_id');


        //alert(id);
        if(set_num===0){
            alert('The beatmap have not exist!');

        }
        //check same id
        for(var i=0;i<set_num;i++){
            sameBeatmap = document.getElementsByTagName('main')[0].getElementsByClassName('set')[i].getElementsByClassName('title')[0].getAttribute('href');
            var cut=sameBeatmap.substring(2);
            if(cut === id){
                // alert("success");
                document.getElementsByTagName('main')[0].getElementsByClassName('set')[i].getElementsByClassName('title')[0].click();
            }           
        }

        if(str.indexOf(id)!== -1){
            if(set_num==1)
            {
                document.getElementsByClassName('title')[1].click();

            }


        }

    }














})();