ClipTags (RED/OPS)

Adds a button to copy tags as comma-separated from RED/OPS torrents, artists and requests pages.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         ClipTags (RED/OPS)
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds a button to copy tags as comma-separated from RED/OPS torrents, artists and requests pages.
// @match        https://redacted.sh/torrents.php?id=*
// @match        https://orpheus.network/torrents.php?id=*
// @match        https://redacted.sh/artist.php?id=*
// @match        https://orpheus.network/artist.php?id=*
// @match        https://redacted.sh/requests.php?action=view&id=*
// @match        https://orpheus.network/requests.php?action=view&id=*
// @grant        GM_setClipboard
// @author       rodriguito
// ==/UserScript==

(function() {
    'use strict';

    function extractTags(container) {
        const tagLinks = container.querySelectorAll('a[href*="taglist="]');

        const tags = Array.from(tagLinks)
            .map(a => a.textContent.trim())
            .filter(Boolean);

        return [...new Set(tags)].join(',');
    }

    function findTagsContainer() {
        const elements = document.querySelectorAll('div, td, li');

        for (let el of elements) {
            const text = (el.innerText || el.textContent || "").trim();

            if (text.startsWith("Tags")) {
                return el;
            }
        }

        return null;
    }

    function findTagsLabel(container) {
        const walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT);

        let node;
        while (node = walker.nextNode()) {
            if (node.nodeValue.trim() === "Tags") {
                return node.parentElement;
            }
        }

        return null;
    }

    function insertButton(labelEl, container) {
        if (!labelEl || labelEl.querySelector('.copy-tags-btn')) return;

        labelEl.style.display = 'flex';
        labelEl.style.justifyContent = 'space-between';
        labelEl.style.alignItems = 'center';

        const btn = document.createElement('button');
        btn.textContent = "Copy Tags";
        btn.className = "copy-tags-btn";
        btn.style.padding = "2px 6px";
        btn.style.fontSize = "11px";
        btn.style.cursor = "pointer";

        btn.addEventListener('click', () => {
            const result = extractTags(container);

            if (!result) {
                alert("No tags found.");
                return;
            }

            GM_setClipboard(result);

            btn.textContent = "Copied!";
            setTimeout(() => btn.textContent = "Copy Tags", 1500);
        });

        labelEl.appendChild(btn);
    }

    function init() {
        const container = findTagsContainer();
        if (!container) return;

        const label = findTagsLabel(container);
        if (!label) return;

        insertButton(label, container);
    }

    window.addEventListener('load', () => {
        setTimeout(init, 500);
    });

})();