OMDB Button Adder

Adds "Rate on OMDB" button on osu! beatmap pages

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         OMDB Button Adder
// @namespace    omdbButtonAdder
// @version      1.06
// @author       cyndifusic
// @run-at       document-start
// @description  Adds "Rate on OMDB" button on osu! beatmap pages
// @include   http://osu.ppy.sh*
// @include   https://osu.ppy.sh*
// ==/UserScript==

var currentURL = window.location.href;

var extractMapsetID = function (url) {
	var startIndex = url.indexOf("beatmapsets") + 12;
	var go = true;
	var i = startIndex;
	var setID = "";
	while (go) {
		if (url.charAt(i) == "#") {
			go = false;
		} else {
			setID += url.charAt(i);
			i++;
		}
	}
	return setID;
}

var addButton = function () {
	if (currentURL.includes("beatmapsets") && currentURL.includes("#")) {
		var omdbAddress = "https://omdb.nyahh.net/mapset/" + extractMapsetID(currentURL);
		var buttonsDiv = document.getElementsByClassName("beatmapset-header__buttons")[0];
		buttonsDiv.insertAdjacentHTML('beforeend', '<a class="btn-osu-big btn-osu-big--beatmapset-header" href="' + omdbAddress + '" data-turbolinks="false" target="_blank"><span class="btn-osu-big__content"><span class="btn-osu-big__left"><span class="btn-osu-big__text-top">Rate on OMDB</span></span><span class="btn-osu-big__icon"><span class="fa fa-fw"><span class="fas fa-link"></span></span></span></span></a>');
	}
}

var checkURL = function () {
	var doubleCheck = function () {
		if (window.location.href != currentURL) {
			var currentURLIsBeatmap = window.location.href.includes("beatmapsets") && window.location.href.includes("#");
			var previousURLIsBeatmap = currentURL.includes("beatmapsets") && currentURL.includes("#");

			if (currentURLIsBeatmap && previousURLIsBeatmap) {
				if (extractMapsetID(window.location.href) != extractMapsetID(currentURL)) {
					currentURL = window.location.href;
					addButton();
				}
			}

			if (currentURLIsBeatmap && !previousURLIsBeatmap) {
				currentURL = window.location.href;
				addButton();
			}
		}
	}

	setTimeout(doubleCheck, 2000);
}

setTimeout(addButton, 1000);
document.addEventListener("click", checkURL);