Gamebanana 자동 다운로드

Gamebanana 사이트에서 다양한 태그와 클래스를 기반으로 링크 자동 클릭 및 미디어 자동 다운로드

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Gamebanana 자동 다운로드
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Gamebanana 사이트에서 다양한 태그와 클래스를 기반으로 링크 자동 클릭 및 미디어 자동 다운로드
// @author       Your Name
// @match        *://*gamebanana.com/*
// @grant        none
// ==/UserScript==


(function() {
    'use strict';

    // 다운로드 설정
    const downloadConfig = {
        click: {
            classes: ["GreenColor"],
            substrings: [],
            tags: ["a"],  // 주로 'a' 태그만 검색
            index: 0,  // 첫 번째 링크 대상
            maxCount: 1  // 예시로 한 개만 다운로드하도록 설정
        },
        image: {
            classes: ["PrimaryPreview"],
            substrings: [],
            tags: ["a"],  // 'a' 태그만 검색
            index: 0,  // 첫 번째 링크 대상
            maxCount: 1  // 한 개만 다운로드
        },
        video: {
            classes: [],
            substrings: [],
            tags: [],
            index: 0,
            maxCount: 0
        }
    };

    // 다운로드 실행 함수
    function executeDownloads(type) {
        const config = downloadConfig[type];
        let downloads = 0;

        if (config.tags.length > 0 && config.maxCount > 0) {
            config.tags.forEach(tag => {
                const elements = document.querySelectorAll(tag);
                elements.forEach((element, index) => {
                    if (downloads >= config.maxCount) return;
                    if (index === config.index && (Array.from(element.classList).some(className =>
                        config.classes.includes(className) || config.substrings.some(sub => className.includes(sub))))) {
                        if (element.click && type === 'click') {
                            console.log(`클릭할 요소 발견: ${element.tagName}, 클래스: ${element.className}`);
                            element.click();
                            downloads++;
                        } else {
                            const url = element.tagName.toUpperCase() === tag.toUpperCase() ? element.src : element.href;
                            console.log(`다운로드할 ${type} URL 발견: ${url}`);
                            downloadMedia(url, url.split('/').pop());
                            downloads++;
                        }
                    }
                });
            });
        }
    }

    // 미디어 다운로드 함수
    function downloadMedia(url, filename) {
        const xhr = new XMLHttpRequest();
        xhr.open("GET", url, true);
        xhr.responseType = "blob";
        xhr.onload = function () {
            if (xhr.status === 200) {
                const blob = xhr.response;
                const link = document.createElement('a');
                link.href = window.URL.createObjectURL(blob);
                link.download = filename;
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
            }
        };
        xhr.send();
    }

    // 페이지 로드 후 다운로드 함수 호출
    window.addEventListener('load', () => {
        ['click', 'image', 'video'].forEach(type => {
            if (downloadConfig[type].tags.length > 0 && downloadConfig[type].maxCount > 0) {
                executeDownloads(type);
            }
        });
    });

})();