-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewtab.js
239 lines (211 loc) · 7.18 KB
/
newtab.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// function Todo(id,task){
// this.id = id;
// this.task = task;
// this.checked = false;
// }
// var todos =new Array();
// window.onload = init;
// function init(){
// getTodoItems();
// }
////////////////////////////////////////////////////////////
// Create a "close" button and append it to each list item
var myNodelist = document.getElementsByTagName("LI");
var i;
for (i = 0; i < myNodelist.length; i++) {
var span = document.createElement("SPAN");
var txt = document.createTextNode("\u00D7");
span.className = "close";
span.appendChild(txt);
myNodelist[i].appendChild(span);
}
// Click on a close button to hide the current list item
var close = document.getElementsByClassName("close");
var i;
for (i = 0; i < close.length; i++) {
close[i].onclick = function() {
var div = this.parentElement;
div.style.display = "none";
}
}
// Add a "checked" symbol when clicking on a list item
var list = document.querySelector('ul');
list.addEventListener('click', function(ev) {
if (ev.target.tagName === 'LI') {
ev.target.classList.toggle('checked');
}
}, false);
// Create a new list item when clicking on the "Add" button
function newElement() {
var li = document.createElement("li");
var inputValue = document.getElementById("myInput").value;
var t = document.createTextNode(inputValue);
li.appendChild(t);
if (inputValue === '') {
alert("You must write something!");
} else {
document.getElementById("myUL").appendChild(li);
}
////////////////////////////////////////////
// var id = todos.length;
// var todoItem = new Todo(id,inputValue);
// todos.push(todoItem);
// if (localStorage){
// var key = "todo" + id;
// var item = JSON.stringify(todoItem);
// localStorage.setItem(key,item);
// } else {
// console.log("Error: you don't have localStorage!");
// }
////////////////////////////////////////////
document.getElementById("myInput").value = "";
var span = document.createElement("SPAN");
var txt = document.createTextNode("\u00D7");
span.className = "close";
span.appendChild(txt);
li.appendChild(span);
//hide the element when clicked
for (i = 0; i < close.length; i++) {
close[i].onclick = function() {
var div = this.parentElement;
div.style.display = "none";
}
}
}
//////////////////////////////////////////////////////////////////
// function getTodoItems(){
// if (localStorage) {
// for (var i = 0; i < localStorage.length; i ++) {
// var key = localStorage.key(i);
// if (key.substring(0,4)=="todo") {
// var item = localStorage.getItem(key);
// var todoItem = JSON.parse(item);
// todos.push(todoItem);
// }
// }
// addTodosToPage();
// }
// else {
// console.log("Error: you don't have localStorage!")
// }
// }
// function addTodosToPage() {
// for (var i = 0; i < todos.length; i++) {
// var todoItem = todos[i];
// var li = document.createElement("li");
// var t = document.createTextNode(todoItem);
// li.appendChild(t);
// document.getElementById("myUL").appendChild(li);
// var span = document.createElement("SPAN");
// var txt = document.createTextNode("\u00D7");
// span.className = "close";
// span.appendChild(txt);
// li.appendChild(span);
// }
// }
// tttttttttttttttt this is the division for weather forecast tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
var queryURL = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20%3D%2023396898&format=json&env=store/";
$.getJSON(queryURL, function (data) {
function FtoC(temp) {
return Math.round((temp - 32) / (9 / 5));
}
var results = data.query.results.channel;
var city = results.location.city;
var region = results.location.region;
var time = results.item.condition.date;
var temp = FtoC(results.item.condition.temp);
var text = results.item.condition.text;
var i = 0;
var item = results.item.forecast[0];
var prevbtn = document.querySelector("#prev");
var nextbtn = document.querySelector("#next");
prevbtn.addEventListener("click",function(){
if(i != 0){
i -= 1;
var item = results.item.forecast[i];
$('#date').html(item.day + ". " + item.date);
$('#low').html(FtoC(item.low));
$('#high').html(FtoC(item.high));
$('#text').html(item.text);
}
})
nextbtn.addEventListener("click",function(){
if(i != 9){
i += 1;
var item = results.item.forecast[i];
$('#date').html(item.day + ". " + item.date);
$('#low').html(FtoC(item.low));
$('#high').html(FtoC(item.high));
$('#text').html(item.text);
}
})
// var weather = document.getElementById("weather");
$('#location').append(city + ". " + region);
$('#time').append(time);
$('#date').html(item.day + ". " + item.date);
$('#low').html(FtoC(item.low));
$('#high').html(FtoC(item.high));
$('#text').html(item.text);
})
// eeeeeeeeeeeee this is the division line for time eeeeeeeeeeeeeeeeeeeeeee
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
// add a zero in front of numbers<10
m = checkTime(m);
s = checkTime(s);
$('#curtime').html(h + ":" + m + ":" + s);
t = setTimeout(function() {
startTime()
}, 500);
}
startTime();
// rrrrrrrrrrrr this is the division line for changing header rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
// randomly select quotes from the array according to different time zone user is in
// and every refresh of the page triggers the function to run and a random quote will be selected
var titlequotes=[
'Good Morning Emily!',
'You will never have this day again',
'Check the weather and don\'t catch cold!',
'Check Piazza Often!',
'Good Afternoon Emily!',
'Smile! :)',
'Good Evening Emily!',
'Never regret a day in your life',
'Sweet Dream ~',
'Don\'t stay up too late!'
]
var subquotes=[
'Start your day listing Todo\'s',
'so make it count',
'To see the world, things dangerous to come to, to see behind walls, to draw closer, to find each other and to feel.',
'Be clear of where you really want to head for.',
'Why are you trying so hard to fit in when you were born to stand out?',
'To find something, anything, a great truth or a lost pair of glasses, you must first believe there will be some advantage in finding it.',
'In the end it\'s all nice',
'Let it be',
'Good job today',
'Think about tomorrow\'s menu !'
]
var j;
function changeQuote(){
var today = new Date();
var h = today.getHours();
if ((h > 4)&&(h < 12)) {
j = 0;
} else if ((h >=12)&& (h < 18)) {
j = 3;
} else j = 6;
var randNum = Math.floor(Math.random()*3+j); //generate integers from 0 to 2 ??? can we hit 3???
$('#header').text(titlequotes[randNum]);
$('#subheader').text(subquotes[randNum]);
}
changeQuote();