-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.js
68 lines (61 loc) · 2.04 KB
/
preload.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
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
const fs = require("fs");
const path = require('path');
const directoryPath = path.join(__dirname, 'notes');
let temp;
readFile = (documentId) => {
fs.readFile("./notes/"+documentId+".txt", (err, data) => {
if (err) console.log(err);
document.getElementById("documentContent").innerText = data.toString();
documentContent = data.toString();
});
}
writeFile = (documentId) => {
let textCont = document.getElementById("documentContent").innerText;
fs.writeFile("./notes/"+documentId+".txt", textCont, (err) => {
if (err) console.log(err);
});
}
scanFile = () => {
fs.readdir(directoryPath, (err, files) => {
if (err) console.log(err);
files.forEach( (file) => {
let fileName = removeFileExtension(file);
constructFileTitleElement(fileName);
});
});
}
removeFileExtension = (fileName) => {
let dotIndex = fileName.indexOf(".");
return fileName.substring(0, dotIndex);
}
constructFileTitleElement = (fileName) => {
let titleHeader = document.getElementById("titleHeader");
let newDiv = document.createElement("div");
newDiv.className = "fileTitle";
newDiv.id = fileName;
newDiv.innerText = fileName;
titleHeader.appendChild(newDiv)
}
highlightDocument = (documentId) => {
let selectedDocument = document.getElementById(documentId);
if (temp !== undefined)
temp.style.backgroundColor = "rgb(60, 60, 60)";
temp = selectedDocument;
selectedDocument.style.backgroundColor = "rgba(77, 155, 191, 75)";
}
newDoc = () => {
const newNoteNameWindow = document.getElementById("newNoteNameWindow");
newNoteNameWindow.style.display = "block";
newNoteNameWindow.focus();
newNoteNameWindow.onkeydown = (k) => {
if (k.keyCode == 13) {
newNoteNameWindow.style.display = "none";
constructFileTitleElement(newNoteNameWindow.textContent);
currentDocumentId = newNoteNameWindow.textContent;
documentContent.focus();
highlightDocument(currentDocumentId);
newNoteNameWindow.textContent = "";
documentContent.textContent = "";
}
}
}