Save images to hard disk WITHOUT prompt?

Gqqnbig picture Gqqnbig · Nov 29, 2012 · Viewed 7.8k times · Source

I use twitter. Some people's tweets contain photos and I want to save them.

I checked ifttt, where twitter is not a trigger. Thus, ifttt cannot help me do it.

One idea is probably to use JavaScript. I use Firefox and installed Greasemonkey. I can write a Greasemonkey script (JavaScript) running on twitter website. Once I click "retweet" link or other button added by my script, my script examines the content of the tweet, find the URL of the photo, and save it to my disk.

One problem is how to save the image. I searched the Internet. Some use win.document.execCommand("SaveAs"), and it will show a "save as" window. Now that the window shows, why not just right click the image and choose save as manually? So I don't like the method.

Any suggestions?

Answer

user136036 picture user136036 · Apr 19, 2016

It is possible when using Tampermonkey or Violentmonkey (Firefox or Chrome).
They added the GM_Download command.
You can use it like this:

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http*://*/*
// @grant        GM_download
// ==/UserScript==


var arg = { url: "https://example.com/123456.jpg",
            name: "CustomFileName.jpg"
          };

GM_download(arg);

For more help and available options see the Tampermonkey documentation: https://tampermonkey.net/documentation.php