blob: 77187898dd2d71d998bcbd769f07ccef117d1eb7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
function downloadResource(info, tab) {
let url = info['srcUrl']
let filename = url.substring(url.lastIndexOf('/')+1)
if (filename.indexOf('?') !== false)
filename = filename.substring(0, filename.indexOf('?'))
filename = safeFileName(filename)
chrome.downloads.download({
url,
filename,
saveAs: false
})
}
chrome.contextMenus.create({
"title": "Save to Downloads…",
"contexts": ["image"],
"onclick": downloadResource
})
function safeFileName(str) {
if (/[|"*?:<>]/.test(str))
str = str.replace(/[\/\\|"*?:<>]/g, '_');
return str
}
|