// ==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
// @downloadURL none
// ==/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 ="";
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