LZTlastPostPreview

Предпросмотр последнего поста в теме

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         LZTlastPostPreview
// @namespace    MeloniuM/LZT
// @version      1.0
// @description  Предпросмотр последнего поста в теме
// @author       MeloniuM
// @match        https://zelenka.guru/*
// @match        https://lolz.live/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function is_scrolling() {
		return window.lastScrollTime && Date.now() < window.lastScrollTime + 500
	}

    XenForo.lastPostInfoPreview = function($el){
        var previewUrl;

		if (!parseInt(XenForo._enableOverlays)) {
			return;
		}

		if (!(previewUrl = $el.attr('href'))) {
			console.warn('Preview tooltip has no preview: %o', $el);
			return;
		}

		$el.find('[title]').andSelf().attr('title', '');
		var loaded = false;

		tippy($el.get(), {
			touch: false,
			interactive: false,
			arrow: true,
			theme: 'popup PreviewTooltip',
			animation: 'shift-toward',
			distance: 5,
			appendTo: $el[0] || document.body,
			delay: [300, 0],
			maxWidth: 400,
			placement: 'top-start',
			flipOnUpdate: true,
			content: '',
			popperOptions: {
				modifiers: {
					computeStyle: {
						gpuAcceleration: false
					}
				}
			},
			onShow(instance) {

				if (is_scrolling()) {
					clearTimeout(XenForo._ShowPreviewTimeout);
					XenForo._ShowPreviewTimeout = setTimeout(function () {
						console.log('check scroll', is_scrolling());
						if (!is_scrolling()) {
							console.log('trigger hover', $el[0]._tippy);
							$el[0]._tippy.show();
						}
					}, 700);

					return false;
				}

				if (XenForo._ActivePreviewTooltip && XenForo._ActivePreviewTooltip !== instance) {
					XenForo._ActivePreviewTooltip.hide();
				}

				if (!loaded) {
					XenForo.ajax(previewUrl + 'translate', {}, function (ajaxData) {
                        let template = `<div class="text"><blockquote class="previewText"></blockquote></div>`
                        loaded = true;
                        var $content = $('#PreviewTooltip').clone();
                        $content.find('.previewContent').html('');
                        $(`<div class="text"><blockquote class="previewText">${$(ajaxData.messagesTemplateHtml[previewUrl.replace('posts/', '#post-').replace('/', '')]).find('.messageContent .messageText').html()}</blockquote></div>`).xfInsert('appendTo', $content.find('.previewContent'), 'fadeIn', 50, function () {
                            instance.setContent($content.html());
                            loaded = true;
                            if ($el.is(':hover')) {
                                instance.show();
                                    XenForo._ActivePreviewTooltip = instance;
                                return true;
                            }
                        });
                        return true;
                    });

					return false;
				}

				return true;
			},
		})
    }
    XenForo.register('a.lastPostInfo', 'XenForo.lastPostInfoPreview');
    $('a.lastPostInfo').each(function(){
        XenForo.lastPostInfoPreview($(this));
    })
})();