Greasy Fork

来自缓存

Greasy Fork is available in English.

SOOP 채팅창 아이디 복사 버튼

SOOP 채팅창에 아이디 복사 버튼을 추가합니다.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         SOOP 채팅창 아이디 복사 버튼
// @namespace    https://www.sooplive.co.kr/
// @version      1.1
// @description  SOOP 채팅창에 아이디 복사 버튼을 추가합니다.
// @match        https://play.sooplive.co.kr/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=play.sooplive.co.kr
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            if (mutation.addedNodes.length) {
                mutation.addedNodes.forEach((node) => {
                    if (node.nodeType === 1 && node.classList.contains('chatIct-card')) {
                        addCopyButton(node);
                    }
                });
            }
        });
    });

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

    function addCopyButton(card) {
        let userId = card.getAttribute('user_id');
        userId = userId.replace(/\(\d+\)/g, ''); // 괄호 안의 숫자를 제거
        const menuList = card.querySelector('.menu-list');

        if (menuList) {
            const copyButton = document.createElement('button');
            copyButton.type = 'button';
            copyButton.id = 'copyUserId';
            copyButton.textContent = '아이디 복사';
            copyButton.addEventListener('click', () => {
                navigator.clipboard.writeText(userId).then(() => {
                    alert('아이디가 복사되었습니다: ' + userId);
                }).catch((err) => {
                    console.error('아이디 복사 실패: ', err);
                });
            });

            const listItem = document.createElement('li');
            listItem.appendChild(copyButton);
            menuList.insertBefore(listItem, menuList.firstChild);
        }
    }
})();