Image Downloader Button

Adds a download button to every image on the page

Από την 11/04/2025. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Image Downloader Button
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds a download button to every image on the page
// @author       You
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Add a download button to each image
    function addDownloadButtons() {
        const images = document.querySelectorAll('img');
        images.forEach(img => {
            // Skip if button already added
            if (img.dataset.hasDownloadButton) return;

            // Create button
            const button = document.createElement('button');
            button.textContent = '⬇️';
            button.style.position = 'absolute';
            button.style.top = '5px';
            button.style.left = '5px';
            button.style.zIndex = 9999;
            button.style.background = 'white';
            button.style.border = '1px solid #ccc';
            button.style.cursor = 'pointer';

            // Button click downloads the image
            button.addEventListener('click', (e) => {
                e.stopPropagation();
                e.preventDefault();

                const link = document.createElement('a');
                link.href = img.src;
                link.download = img.src.split('/').pop().split('?')[0]; // try to name file from URL
                link.click();
            });

            // Wrap image in a relative container to position button
            const wrapper = document.createElement('div');
            wrapper.style.position = 'relative';
            wrapper.style.display = 'inline-block';
            img.parentNode.insertBefore(wrapper, img);
            wrapper.appendChild(img);
            wrapper.appendChild(button);

            img.dataset.hasDownloadButton = true;
        });
    }

    // Run after DOM loads
    window.addEventListener('load', addDownloadButtons);

    // Run again if the page updates dynamically
    setInterval(addDownloadButtons, 3000);
})();