LZTCopyLink

1 секунда для копирование

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         LZTCopyLink
// @namespace    http://tampermonkey.net/
// @version      1.8
// @description  1 секунда для копирование  
// @author       HashBrute
// @match        https://lolz.live/*
// @grant        GM_setClipboard
// ==/UserScript==

(function() {
    'use strict';

    function addCopyLinkButtonToFirstPost() {
        const firstPost = document.querySelector('li.message.firstPost');
        if (!firstPost || firstPost.querySelector('.copyLinkButton')) return;

        const postId = firstPost.id;
        const authorName = firstPost.getAttribute('data-author');

        const copyLinkButton = document.createElement('a');
        copyLinkButton.setAttribute('role', 'button');
        copyLinkButton.classList.add('item', 'control', 'copyLinkButton');
        copyLinkButton.title = `Скопировать ссылку на пост ${authorName}`;
        copyLinkButton.setAttribute('data-username', authorName);

        const icon = document.createElement('i');
        icon.className = 'fa fa-wheelchair';
        icon.style.fontSize = '20px';
        icon.style.color = '#8C8C8C';
        icon.style.marginRight = '5px';

        copyLinkButton.appendChild(icon);

        copyLinkButton.addEventListener('click', () => {
            const link = `${window.location.origin}${window.location.pathname}#${postId}`;
            GM_setClipboard(link);

            if (typeof XenForo !== 'undefined' && typeof XenForo.alert === 'function') {
                XenForo.alert('Ссылка скопирована в буфер обмена!', '', 5000);
            }
        });

        const publicControls = firstPost.querySelector('.publicControls');
        if (publicControls) {
            publicControls.appendChild(copyLinkButton);
        }
    }

    const observer = new MutationObserver(() => {
        addCopyLinkButtonToFirstPost();
    });

    observer.observe(document.body, { childList: true, subtree: true });

})();