Greasy Fork is available in English.

Export Shopify Fullsize File URLs

Export all fullsize file URLs from Shopify to clipboard and log them in console (bulk export)

Versión del día 28/5/2024. Echa un vistazo a la versión más reciente.

// ==UserScript==
// @name         Export Shopify Fullsize File URLs
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  Export all fullsize file URLs from Shopify to clipboard and log them in console (bulk export)
// @author       sharmanhall
// @match        https://admin.shopify.com/store/*/content/files?limit=*&selectedView=all
// @match        https://admin.shopify.com/store/*/content/files*
// @grant        GM_setClipboard
// @grant        GM_log
// @run-at       document-end
// @license      MIT
// @icon         https://www.google.com/s2/favicons?sz=64&domain=shopify.com
// @compatible         chrome
// @compatible         edge
// @compatible         firefox
// @compatible         safari
// @compatible         brave
// ==/UserScript==

(function() {
    'use strict';

    // Function to extract file URLs
    function extractFileUrls() {
        // Select all elements that contain file URLs using the provided selector
        const fileElements = document.querySelectorAll('td._ThumbnailCell_b1ynd_1.Polaris-IndexTable__TableCell div > div > button > span img');

        // Extract URLs from the elements and convert to fullsize image URLs
        const fileUrls = Array.from(fileElements).map(el => el.src.replace('_60x60', ''));

        // Log the URLs to the console
        console.log('Fullsize File URLs:', fileUrls);

        // Copy URLs to clipboard
        GM_setClipboard(fileUrls.join('\n'));

        // Log success message
        GM_log('Fullsize file URLs copied to clipboard.');
    }

    // Function to create a floating button for extracting URLs
    function createFloatingButton() {
        const button = document.createElement('button');
        button.innerText = 'Export File URLs';
        button.style.position = 'fixed';
        button.style.bottom = '10px';
        button.style.right = '10px';
        button.style.zIndex = '1000';
        button.style.padding = '10px';
        button.style.backgroundColor = '#008CBA';
        button.style.color = 'white';
        button.style.border = 'none';
        button.style.borderRadius = '5px';
        button.style.cursor = 'pointer';

        button.addEventListener('click', extractFileUrls);

        document.body.appendChild(button);
    }

    // Function to create a floating input area for changing the limit parameter
    function createLimitInput() {
        const container = document.createElement('div');
        container.style.position = 'fixed';
        container.style.bottom = '50px';
        container.style.right = '10px';
        container.style.zIndex = '1000';
        container.style.padding = '10px';
        container.style.backgroundColor = '#fff';
        container.style.border = '1px solid #ccc';
        container.style.borderRadius = '5px';

        const label = document.createElement('label');
        label.innerText = 'Set Limit: ';
        label.style.marginRight = '5px';

        const input = document.createElement('input');
        input.type = 'number';
        input.value = 10;
        input.style.marginRight = '5px';
        input.style.width = '50px';

        const setButton = document.createElement('button');
        setButton.innerText = 'Set';
        setButton.style.padding = '5px';
        setButton.style.backgroundColor = '#008CBA';
        setButton.style.color = 'white';
        setButton.style.border = 'none';
        setButton.style.borderRadius = '5px';
        setButton.style.cursor = 'pointer';

        setButton.addEventListener('click', () => {
            const limit = input.value;
            const currentUrl = new URL(window.location.href);
            currentUrl.searchParams.set('limit', limit);
            window.location.href = currentUrl.toString();
        });

        container.appendChild(label);
        container.appendChild(input);
        container.appendChild(setButton);

        document.body.appendChild(container);
    }

    // Function to create quick change buttons
    function createQuickChangeButtons() {
        const limits = [10, 50, 100, 200, 250];
        const container = document.createElement('div');
        container.style.position = 'fixed';
        container.style.bottom = '110px';
        container.style.right = '10px';
        container.style.zIndex = '1000';
        container.style.padding = '10px';
        container.style.backgroundColor = '#fff';
        container.style.border = '1px solid #ccc';
        container.style.borderRadius = '5px';
        container.style.display = 'flex';
        container.style.flexDirection = 'column';
        container.style.gap = '5px';

        limits.forEach(limit => {
            const button = document.createElement('button');
            button.innerText = `Set Limit ${limit}`;
            button.style.padding = '5px';
            button.style.backgroundColor = '#008CBA';
            button.style.color = 'white';
            button.style.border = 'none';
            button.style.borderRadius = '5px';
            button.style.cursor = 'pointer';

            button.addEventListener('click', () => {
                const currentUrl = new URL(window.location.href);
                currentUrl.searchParams.set('limit', limit);
                window.location.href = currentUrl.toString();
            });

            container.appendChild(button);
        });

        document.body.appendChild(container);
    }

    // Wait for the page to fully load
    window.addEventListener('load', () => {
        createFloatingButton();
        createLimitInput();
        createQuickChangeButtons();
    });

})();