카테고리 없음

TamperMonkey_자동화 스크립트

헛둘이 2024. 8. 21. 06:42
// ==UserScript==
// @name         XPath Button Clicker
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  XPath를 통해 특정 버튼을 클릭하는 스크립트
// @author       Your Name
// @match        https://honglab.co.kr/collections
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // XPath를 통한 버튼 클릭 함수
    function clickButton(xpath) {
        const result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
        const element = result.singleNodeValue;

        if (element) {
            element.click();
        }
    }

    // 페이지에 테스트용 버튼 추가
    const testButton = document.createElement('button');
    testButton.innerText = 'Click Me';
    testButton.style.position = 'fixed';
    testButton.style.top = '10px';
    testButton.style.right = '10px';
    testButton.style.zIndex = 1000;
    document.body.appendChild(testButton);

    // 테스트 버튼 클릭 시 XPath를 이용해 특정 버튼 클릭
    testButton.addEventListener('click', function() {
        clickButton("//*[@id=\"main-content\"]/div/div[2]/ul/li[2]/a/div[1]/img");  // XPath를 적절히 수정하세요
    });
})();

function clickButton(xpath) {
    const result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
    const element = result.singleNodeValue;

    if (element) {
        element.click();
    }
}

 

 

다중 처리

// ==UserScript==
// @name         Multi XPath Button Clicker
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  여러 XPath를 통해 여러 버튼을 클릭하는 스크립트
// @author       Your Name
// @match        https://example.com/*  // 적용할 웹사이트의 URL 패턴
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 주어진 XPath 목록을 통해 각각의 버튼을 클릭하는 함수
    function clickMultipleButtons(xpaths) {
        xpaths.forEach(xpath => {
            const result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
            const element = result.singleNodeValue;

            if (element) {
                element.click();
            }
        });
    }

    // 페이지에 테스트용 버튼 추가
    const testButton = document.createElement('button');
    testButton.innerText = 'Click All Buttons';
    testButton.style.position = 'fixed';
    testButton.style.top = '10px';
    testButton.style.right = '10px';
    testButton.style.zIndex = 1000;
    document.body.appendChild(testButton);

    // 테스트 버튼 클릭 시 여러 XPath를 이용해 여러 버튼 클릭
    testButton.addEventListener('click', function() {
        const xpaths = [
            "//button[@id='download-button']",    // 첫 번째 버튼의 XPath
            "//button[@id='another-button']",     // 두 번째 버튼의 XPath
            "//a[@id='link-button']"              // 세 번째 버튼의 XPath (예시)
        ];

        clickMultipleButtons(xpaths);
    });
})();

 

다중 다운로드 및 이름 변경

// ==UserScript==
// @name         Multi-file Downloader with Custom Names
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  여러 파일을 동시에 다운로드하고 파일 이름을 원하는 대로 변경
// @author       Your Name
// @match        https://example.com/*  // 적용할 웹사이트의 URL 패턴
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 파일 URL과 사용자 정의 파일 이름 배열
    const filesToDownload = [
        {
            url: 'https://example.com/file1.zip',   // 첫 번째 파일 URL
            name: 'custom_name1.zip'                // 첫 번째 파일의 사용자 정의 이름
        },
        {
            url: 'https://example.com/file2.zip',   // 두 번째 파일 URL
            name: 'custom_name2.zip'                // 두 번째 파일의 사용자 정의 이름
        },
        {
            url: 'https://example.com/file3.zip',   // 세 번째 파일 URL
            name: 'custom_name3.zip'                // 세 번째 파일의 사용자 정의 이름
        },
        {
            url: 'https://example.com/file4.zip',   // 네 번째 파일 URL
            name: 'custom_name4.zip'                // 네 번째 파일의 사용자 정의 이름
        }
    ];

    // 단일 파일을 다운로드하고 이름을 지정하는 함수
    function downloadFile(file) {
        fetch(file.url)
            .then(response => response.blob())
            .then(blob => {
                const link = document.createElement('a');
                link.href = URL.createObjectURL(blob);
                link.download = file.name;
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
            });
    }

    // 페이지에 다운로드 버튼 추가
    const downloadButton = document.createElement('button');
    downloadButton.innerText = 'Download All Files';
    downloadButton.style.position = 'fixed';
    downloadButton.style.top = '10px';
    downloadButton.style.right = '10px';
    downloadButton.style.zIndex = 1000;
    document.body.appendChild(downloadButton);

    // 다운로드 버튼 클릭 시 모든 파일 다운로드
    downloadButton.addEventListener('click', function() {
        filesToDownload.forEach(file => {
            downloadFile(file);
        });
    });
})();