-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
44 lines (41 loc) · 1.76 KB
/
background.js
File metadata and controls
44 lines (41 loc) · 1.76 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
chrome.downloads.onDeterminingFilename.addListener((downloadItem, suggest) => {
const categories = {
images: [
"png", "jpg", "jpeg", "webp", "gif", "bmp", "tiff", "svg", "ico", "avif", "heic"
],
compress: [
"zip", "rar", "7z", "tar", "gz", "bz2", "xz", "lz", "lzma"
],
audio: [
"mp3", "wav", "ogg", "flac", "aac", "m4a", "wma", "aiff", "alac"
],
videos: [
"mp4", "mkv", "avi", "mov", "webm", "flv", "wmv", "mpeg", "mpg", "3gp"
],
documents: [
"pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "txt", "md", "odt", "ods", "odp", "rtf", "csv"
],
code: [
"js", "ts", "py", "java", "cpp", "c", "cs", "html", "css", "json", "xml", "php", "rb", "go", "sh", "yml", "yaml", "sql"
],
torrents: ["torrent"],
isos: ["iso", "img", "bin", "cue", "nrg"],
programs: ["exe", "msi", "deb", "rpm", "apk", "dmg", "pkg", "appimage"],
ebooks: ["epub", "mobi", "azw", "azw3", "fb2", "cbz", "cbr"],
fonts: ["ttf", "otf", "woff", "woff2", "eot"],
design: ["psd", "ai", "sketch", "xd", "fig", "svgz"],
datasets: ["csv", "tsv", "jsonl", "parquet", "hdf5"]
};
const fileName = downloadItem.filename.split("/").pop();
const fileExtMatch = fileName.match(/\.([a-z0-9]+)$/i);
const fileExt = fileExtMatch ? fileExtMatch[1].toLowerCase() : "";
let subfolder = "others";
for (const [category, extensions] of Object.entries(categories)) {
if (extensions.includes(fileExt)) {
subfolder = category;
break;
}
}
const newPath = `${subfolder}/${fileName}`;
suggest({ filename: newPath });
});