-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
79 lines (67 loc) · 2.2 KB
/
script.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
69
70
71
72
73
74
75
76
77
78
79
// Notes functionality JS (with guidance from https://eqdn.tech/html5-note-app-tutorial/)
window.onload = function() {
display_saved_note();
}
function check_web_storage_support() {
if(typeof(Storage) !== "undefined") {
return(true);
}
else {
alert("Web storage unsupported!");
return(false);
}
}
function display_saved_note() {
if(check_web_storage_support() == true) {
result = localStorage.getItem('note');
}
if(result === null) {
result = "";
}
document.getElementById('area').value = result;
}
function save() {
if(check_web_storage_support() == true) {
var area = document.getElementById("area");
if(area.value != '') {
localStorage.setItem("note", area.value);
}
else {
alert("Nothing to save");
}
}
}
window.addEventListener('load', function load(event){
var createButton = document.getElementById('save');
createButton.addEventListener('click', function() { save(); });
});
// -------------------------------------------------------
// Date & Time JS
function updateClock() {
var date = new Date();
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var year = date.getFullYear();
var month = months[date.getMonth()];
var day_num = date.getDate();
var day_text = days[date.getDay()];
if (day_num == 1 || day_num == 21) {
var suffix = "st";
} else if (day_num == 2 || day_num == 22) {
var suffix = "nd";
} else if (day_num == 3 || day_num == 23) {
var suffix = "rd";
} else {
var suffix = "th";
}
document.getElementById("date").innerHTML = day_text + ", " + month + " " + day_num + suffix + ", " + year;
var hour_24hrs = date.getHours();
var hour = (hour_24hrs % 12);
if (hour == 0) { hour = 12; }
var amORpm = (hour_24hrs / 12 < 1 ? "AM" : "PM");
var minute = date.getMinutes();
if (minute < 10) { minute = "0" + minute; };
document.getElementById("time").innerHTML = "<b>"+hour + ":" + minute + " " + amORpm+"</b>";
setTimeout(updateClock, 1000);
}
updateClock();