-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
62 lines (44 loc) · 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
jQuery(document).ready(function(){
// adding and styling current date and time
$('#currentDay').text(moment().format('[Today is ] LL')).css({fontSize: "25px"});
$('#currentTime').text(moment().format('LT')).css({fontSize: "25px"});
let realTime = moment().format('HH:mm'); // current time
let startHour = moment().startOf('hour').format("HH:mm") // start of current hour
let endTime = moment("23:59", "HH:mm").format('HH:mm')
// clearing local storage at the end of the day
if(realTime === endTime){
localStorage.clear()
}
// setting classes for textarea based on real time
$('.hour').each(function(){
let convertingTime = $(this).text() //setting values to variable
let convertedTime = moment(convertingTime, 'HA').format('HH:mm') // coverting time to military
// adding class depending on past, present, future
if (convertedTime < startHour) {
$(this).siblings('textarea').addClass('past')
} else if (convertedTime === startHour){
$(this).siblings('textarea').addClass('present')
} else if (convertedTime > realTime){
$(this).siblings('textarea').addClass('future')
}
})
//setting input from textarea and saving it to local storage
$('.saveBtn').on('click', setLocalStorage);
function setLocalStorage(){
$('textarea').each(function () {
var id = $(this).attr('id');
var value = $(this).val();
localStorage.setItem(id, value);
});
}
// getting input from local storage
$('#hourNine').text(window.localStorage.getItem('hourNine'));
$('#hourTen').text(window.localStorage.getItem('hourTen'));
$('#hourEleven').text(window.localStorage.getItem('hourEleven'))
$('#hourTwelve').text(window.localStorage.getItem('hourTwelve'))
$('#hourOne').text(window.localStorage.getItem('hourOne'))
$('#hourTwo').text(window.localStorage.getItem('hourTwo'))
$('#hourThree').text(window.localStorage.getItem('hourThree'))
$('#hourFour').text(window.localStorage.getItem('hourFour'))
$('#hourFive').text(window.localStorage.getItem('hourFive'))
})