Tag Preview

Show tags on hover.

目前為 2021-03-04 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Tag Preview
// @version      1.50
// @description  Show tags on hover.
// @author       Hauffen
// @include      /https?:\/\/(e-|ex)hentai\.org\/.*/
// @require      https://code.jquery.com/jquery-3.3.1.min.js
// @namespace    https://greasyfork.org/users/285675
// ==/UserScript==

(function() {
    let $ = window.jQuery;
	const elem = {0: '.gl3m a', 1: '.gl3m a', 2: '.gl3c a', 4: '.gl3t a'};
    var spl = document.URL.split('/');
	var element, title;

	if ((spl[3].substr(0, 1).match(/[?#fptw]/i) && !spl[3].startsWith('toplist')) || !spl[3]) {
		var $tagP = $('<div id="tagPreview">');
		$tagP.css({
			position:'absolute',
			zIndex: '2',
			visiblility:'hidden !important',
			maxWidth: '400px',
			background: window.getComputedStyle(document.getElementsByClassName('ido')[0]).backgroundColor,
			border:'1px solid #000',
			padding: '10px'
		});
		$tagP.appendTo("body");
		$('#tagPreview').css('visibility', 'hidden');

		element = elem[document.getElementsByTagName("select")[0].selectedIndex];

		$('.itg').on('mouseover', `${element}`, function(e) {
			title = this.children[0].title; // Save the title so we can put it back later, probably unnecessary
            this.children[0].title = ""; // Clear the title so we don't have it over our new window

			var $content = $('<div>');
			$content.load(this.href, function() {
				document.getElementById('tagPreview').innerHTML = $('#gd2', this).html() + $('#taglist', this).html();

				var posY, posX = (e.pageX + 432 < screen.width) ? e.pageX + 10 : e.pageX - 412;
				var scrollHeight = $(document).height();
				var scrollPosition = $(window).height() + $(window).scrollTop();

				if ((scrollHeight - scrollPosition) < (scrollHeight / 10)) { posY = (e.pageY + 300 < scrollHeight) ? e.pageY + 10 : e.pageY - 300; }
				else { posY = e.pageY + 10; }

				$tagP.css({
					left: posX,
					top: posY,
					border: '1px solid ' + window.getComputedStyle(document.getElementsByTagName("a")[0]).getPropertyValue("color"),
					visibility: 'visible'
				});
				$('#tagPreview').css('visibility', 'visible');
			});
		}).on('mousemove', `${element}`,function(e) {
			var posY, posX = (e.pageX + 432 < screen.width) ? e.pageX + 10 : e.pageX - 412;
			var scrollHeight = $(document).height();
			var scrollPosition = $(window).height() + $(window).scrollTop();

			if ((scrollHeight - scrollPosition) < (scrollHeight / 10)) { posY = (e.pageY + document.getElementById('tagPreview').offsetHeight < window.innerHeight) ? e.pageY + 10 : e.pageY - 10 - document.getElementById('tagPreview').offsetHeight; }
			else { posY = e.pageY + 10; }

			$tagP.css({
				visibility:'visible',
				top: posY,
				left: posX
			});
			$('#tagPreview').css('visibility', 'visible');
		}).on('mouseout', `${element}`, function() {
            this.children[0].title = title; // Put the saved title back
			$tagP.css({
				visibility:'hidden'
			});
			$('#tagPreview').css('visibility', 'hidden');
			$tagP.empty();
		});

		$(document).on('scroll', function() {
			document.getElementById('tagPreview').style.visibility = 'hidden';
		});
	} else return;
})();