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)
|
let filename = url.substring(url.lastIndexOf('/')+1)
|
||||||
if (filename.indexOf('?') !== false)
|
if (filename.indexOf('?') !== false)
|
||||||
filename = filename.substring(0, filename.indexOf('?'))
|
filename = filename.substring(0, filename.indexOf('?'))
|
||||||
|
filename = safeFileName(filename)
|
||||||
|
|
||||||
chrome.downloads.download({
|
chrome.downloads.download({
|
||||||
url,
|
url,
|
||||||
@ -17,3 +18,9 @@ chrome.contextMenus.create({
|
|||||||
"contexts": ["image"],
|
"contexts": ["image"],
|
||||||
"onclick": downloadResource
|
"onclick": downloadResource
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function safeFileName(str) {
|
||||||
|
if (/[|"*?:<>]/.test(str))
|
||||||
|
str = str.replace(/[\/\\|"*?:<>]/g, '_');
|
||||||
|
return str
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Save images to Downloads",
|
"name": "Save images to Downloads",
|
||||||
"version": "1.0",
|
"version": "1.1",
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": ["background.js"]
|
"scripts": ["background.js"]
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user