您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
simple wrapper for making osu related sequential web requests
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/441005/1024904/OsuWebRequests.js
class Request { constructor(url, params, callback) { this.url = new URL(url); this.url.search = new URLSearchParams(params).toString(); this.callback = callback; } send(cb) { fetch(this.url, { credentials: "include" }).then(res => { cb(); this.callback(res); }).catch(err => { cb(); console.log(err); }); } } class Web { base = "https://osu.ppy.sh"; constructor(apiKey = null) { this.key = apiKey; this.requests = []; } get(path, params, cb) { const req = new Request(`${this.base}${path}`, params, cb); this.queue(req); } api(path, params, cb) { params.k = this.key; const req = new Request(`${this.base}/api${path}`, params, cb); this.queue(req); } queue(req) { this.requests.push(req); if (this.requests.length === 1) { this.next(); } } next() { if (this.requests.length === 0) { return; } const req = this.requests[0]; req.send(() => { this.requests.shift(); this.next(); }); } }