MH - Enable tooltips for item favorites

Enables item description tooltips on hover for favorited items in the trap selector

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         MH - Enable tooltips for item favorites
// @namespace    https://greasyfork.org/users/918578
// @version      0.2
// @description  Enables item description tooltips on hover for favorited items in the trap selector
// @author       squash
// @match        https://www.mousehuntgame.com/*
// @match        http://www.mousehuntgame.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=mousehuntgame.com
// @grant        none
// ==/UserScript==

(function () {
	'use strict';

	function init() {
		function bindMouseEvents() {
			const itemDescriptionHover = document.querySelector(
				'.campPage-trap-itemBrowser-itemDescriptionHover'
			);
			const favorites = document.querySelectorAll(
				'.campPage-trap-itemBrowser-favorite-item'
			);
			if (favorites && itemDescriptionHover) {
				if (itemDescriptionHover.style.display == 'none') {
					itemDescriptionHover.style.marginTop = '0';
				}

				favorites.forEach(function (item) {
					if (item.dataset.itemId) {
						item.onmouseenter = function (event) {
							itemDescriptionHover.style.marginTop = '-80px';
							app.pages.CampPage.showItemDescription(event);
						};
					}
					item.onmouseleave = function () {
						itemDescriptionHover.style.marginTop = '0';
						app.pages.CampPage.hideItemDescription();
					};
				});
			}
		}

		// When favorites get rerendered after adding/removing
		let timeoutId;
		eventRegistry.addEventListener(
			app.pages.CampPage.EventUpdateItemArray,
			function (data) {
				clearTimeout(timeoutId);

				timeoutId = setTimeout(function () {
					bindMouseEvents();
				}, 1000);
			}
		);

		// When item browser is initially opened
		eventRegistry.addEventListener(
			'camp_page_toggle_blueprint',
			function (type) {
				if (type == 'item_browser') {
					bindMouseEvents();
				}
			}
		);
	}

	if (typeof eventRegistry === 'undefined') {
		// Workaround for GM
		const script = document.createElement('script');
		script.type = 'application/javascript';
		script.textContent = '(' + init + ')();';
		document.body.appendChild(script);
	} else {
		init();
	}
})();