ClipTags (RED/OPS)

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
    });

})();