// ==UserScript==
// @name OSU Download Booster
// @namespace https://www.rainng.com/
// @version 2.6
// @description Osu谱面下载加速, 为中国玩家打造, 支持Rainng(Azure99维护)和Sayo(小夜维护)的镜像
// @author Azure99
// @homepage https://www.rainng.com/osu-download-booster
// @supportURL https://www.rainng.com/osu-download-booster
// @icon https://osu.ppy.sh/favicon.ico
// @include http*://osu.ppy.sh/*
// @grant GM_xmlhttpRequest
// @connect bm4.ppy.sh
// @connect bm5.ppy.sh
// @connect bm6.ppy.sh
// @connect bm7.ppy.sh
// @connect bm8.ppy.sh
// @connect bm9.ppy.sh
// @connect bm10.ppy.sh
// @license MIT License
// @antifeature tracking
// @downloadURL https://update.greasyfork.icu/scripts/429781/OSU%20Download%20Booster.user.js
// @updateURL https://update.greasyfork.icu/scripts/429781/OSU%20Download%20Booster.meta.js
// ==/UserScript==
(function () {
'use strict';
const SAYO_URL = 'https://txy1.sayobot.cn/beatmaps/download/full/';
let lastId = -1;
let latestDownloadUrl = '';
let running = false;
setBeatmapTimer();
setButtonTimer();
injectGoogleAnalytics();
function injectGoogleAnalytics() {
let script = document.createElement('script');
script.src = 'https://www.googletagmanager.com/gtag/js?id=G-61W3GZ0ZNP';
document.body.appendChild(script);
script = document.createElement('script');
script.innerHTML = "window.dataLayer = window.dataLayer || [];\n" +
"function gtag(){dataLayer.push(arguments);}\n" +
"gtag('js', new Date());\n" +
"gtag('config', 'G-61W3GZ0ZNP');";
document.body.appendChild(script)
}
function setBeatmapTimer() {
setInterval(function () {
checkBeatmapId();
}, 500);
}
function setButtonTimer() {
setInterval(function () {
insertButton();
updateButton();
}, 100);
}
function checkBeatmapId() {
let currentId = getBeatmapId();
if (lastId !== currentId) {
lastId = currentId;
if (currentId > 0) {
getDownloadUrl(currentId);
}
}
}
function insertButton() {
let needInsert = $('.beatmapset-header__buttons').length == 1 && $('.beatmapset-header__buttons')[0].innerHTML.indexOf('/download"') && $('.btn-osu-mirror').length === 0;
if (needInsert) {
$('.beatmapset-header__buttons').append(
''
);
$('.beatmapset-header__buttons').append(
''
);
}
}
function updateButton() {
let btn = $('.btn-osu-mirror')[0];
if (btn && btn.href !== latestDownloadUrl) {
btn.href = latestDownloadUrl;
if (btn.href.startsWith('https://bm')) {
$('.btn-osu-hint')[0].innerText = '由Azure99加速';
} else {
$('.btn-osu-hint')[0].innerText = '获取地址中...';
}
}
}
function getBeatmapId() {
let url = window.location.pathname;
if (url.startsWith('/beatmapsets/')) {
let id = parseInt(url.substring(13, url.length));
if (typeof (id) == 'number' && id > 0) {
return id;
}
}
return -1;
}
function getDownloadUrl(mapId) {
if (running) {
return;
}
running = true;
latestDownloadUrl = '';
let request = GM_xmlhttpRequest({
method: 'HEAD',
url: '/beatmapsets/' + mapId + '/download',
headers: {
'Referer': 'https://osu.ppy.sh/beatmapsets/' + mapId
},
onreadystatechange: function (status) {
let url = status.finalUrl.toString();
if (url.startsWith('https://bm') && status.readyState === 2) {
running = false;
request.abort();
latestDownloadUrl = url.replace('.ppy.sh/', '.osu.rainng.com/');
}
}
});
}
})();