Update hosts.js

This commit is contained in:
Namhyeon Go 2020-07-29 15:48:49 +09:00
parent 1ef81ad19a
commit d39a2c7d0b

View File

@ -11,22 +11,17 @@ exports.getHosts = function() {
var filePath = SYS.getEnvString("windir") + "\\System32\\\drivers\\etc\\hosts";
var fileContent = FILE.readFile(filePath, "utf-8");
var lines = fileContent.split(/[\r\n]+/g).filter(function(s) {
return !(s.indexOf(' #') == 0)
var rows = fileContent.split(/[\r\n]+/g).filter(function(s) {
return !(s.indexOf('#') == 0);
}).map(function(s) {
var pos = s.indexOf(' #');
if(pos > -1) {
return s.substring(pos).replace(/\s\s/g, ' ');
} else {
return s.replace(/\s\s/g, ' ');
}
var pos = s.indexOf(" #");
return (pos > -1 ? s.substring(0, pos) : s).split(/\s+/);
});
for (var i = 0; i < lines.length; i++) {
var col = lines[i].split(' ');
for (var i = 0; i < rows.length; i++) {
hosts.push({
host: col[0],
domain: col[1]
host: rows[i][0],
domain: rows[i][1]
});
}