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'.

  1. // ==UserScript==
  2. // @name Twitter Image 1-Click Download Background Space
  3. // @version 0.4
  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'.
  5. // @author Cro
  6. // @match https://pbs.twimg.com/media/*
  7. // @grant none
  8. // @namespace https://greasyfork.org/users/10865
  9. // ==/UserScript==
  10. (function () {
  11. 'use strict';
  12. var img = document.getElementsByTagName('img')[0];
  13. var body = document.getElementsByTagName('body')[0];
  14.  
  15. if (img && body)
  16. {
  17. var src = img.getAttribute('src');
  18.  
  19. if (src)
  20. {
  21. var a = document.createElement('a');
  22.  
  23. a.setAttribute('href', src);
  24. a.setAttribute('download', src.substr(src.lastIndexOf('/') + 1).replace(/:.*/, ''));
  25. a.style.setProperty('position', 'absolute');
  26. a.style.setProperty('height', '100%');
  27. a.style.setProperty('width', '100%');
  28. a.style.setProperty('z-index', '-1');
  29.  
  30. body.appendChild(a);
  31. body.onclick = function (evt)
  32. {
  33. if (evt.target == body)
  34. {
  35. a.click();
  36. }
  37. };
  38. }
  39. }
  40. })();