-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
72 lines (67 loc) · 2.16 KB
/
Copy pathscript.js
File metadata and controls
72 lines (67 loc) · 2.16 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
64
65
66
67
68
69
70
71
72
$(document).ready(function () {
setCurrentTime();
setInterval(function(){
setCurrentTime();
},10*1000);
var username = getCookie('username');
//rudimentary javascript to check cookie
if(username){
$('.greeting').css('display','inline-block');
$('.user-name').css('display','none');
$('.greeting').html(`Hello <span class="stored-name">${username}</span>.`);
}else{
$('.greeting').css('display','none');
$('.user-name').css('display','inline-block');
$('.greeting').html(`What's your name?`);
}
$('.user-name').keypress(function(e) {
if(e.which == 13) {
var username = e.target.value;
if(!username) return;
$('.user-name').fadeOut(function(){
$('.greeting').html(`Hello ${username}.`);
$('.greeting').fadeIn(function(){
setCookie('username', username,365);
});
});
}
});
});
function setCurrentTime(){
var now = new Date();
$('.time').html(now.getHours()+":"+now.getMinutes())
$('.date').html(now.toLocaleDateString('en-US', { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric' }));
}
function setCookie(cname,cvalue,exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function newimage(keyword){
if(!ACCESS_KEY){
alert("Please update your access key");
return;
}
var url = `https://api.unsplash.com/search/photos?query=${keyword}&per_page=20&orientation=landscape&client_id=${ACCESS_KEY}`;
$.get(url,function(data){
var picture_url = data.results[0].urls.raw;
setCookie("picture",picture_url);
$('body').css('background-image',`url(${picture_url})`);
});
}