diff options
| author | Teddy Wing | 2014-03-30 18:07:34 -0400 | 
|---|---|---|
| committer | Teddy Wing | 2014-03-30 18:07:34 -0400 | 
| commit | 3910c9f07a529924b3c157894f5d511ea5c6ac0b (patch) | |
| tree | ec8e41b628f4f98aa4bcbafbc614cc1af56c650c /chrome-get-urls-from-tabs-in-windows.js | |
| parent | aae7502ceca9f78aaa0bb18b1b172738422f2da7 (diff) | |
| download | chrome-copy-urls-from-all-tabs-3910c9f07a529924b3c157894f5d511ea5c6ac0b.tar.bz2 | |
Append correct file extension depending on format
For the download link, append a file extension appropriate to the type
of file being downloaded.
Diffstat (limited to 'chrome-get-urls-from-tabs-in-windows.js')
| -rw-r--r-- | chrome-get-urls-from-tabs-in-windows.js | 58 | 
1 files changed, 38 insertions, 20 deletions
diff --git a/chrome-get-urls-from-tabs-in-windows.js b/chrome-get-urls-from-tabs-in-windows.js index 5516edd..100c784 100644 --- a/chrome-get-urls-from-tabs-in-windows.js +++ b/chrome-get-urls-from-tabs-in-windows.js @@ -65,27 +65,45 @@ chrome.windows.getAll({populate:true}, function(windows){  // Adapted from:  // http://stackoverflow.com/a/18197511  create_download_link = function(text) { -	var download_link = document.createElement('a'); -	download_link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); -	download_link.setAttribute('download', generate_filename()); -	download_link.innerHTML = 'Download file'; -	 -	document.querySelector('body').appendChild(download_link); +	generate_filename(function(filename) { +		var download_link = document.createElement('a'); +		download_link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); +		download_link.setAttribute('download', filename); +		download_link.innerHTML = 'Download file'; +		 +		document.querySelector('body').appendChild(download_link); +	});  }; -generate_filename = function() { -	var d = new Date(); -	var date_string =  -		d.getFullYear()  -		+ ''  -		+ ('0' + (d.getMonth() + 1)).slice(-2)  -		+ ''  -		+ ('0' + d.getDate()).slice(-2)  -		+ '-'  -		+ ('0' + d.getHours()).slice(-2)  -		+ 'h'  -		+ d.getMinutes(); -	 -	return 'chrome-tabs-' + date_string + '.txt'; +generate_filename = function(callback) { +	chrome.storage.sync.get(function(items) { +		var format = items.file_format; +		 +		var d = new Date(); +		var date_string =  +			d.getFullYear()  +			+ ''  +			+ ('0' + (d.getMonth() + 1)).slice(-2)  +			+ ''  +			+ ('0' + d.getDate()).slice(-2)  +			+ '-'  +			+ ('0' + d.getHours()).slice(-2)  +			+ 'h'  +			+ d.getMinutes(); +		 +		 +		var file_extension = ''; +		if (format === 'yaml') { +			file_extension = 'yml'; +		} +		else if (format === 'html') { +			file_extension = 'html'; +		} +		else { +			file_extension = 'txt'; +		} +		 +		callback('chrome-tabs-' + date_string + '.' + file_extension); +	});  };
\ No newline at end of file  | 
