osu!backgrounddl

downloader for the backgrounds in osu beatmaps

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         osu!backgrounddl
// @namespace    http://osu.ppy.sh
// @version      0.12
// @description  downloader for the backgrounds in osu beatmaps
// @author       aisuneko
// @match        https://osu.ppy.sh/*
// @icon         https://osu.ppy.sh/favicon.ico
// @run-at document-body
// @license      MIT
// ==/UserScript==
const bodyList = document;
const config = {
    childList: true,
    subtree: true
};
function main(){
    let container = document.getElementsByClassName("beatmapset-header__buttons")[0];
    if (container != undefined){
        let i = container.firstChild;
        let btn = i.cloneNode(true);
        btn.setAttribute('title', 'Get background image for this diff');
        btn.innerHTML = "<span class=\"btn-osu-big__content btn-osu-big__content--center\"><span class=\"btn-osu-big__icon\"><span class=\"fa fa-fw\"><span class=\"far fa-image\"></span></span></span></span>";
        //i.parentNode.replaceChild(clm, i);
        if(container.lastChild.getAttribute("class") != btn.getAttribute("class")){
            container.append(btn);
            btn.addEventListener('click', function(){
                let re = new RegExp('\\d+', 'g');
                let res_arr = window.location.href.match(re);
                let dest = "https://beatconnect.io/bg/"+res_arr[0]+"/"+res_arr[1];
                window.open(dest);
            });
        }
    }
    return;
}
function observe(){
    let oldHref = document.location.href;
    window.onload = function() {
        let observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                if (oldHref != document.location.href) {
                    oldHref = document.location.href;
                    main();
                }
            });
        });
        observer.observe(bodyList, config);
    };
}
(function(){
    observe();
})();