|
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 () { |
|
37 | 28 | document.getElementById("time").innerHTML = h + ":" + m; |
38 | 29 | setTimeout(function () { |
39 | 30 | startTime(); |
40 | | - }, 500); |
| 31 | + }, 1000); |
41 | 32 | } |
42 | | - |
43 | 33 | startTime(); |
44 | 34 | })(); |
45 | 35 |
|
@@ -71,14 +61,27 @@ function insertDom() { |
71 | 61 | } |
72 | 62 |
|
73 | 63 | 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 | + } |
82 | 85 | }); |
83 | 86 | } |
84 | 87 |
|
|
0 commit comments