Skip to content

Commit 899ff30

Browse files
Develop to main
New release
2 parents b6c8366 + 5eff644 commit 899ff30

2 files changed

Lines changed: 27 additions & 26 deletions

File tree

.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

index.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,13 @@
66
fetchImage();
77

88
function fetchImage() {
9-
fetch("https://source.unsplash.com/random/3840x2160/?nature")
10-
.then((resp) => resp)
9+
fetch("https://source.unsplash.com/3840x2160/?nature")
10+
.then((resp) => {
11+
return resp.url;
12+
})
1113
.then((imagelists) => {
12-
let selectedImage = imagelists.url;
13-
let dom = document.getElementById("bgimg");
14-
dom.style.backgroundColor = "grey";
15-
dom.style.backgroundImage = `url(${selectedImage})`;
14+
dom.style.backgroundImage = `url(${imagelists})`;
1615
})
17-
.catch(() => {
18-
error();
19-
});
20-
}
21-
22-
function error() {
23-
let dom = document.getElementById("bgimg");
24-
dom.style.backgroundColor = "grey";
2516
}
2617
})();
2718
(function () {
@@ -37,9 +28,8 @@
3728
document.getElementById("time").innerHTML = h + ":" + m;
3829
setTimeout(function () {
3930
startTime();
40-
}, 500);
31+
}, 1000);
4132
}
42-
4333
startTime();
4434
})();
4535

@@ -71,14 +61,27 @@ function insertDom() {
7161
}
7262

7363
function getQuote() {
74-
$.getJSON('https://api.quotable.io/random', function (data) {
75-
let template =
76-
'<span style="font-size: 2vh;padding: 8px;;text-shadow: 2px 2px 4px #000000;"><strong style="font-style: italic;font-size: 2vh;text-shadow: 0 0 2px gray;">"QUOTE"</strong><a target="_blank" rel="noopenner" style="color:white;text-decoration: none;">- AUTHOR</a><span></span></span>';
77-
const quote = `${data.content}`;
78-
const author = `${data.author}`;
79-
template = template.replace("QUOTE", quote);
80-
template = template.replace("AUTHOR", author);
81-
$("#quote").html(template);
64+
$.ajax({
65+
url: "https://api.quotable.io/random",
66+
dataType: "json",
67+
success: function (data) {
68+
let template =
69+
'<span style="font-size: 2vh;padding: 8px;;text-shadow: 2px 2px 4px #000000;"><strong style="font-style: italic;font-size: 2vh;text-shadow: 0 0 2px gray;">"QUOTE"</strong><a target="_blank" rel="noopenner" style="color:white;text-decoration: none;">- AUTHOR</a><span></span></span>';
70+
const quote = `${data.content}`;
71+
const author = `${data.author}`;
72+
template = template.replace("QUOTE", quote);
73+
template = template.replace("AUTHOR", author);
74+
$("#quote").html(template);
75+
},
76+
error: function (data) {
77+
let template =
78+
'<span style="font-size: 2vh;padding: 8px;;text-shadow: 2px 2px 4px #000000;"><strong style="font-style: italic;font-size: 2vh;text-shadow: 0 0 2px gray;">"QUOTE"</strong><a target="_blank" rel="noopenner" style="color:white;text-decoration: none;">- AUTHOR</a><span></span></span>';
79+
const quote = `Error while fetching quote`;
80+
const author = `OpenSourceSimon`;
81+
template = template.replace("QUOTE", quote);
82+
template = template.replace("AUTHOR", author);
83+
$("#quote").html(template);
84+
}
8285
});
8386
}
8487

0 commit comments

Comments
 (0)