SimDevices Osu Beatmap Downloader Plugin

Add extra download buttons on beatmap page for SimDevices Beatmap Downloader on osu.ppy.sh

目前為 2020-04-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name               SimDevices Osu Beatmap Downloader Plugin
// @name:zh-CN         SimDevices Osu 谱面下载器插件
// @include            http*://osu.ppy.sh/*
// @copyright          2020, Handle
// @version            0.3
// @description        Add extra download buttons on beatmap page for SimDevices Beatmap Downloader on osu.ppy.sh
// @description:zh-CN  在 osu! 谱面下载页面上添加额外的按钮,可以唤醒下载器自动下载并导入谱面。
// @author             Handle
// @namespace          https://github.com/SimDevices-Project
// @supportURL         https://github.com/SimDevices-Project/beatmap-downloader-user-script/issues
// @grant              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 = `
  <a href="osu://s/${id}" class="btn-osu-big btn-osu-big--beatmapset-header">
    <span class="btn-osu-big__content ">
      <span class="btn-osu-big__left">
        <span class="btn-osu-big__text-top">启动</span>
        <span class="btn-osu-hint btn-osu-big__text-bottom">Beatmap Downloader</span>
      </span>
      <span class="btn-osu-big__icon">
        <span class="fa-fw">
          <i class="fas fa-download"></i>
        </span>
      </span>
    </span>
  </a>`
  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)
})()