-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.js
More file actions
63 lines (52 loc) · 1.52 KB
/
Copy pathform.js
File metadata and controls
63 lines (52 loc) · 1.52 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
// Adds new data to local storage
var submit = document.getElementById("submitter");
submit.addEventListener("click", function () {
var text = document.getElementById("text");
textStore(valueCreator(), text.value);
logger(valueCreator(), text.value);
text.value = "";
});
//creates/updates a "log" list of all the posts made
function logger(value, pair) {
var logs = localStorage.getItem("log");
if (logs === null) {
var _a = JSON.stringify([value]);
localStorage.setItem("log", _a);
console.log(_a);
} else {
var _a2 = JSON.parse(logs);
_a2.push(value);
localStorage.setItem("log", JSON.stringify(_a2));
console.log(_a2);
}
}
function textStore(value, written) {
if (written == "") {
window.alert("If you want to submit text, then\nyou've got to write some first!");
throw new Error("write the text");
} else {
var t = new a();
var entry = [t, written];
console.log(JSON.stringify(entry));
localStorage.setItem(value, JSON.stringify(entry));
}
}
// gets the time the post was made
function a() {
var d = new Date();
return d;
}
//creates the names of the posts
function valueCreator() {
var currentdex = logIndex() + 1;
var name = "logEntry" + currentdex;
return name;
}
// returns the number of posts
function logIndex() {
if (localStorage.getItem("log") === null) {
return 0;
} else {
return JSON.parse(localStorage.getItem("log")).length;
}
}