file saver

library for save various data into file

Ten skrypt nie powinien być instalowany bezpośrednio. Jest to biblioteka dla innych skyptów do włączenia dyrektywą meta // @require https://update.greatest.deepsurf.us/scripts/39714/259782/file%20saver.js

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

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

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        file saver
// @namespace   https://greatest.deepsurf.us/users/174399
// @description library for save various data into file
// @version     0.1.0
// ==/UserScript==

function saveFile(name, source)
{
	var a = document.createElement('a');
	a.download = name;
	a.href = source;
	document.body.appendChild(a);
	a.click();
	a.parentNode.removeChild(a);
}
function createFile(data, type){return createResource(new Blob([data], {type: type}));}
function createResource(blob)
{
	var wurl = window.URL || window.webkitURL,
		resource = wurl.createObjectURL(blob);
	setTimeout(function(){wurl.revokeObjectURL(resource);}, 1e4);
	return resource;
}
function createBlob(base64, type, len)
{
	len = len || 1024;
	var bytes = [];
	for(var offset = 0, charString = atob(base64), chunk, chunkBytes; offset < charString.length; offset += len)
	{
		chunk = charString.slice(offset, offset + len);
		chunkBytes = new Array(chunk.length);
		for(var i = 0; i < chunk.length; ++i)
			chunkBytes[i] = chunk.charCodeAt(i);
		bytes.push(new Uint8Array(chunkBytes));
	}
	return new Blob(bytes, {type: type});
}
function saveData(name, data, type){saveFile(name, createFile(data, type));}
function saveBlob(name, blob){saveFile(name, createResource(blob));}
function saveBase64(name, base64, type){saveBlob(name, createBlob(base64, type));}