Skip to content

Commit adcb50b

Browse files
Update
1 parent 303972c commit adcb50b

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Quote.php is in the quote branch because it's on a server
2-
quote.php
2+
image.php

index.js

Lines changed: 18 additions & 14 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 () {
@@ -80,6 +71,19 @@ function getQuote() {
8071
template = template.replace("AUTHOR", author);
8172
$("#quote").html(template);
8273
});
74+
// On error, show an error quote and author.
75+
$.ajax({
76+
url: "https://api.quotable.io/random",
77+
error: function (data) {
78+
let template =
79+
'<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>';
80+
const quote = `Error while fetching quote`;
81+
const author = `OpenSourceSimon`;
82+
template = template.replace("QUOTE", quote);
83+
template = template.replace("AUTHOR", author);
84+
$("#quote").html(template);
85+
}
86+
});
8387
}
8488

8589
function getdateDetails() {

0 commit comments

Comments
 (0)