Added export shortcut

This commit is contained in:
neauoire
2019-11-03 09:45:03 -05:00
parent b4beaf03af
commit d4380e9887
2 changed files with 10 additions and 5 deletions

View File

@@ -56,9 +56,14 @@ function Source () {
}
this.download = (name, content, type) => {
const pom = document.createElement('a')
pom.setAttribute('download', name)
pom.setAttribute('href', 'data:' + type + ';charset=utf-8,' + encodeURIComponent(content))
pom.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }))
console.info('Source', `Downloading ${name}(${type})`)
const link = document.createElement('a')
link.setAttribute('download', name)
if (type === 'image/png' || type === 'image/jpeg') {
link.setAttribute('href', content)
} else {
link.setAttribute('href', 'data:' + type + ';charset=utf-8,' + encodeURIComponent(content))
}
link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }))
}
}