-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.js
38 lines (31 loc) · 813 Bytes
/
view.js
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
let $ = require("jquery");
let fs = require("fs");
let filename = "links";
let sno = 0;
$("#add-to-list").on("click", () => {
let link = $("#Link").val();
fs.appendFile("links", "127.0.0.1" + " " + link + "\n");
addEntry(link);
});
function addEntry(link) {
if (link) {
sno++;
let updateString = "<tr><td>" + sno + "</td><td>" + link + "</td></tr>";
$("#link-table").append(updateString);
}
}
function loadAndDisplayLinks() {
//Check if file exists
if (fs.existsSync(filename)) {
let data = fs.readFileSync(filename, "utf8").split("\n");
data.forEach(index => {
addEntry(link);
});
} else {
console.log("File Doesn't Exist. Creating new file.");
fs.writeFile(filename, "", err => {
if (err) console.log(err);
});
}
}
loadAndDisplayLinks();