-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (56 loc) · 1.55 KB
/
script.js
File metadata and controls
60 lines (56 loc) · 1.55 KB
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
$(document).ready(function() {
var colors = [
"#880E4F",
"#F57F17",
"#0D47A1",
"#3E2723",
"#b71c1c",
"#4A148C",
"#311B92",
"#004D40",
"#212121",
"#D500F9",
"#F57C00",
"#76FF03",
"#263238"
];
var gQuote = {};
var i = 0;
function tweetCurrentPage() {
window.open(
'https://twitter.com/intent/tweet?text="' +
encodeURIComponent(gQuote.quoteText.trim() + '" ' + gQuote.quoteAuthor)
);
return false;
}
function getQuote() {
i = Math.floor(Math.random() * (colors.length));
console.log(i);
$.getJSON(
"https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&jsonp=?",
function(quote) {
gQuote = quote;
document.getElementsByClassName("quote")[0].style.color = colors[i];
document.getElementsByClassName("author")[0].style.color = colors[i];
document
.getElementById("refresh")
.setAttribute("style", "color: " + colors[i] + ";");
document
.getElementsByClassName("twitter-share")[0]
.setAttribute("style", "color: " + colors[i] + ";");
$(".quote").html('"' + quote.quoteText + '"');
$(".author").html("- " + (quote.quoteAuthor || 'Unknown'));
document.getElementsByTagName("body")[0].style.backgroundColor = colors[i];
$('.quote, .author, .twitter-share, #refresh, #body').addClass('animated fadeIn');
}
);
}
getQuote();
$("#refresh").on("click", function() {
getQuote();
$('.quote, .author, .twitter-share, #refresh, #body').removeClass('animated fadeIn');
});
$(".twitter-share").on("click", function() {
tweetCurrentPage();
});
});