sanitize filename
This commit is contained in:
parent
aa41a8cacc
commit
e80d6a5f7b
@ -4,6 +4,7 @@ function downloadResource(info, tab) {
|
||||
let filename = url.substring(url.lastIndexOf('/')+1)
|
||||
if (filename.indexOf('?') !== false)
|
||||
filename = filename.substring(0, filename.indexOf('?'))
|
||||
filename = safeFileName(filename)
|
||||
|
||||
chrome.downloads.download({
|
||||
url,
|
||||
@ -16,4 +17,10 @@ chrome.contextMenus.create({
|
||||
"title": "Save to Downloads…",
|
||||
"contexts": ["image"],
|
||||
"onclick": downloadResource
|
||||
})
|
||||
})
|
||||
|
||||
function safeFileName(str) {
|
||||
if (/[|"*?:<>]/.test(str))
|
||||
str = str.replace(/[\/\\|"*?:<>]/g, '_');
|
||||
return str
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"name": "Save images to Downloads",
|
||||
"version": "1.0",
|
||||
"version": "1.1",
|
||||
"background": {
|
||||
"scripts": ["background.js"]
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user