🐭️ MouseHunt - Mouse Links

Add links to the MouseHunt wiki & MHDB for mice.

当前为 2022-08-13 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         🐭️ MouseHunt - Mouse Links
// @version      1.0.1
// @description  Add links to the MouseHunt wiki & MHDB for mice.
// @license      MIT
// @author       bradp
// @namespace    bradp
// @match        https://www.mousehuntgame.com/*
// @icon         https://brrad.com/mouse.png
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function () {
	'use strict';

	const addStyles = () => {
		const style = document.createElement('style');
		style.innerHTML = `
		.mouseView-titleContainer {
			height: 26px;
		}

		.mhMouseLinks {
			margin-left: 10px;
		}
		.mouseView-values {
			font-size: .9em;
		}
		.mouseView-title {
			font-size: 1.2em;
			line-height: 24px;
		}`;

		document.head.appendChild(style);
	};

	/**
	 * Return an anchor element with the given text and href.
	 *
	 * @param {string} text Text to use for link.
	 * @param {string} href URL to link to.
	 *
	 * @return {string} HTML for link.
	 */
	const makeLink = (text, href) => {
		href = href.replace(/\s/g, '_');
		return `<a href="${ href }" target="_mouse" class="mousehuntActionButton tiny mhMouseLinks"><span>${ text }</span></a>`;
	};

	const addLinks = (mouse) => {
		let links = makeLink('Wiki', `https://mhwiki.hitgrab.com/wiki/index.php/${ mouse.name }`);
		links += makeLink('mhdb', `https://dbgames.info/mousehunt/mice/${ mouse.name }`);
		const title = document.querySelector('.mouseView-title');
		title.insertAdjacentHTML('beforeend', links);
	};

	$(document).ready(function () { // eslint-disable-line no-undef
		addStyles();
	});

	$(document).ajaxComplete(function (_event, _xhr, options) { // eslint-disable-line no-undef
		if (options.url.indexOf('managers/ajax/mice/getstat.php') !== -1) {
			if (_xhr.responseJSON.mice && _xhr.responseJSON.mice.length > 0) {
				addLinks(_xhr.responseJSON.mice[ 0 ]);
			}
		}
	});
}());