Media Link Extractor

Extract media links from various websites.

目前為 2025-01-14 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Media Link Extractor
// @namespace    http://tampermonkey.net/
// @version      3.2
// @description  Extract media links from various websites.
// @author       1axx
// @icon         https://img.freepik.com/premium-photo/link-icon-3d-render-illustration_567294-4275.jpg?semt=ais_hybrid
// @include      https://cyberdrop.me/*
// @include      https://files.fm/*
// @include      https://app.koofr.net/*
// @include      https://bunkr.*/*
// @include      https://*.dropbox.com/*
// @grant        GM_setClipboard
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    //  configuration for selectors and processing
    const siteConfigs = {
        'cyberdrop.me': {
            selector: '.image-container.column a.image',
            process: (el) => el.getAttribute('href'),
        },
        'files.fm': {
            selector: '.item.file.image-item a.top_button_download.my_tooltip, .item.file.video-item a.top_button_download.my_tooltip',
            process: (el) => el.getAttribute('href'),
        },
        'app.koofr.net': {
            selector: 'a[href^="/content/links/"]',
            process: (el) => el.getAttribute('href'),
        },
        'bunkr': {
            selector: 'a[href^="https://bunkrrr.org/"], a[href^="/f/"]',
            process: (el) => el.getAttribute('href'),
        },
        'dropbox.com': {
            selector: 'a[href^="https://www.dropbox.com/scl/"]',
            process: (el) => el.getAttribute('href'),
        }
    };

    let mediaLinks = new Set(); //  avoid duplicates

    // Function to collect media links
    function collectMediaLinks() {
        const host = window.location.host;
        const configKey = Object.keys(siteConfigs).find((key) => host.includes(key));
        const config = siteConfigs[configKey];
        if (!config) {
            return; // Do nothing if the site is not supported
        }

        mediaLinks.clear(); // Clear previous links
        const elements = document.querySelectorAll(config.selector);
        elements.forEach((el) => {
            const link = config.process(el);
            if (link) {
                mediaLinks.add(link.startsWith('http') ? link : `${window.location.origin}${link}`);
            }
        });
    }

    // Function to display the links
    function displayLinksUI() {
        if (mediaLinks.size === 0) return;

        const popup = document.createElement('div');
        popup.style.cssText = `
            position: fixed;
            top: 20%;
            left: 50%;
            transform: translate(-50%, -20%);
            background-color: #121212;
            padding: 20px;
            border: 2px solid #444;
            border-radius: 10px;
            z-index: 10000;
            width: 60%;
            box-shadow: 0px 0px 20px rgba(0, 255, 255, 0.3);
        `;

        const textarea = document.createElement('textarea');
        textarea.value = Array.from(mediaLinks).join('\n');
        textarea.style.cssText = `
            width: 100%;
            height: 200px;
            margin-bottom: 10px;
            background-color: #181818;
            color: #00FFFF;
            border: 1px solid #555;
            border-radius: 5px;
            padding: 10px;
            font-family: Consolas, "Courier New", monospace;
            font-size: 14px;
            resize: none;
        `;
        popup.appendChild(textarea);

        const counter = document.createElement('div');
        counter.textContent = `Total Unique Links: ${mediaLinks.size}`;
        counter.style.cssText = `
            margin-bottom: 10px;
            font-weight: bold;
            text-align: center;
            color: #00FFFF;
        `;
        popup.appendChild(counter);

        const copyButton = document.createElement('button');
        copyButton.textContent = 'Copy to Clipboard';
        copyButton.style.cssText = `
            padding: 10px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        `;
        copyButton.addEventListener('click', () => {
            textarea.select();
            document.execCommand('copy');
            alert('Links copied to clipboard!');
        });
        popup.appendChild(copyButton);

        const closeButton = document.createElement('button');
        closeButton.textContent = 'Close';
        closeButton.style.cssText = `
            margin-left: 10px;
            padding: 10px;
            background-color: #dc3545;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        `;
        closeButton.addEventListener('click', () => {
            document.body.removeChild(popup);
        });
        popup.appendChild(closeButton);

        document.body.appendChild(popup);
    }

    // Add a button to trigger the process only if the site is supported
    const host = window.location.host;
    const configKey = Object.keys(siteConfigs).find((key) => host.includes(key));

    if (configKey) {
        const extractButton = document.createElement('button');
        extractButton.textContent = 'Extract Media Links';
        extractButton.style.cssText = `
            position: fixed;
            top: 10px;
            right: 10px;
            z-index: 9999;
            background-color: #007bff;
            color: white;
            border: none;
            padding: 10px 15px;
            border-radius: 5px;
            cursor: pointer;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        `;
        extractButton.addEventListener('click', () => {
            collectMediaLinks();
            displayLinksUI();
        });

        document.body.appendChild(extractButton);

        // Monitor for dynamic content loading
        const observer = new MutationObserver(() => {
            collectMediaLinks();
        });

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