Twitter Image 1-Click Download Background Space

Make the background area of a Twitter-hosted image (like an address ending in .jpg) a clickable download-prompt to image itself. Think of it like 'left click empty space == save-as'.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Twitter Image 1-Click Download Background Space
// @version      0.4
// @description  Make the background area of a Twitter-hosted image (like an address ending in .jpg) a clickable download-prompt to image itself. Think of it like 'left click empty space == save-as'.
// @author       Cro
// @match        https://pbs.twimg.com/media/*
// @grant        none
// @namespace https://greasyfork.org/users/10865
// ==/UserScript==
(function () {
    'use strict';
    var img = document.getElementsByTagName('img')[0];
    var body = document.getElementsByTagName('body')[0];

    if (img && body)
    {
        var src = img.getAttribute('src');

        if (src)
        {
            var a = document.createElement('a');

            a.setAttribute('href', src);
            a.setAttribute('download', src.substr(src.lastIndexOf('/') + 1).replace(/:.*/, ''));
            a.style.setProperty('position', 'absolute');
            a.style.setProperty('height', '100%');
            a.style.setProperty('width', '100%');
            a.style.setProperty('z-index', '-1');

            body.appendChild(a);
            body.onclick = function (evt)
            {
                if (evt.target == body)
                {
                    a.click();
                }
            };
        }
    }
})();