Greasy Fork

来自缓存

Greasy Fork is available in English.

SOOP - 하이라이트 댓글 자동 생성

하이라이트 댓글 링크를 자동으로 생성하고 복사하는 버튼 추가

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         SOOP - 하이라이트 댓글 자동 생성
// @icon         https://www.google.com/s2/favicons?sz=64&domain=www.sooplive.co.kr
// @namespace    http://tampermonkey.net/

// @license      MIT
// @author       고기
// @version      250224
// @match        https://ch.sooplive.co.kr/*/post/*
// @description  하이라이트 댓글 링크를 자동으로 생성하고 복사하는 버튼 추가

// @grant        GM_setClipboard

// ==/UserScript==

(function() {
    'use strict';

    function generateHighlightLink(commentId) {
        if (!commentId) {
            alert("답글을 누른 후 눌러주세요.");
            return;
        }

        let url = window.location.href;
        let postId = url.match(/post\/(\d+)/);
        if (!postId) {
            alert("게시글 ID를 찾을 수 없습니다.");
            return;
        }

        let newUrl = `https://ch.sooplive.co.kr/${window.location.pathname.split("/")[1]}/post/${postId[1]}#comment_noti${commentId}`;
        GM_setClipboard(newUrl);
        alert("하이라이트 댓글이 복사되었습니다.");
    }

    function getCommentId(comment) {
        let replyInput = comment.querySelector("div[id^='reply_write_form_']");
        if (!replyInput) return null;
        let match = replyInput.id.match(/reply_write_form_(\d+)_input/);
        return match ? match[1] : null;
    }

    function addHighlightButtonToMenu(menu, comment) {
        if (!menu || menu.querySelector(".highlight-btn")) return;

        let highlightBtn = document.createElement("button");
        highlightBtn.innerHTML = "<span>하이라이트</span>";
        highlightBtn.className = "highlight-btn";
        highlightBtn.style.backgroundColor = getComputedStyle(menu.querySelector("button")).backgroundColor;
        highlightBtn.style.color = getComputedStyle(menu.querySelector("button")).color;
        highlightBtn.addEventListener("click", () => {
            let commentId = getCommentId(comment);
            generateHighlightLink(commentId);
        });

        menu.appendChild(highlightBtn);
    }

    function observeMoreLayer() {
        const observer = new MutationObserver(mutations => {
            mutations.forEach(mutation => {
                mutation.addedNodes.forEach(node => {
                    if (node.classList && node.classList.contains("more-layer")) {
                        let comment = node.closest("li");
                        if (comment) {
                            addHighlightButtonToMenu(node, comment);
                        }
                    }
                });
            });
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }

    observeMoreLayer();
})();