-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathbrowsers.js
More file actions
119 lines (109 loc) · 3.11 KB
/
browsers.js
File metadata and controls
119 lines (109 loc) · 3.11 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const Path = require('path')
const fs = require("fs");
const { setupDefaultPaths: setupPaths } = require('./history_paths');
const CHROME = "Google Chrome",
FIREFOX = "Mozilla Firefox",
TORCH = "Torch",
OPERA = "Opera",
SEAMONKEY = "SeaMonkey",
VIVALDI = "Vivaldi",
MAXTHON = "Maxthon",
EDGE = "Microsoft Edge",
BRAVE = "Brave",
AVAST = "AVAST Browser";
let browserDbLocations = {
chrome: "",
firefox: "",
opera: "",
edge: "",
torch: "",
seamonkey: "",
vivaldi: "",
maxthon: "",
brave: "",
avast: ""
};
let defaultPaths = setupPaths();
/**
* Find all files recursively in specific folder with specific extension, e.g:
* findFilesInDir('./project/src', '.html') ==> ['./project/src/a.html','./project/src/build/index.html']
* @param {String} startPath Path relative to this file or other file which requires this files
* @param {String} filter Extension name, e.g: '.html'
* @param targetFile
* @param depth
* @return {Array} Result files with path string in an array
*/
function findFilesInDir(startPath, filter, targetFile, depth = 0) {
if(depth === 4){
return [];
}
let results = [];
if (!fs.existsSync(startPath)) {
//console.log("no dir ", startPath);
return results;
}
let files = fs.readdirSync(startPath);
for (let i = 0; i < files.length; i++) {
let filename = Path.join(startPath, files[i]);
if (!fs.existsSync(filename)) {
// console.log('file doesn\'t exist ', startPath);
continue;
}
let stat = fs.lstatSync(filename);
if (stat.isDirectory()) {
results = results.concat(findFilesInDir(filename, filter, targetFile, depth + 1)); //recurse
} else if(filename.endsWith(targetFile) === true) {
// console.log('-- found: ', filename);
results.push(filename);
}
/*
} else if (filename.indexOf(filter) >= 0 && regExp.test(filename)) {
results.push(filename);
} else if (filename.endsWith('\\History') === true) {
// console.log('-- found: ', filename);
results.push(filename);
}*/
}
return results;
}
/**
* Finds the path to the browsers DB file.
* Returns an array of strings, paths, or an empty array
* @param path
* @param browserName
* @returns {Array}
*/
function findPaths(path, browserName) {
switch (browserName) {
case FIREFOX:
case SEAMONKEY:
return findFilesInDir(path, ".sqlite", Path.sep + 'places.sqlite');
case CHROME:
case TORCH:
case OPERA:
case BRAVE:
case VIVALDI:
case EDGE:
case AVAST:
return findFilesInDir(path, "History", Path.sep + 'History');
case MAXTHON:
return findFilesInDir(path, ".dat", Path.sep + 'History.dat');
default:
return [];
}
}
module.exports = {
findPaths,
browserDbLocations,
defaultPaths,
CHROME,
FIREFOX,
TORCH,
OPERA,
SEAMONKEY,
VIVALDI,
MAXTHON,
BRAVE,
EDGE,
AVAST
};