Created
November 9, 2016 13:51
-
-
Save InKolev/8bfa19c210bc96f2c84a0f0168266707 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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