// ==UserScript== // @name SimDevices Beatmap Downloader User Script // @include http*://osu.ppy.sh/* // @copyright 2020, Handle // @version 0.3 // @description Add extra download buttons on beatmap page for SimDevices Beatmap Downloader. // @author Handle // @namespace https://github.com/SimDevices-Project // @grant none // @downloadURL none // ==/UserScript== ;(function () { 'use strict' const URL = document.URL const [mainURL, argument] = URL.substr(URL.indexOf('//') + 2).split('#') const [host, type, id] = mainURL.split('/') if (type !== 'beatmapsets') { return } const [mode, bid] = argument || [] const htmlText = ` 启动 Beatmap Downloader ` const htmlDOM = document.createRange().createContextualFragment(htmlText) const listenElementQueryWith = '.js-react--beatmapset-page' let timer = 0 const loader = () => { const listenElementDOM = document.querySelector(listenElementQueryWith) if (listenElementDOM && listenElementDOM.dataset.reactTurbolinksLoaded === '1') { const btnContainer = document.querySelector('.beatmapset-header__buttons') btnContainer.insertBefore(htmlDOM, btnContainer.lastElementChild) } else { timer = requestAnimationFrame(loader) } } timer = requestAnimationFrame(loader) // 监听 turbolinks 渲染事件 // https://greasyfork.org/zh-CN/scripts/3916-osu-my-download document.addEventListener('turbolinks:load', loader) })()