SimDevices Beatmap Downloader User Script

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

当前为 2020-04-25 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         SimDevices Beatmap Downloader User Script
// @include      http*://osu.ppy.sh/*
// @copyright    2020, Handle
// @version      0.1
// @description  Add extra download buttons on beatmap page for SimDevices Beatmap Downloader.
// @author       Handle
// @namespace    https://osu.ppy.sh/
// @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">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 = requestAnimationFrame(function listener(){
      const listenElementDOM = document.querySelector(listenElementQueryWith)
      if(listenElementDOM && listenElementDOM.dataset.reactTurbolinksLoaded === '1'){
          const btnContainer = document.querySelector('.beatmapset-header__buttons')
          btnContainer.insertBefore(htmlDOM, btnContainer.lastElementChild)
      }else{
          requestAnimationFrame(listener)
      }
  })
})();