-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
63 lines (59 loc) · 1.3 KB
/
script.js
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
function setRandomColor() {
const colors = [
"#1abc9c",
"#2ecc71",
"#3498db",
"#9b59b6",
"#34495e",
"#16a085",
"#27ae60",
"#2980b9",
"#8e44ad",
"#2c3e50",
"#f1c40f",
"#e67e22",
"#e74c3c",
"#ecf0f1",
"#95a5a6",
"#f39c12",
"#d35400",
"#c0392b",
"#bdc3c7",
"#7f8c8d",
];
let index = Math.floor(Math.random() * colors.length);
$("body").css("background-color", colors[index]);
}
function getRandomQuote() {
const settings = {
async: true,
crossDomain: true,
url: "https://quotes15.p.rapidapi.com/quotes/random/",
method: "GET",
headers: {
"X-RapidAPI-Host": "quotes15.p.rapidapi.com",
"X-RapidAPI-Key": config.API_KEY,
},
};
let quote = "";
let author = "";
$.ajax(settings).done(function (response) {
// console.log(response);
quote = response.content;
author = response.originator.name;
//console.log(author)
$("#text").html("");
$("#text").html(quote);
$("#author").html("");
$("#author").html("- " + author);
$("#tweet-quote").attr(
"href",
"https://twitter.com/intent/tweet?text=" + `"${quote}" -${author}`
);
setRandomColor();
});
}
$(document).ready(function () {
getRandomQuote();
$("#new-quote").click(() => getRandomQuote());
});