Skip to content

Instantly share code, notes, and snippets.

@InKolev
Created November 9, 2016 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InKolev/8bfa19c210bc96f2c84a0f0168266707 to your computer and use it in GitHub Desktop.
Save InKolev/8bfa19c210bc96f2c84a0f0168266707 to your computer and use it in GitHub Desktop.
$(function () {
// TODO: expand
const filetypeMap = {
'javascript': 'js',
'haskell': 'hs'
};
const $fetchBtn = $('#fetch-btn'),
$container = $('#paste-details');
$fetchBtn.on('click', function () {
const contents = $container.find('code').text(),
pasteName = $container.find('.paste-name').text();
let type = $container.find('pre').attr('class').split('-').pop();
if(filetypeMap[type]) {
type = filetypeMap[type];
}
window.URL = window.URL || window.webkitURL;
const blob = new Blob([contents], {type: 'octet/stream'});
blob.lastModifiedDate = new Date();
blob.name = pasteName;
$fetchBtn.attr('download', pasteName + '.' + type);
$fetchBtn.attr('href', window.URL.createObjectURL(blob));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment