Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// ==UserScript==
// @name GM_download emulation
// @namespace http://tampermonkey.net/
// @version 0.1
// @description emulate GM_download functionality
// @require https://github.com/eligrey/FileSaver.js/raw/master/FileSaver.js
// @match http://tampermonkey.net/empty.html
// @grant GM_xmlhttpRequest
// @copyright 2014, Jan Biniok
// ==/UserScript==
var GM_download_emu = function(url, name) {
GM_xmlhttpRequest({
method: 'GET',
url: url,
onload: function(r) {
var bb = new Blob([r.responseText], {type: 'text/plain'});
saveAs(bb, name);
}
});
};
GM_download_emu('http://tampermonkey.net/favicon.ico', 'favicon.ico' /* .exe .sh .crx*/);
@pyhedgehog

This comment has been minimized.

Show comment Hide comment
@pyhedgehog

pyhedgehog Jul 2, 2015

text/plain? Maybe {type:parseResponseHeaders(r.responseHeaders)['content-type']}? Or at lease application/octet-stream?

text/plain? Maybe {type:parseResponseHeaders(r.responseHeaders)['content-type']}? Or at lease application/octet-stream?

@martixy

This comment has been minimized.

Show comment Hide comment
@martixy

martixy Mar 12, 2016

Or maybe responseType: "blob",, then saveAs(r.response, name);.
You see, this version doesn't really work in some cases(images, so far as I've discovered).

martixy commented Mar 12, 2016

Or maybe responseType: "blob",, then saveAs(r.response, name);.
You see, this version doesn't really work in some cases(images, so far as I've discovered).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment