|
6 | 6 | fetchImage(); |
7 | 7 |
|
8 | 8 | 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 | + }) |
11 | 13 | .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})`; |
16 | 15 | }) |
17 | | - .catch(() => { |
18 | | - error(); |
19 | | - }); |
20 | | - } |
21 | | - |
22 | | - function error() { |
23 | | - let dom = document.getElementById("bgimg"); |
24 | | - dom.style.backgroundColor = "grey"; |
25 | 16 | } |
26 | 17 | })(); |
27 | 18 | (function () { |
@@ -80,6 +71,19 @@ function getQuote() { |
80 | 71 | template = template.replace("AUTHOR", author); |
81 | 72 | $("#quote").html(template); |
82 | 73 | }); |
| 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 | + }); |
83 | 87 | } |
84 | 88 |
|
85 | 89 | function getdateDetails() { |
|
0 commit comments