-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent.js
112 lines (98 loc) · 3.79 KB
/
content.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var dob = 0;
document.addEventListener('DOMContentLoaded', function() {
var dobtoshow = document.getElementById("dob");
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if(request ==undefined || request == null || request.dateofbirth ==null || request.dateofbirth == undefined )
{
$('#dob').empty().hide();
$('.whole>#dobset').html('<p id="mes">You have not configured your date of birth yet. <a href="about.html" id="about">Learn More</a></p>');
}
else
{
dob = request.dateofbirth;
dateof = dob;
getHours(dob);
}
return true;
});
}
});
background();
quote();
});
function background() {
var imagecat = ['nature', 'ocean', 'travel','clouds', 'sky', 'mono', 'flores','water','flower','green','light','landscape','trees', 'yellow','moon'];
var random = imagecat[Math.floor(Math.random()*imagecat.length)];
// call the flicker api with the call back function.
$.getJSON("https://api.flickr.com/services/rest/?method=flickr.photos.search&format=json&extras=url_l&jsoncallback=?", {
api_key:'0677de6a559772c8cb27dd22219dfa0c',
tags:random,
accuracy:1
}).done(function(data) {
if (data.photos.pages > 0) {
var photo = data.photos.photo[0];
document.querySelector("body").style.backgroundImage = "url('" + photo.url_l + "')";
document.querySelector("#image-source").setAttribute("href", "http://www.flickr.com/photos/" + photo.owner + "/" + photo.id);
document.querySelector("#image-source").setAttribute("target","_blank");
} else {
document.querySelector("body").style.backgroundImage = "url('https://fourtonfish.com/tutorials/weather-web-app/images/default.jpg')";
document.querySelector("#image-source").setAttribute("href", "https://www.flickr.com/photos/superfamous/310185523/sizes/o/");
}
})/*.error(function(data) {
console.error(data);
});*/
}
function quote(){
$.ajax({
url: 'https://andruxnet-random-famous-quotes.p.mashape.com/',
type: 'post',
data: {
},
headers: {
'X-Mashape-Key': '1Xuhcdh7NsmshWXJ9mNNa3ChMDpvp1fIoBNjsnLnPJiwUxrMGO'
},
dataType: 'json',
success: function(data) {
//$('body').fadeIn(50);
$('.real-quote>span>p').text('"' + data.quote + '"');
$('.author>span>p').text("Author: "+data.author);
//$('.author>small').text("Category: " + data.category);
$('#tweet').attr("href","https://twitter.com/intent/tweet?ref_src=twsrc%5Etfw&text="+ '"' + data.quote + '"' + " - " + data.author+"&tw_p=tweetbutton&via=lifehourchrome" );
}
});
}
function getHours(date)
{
date = date+':00';
var datebirthed = moment(date, 'YYYY/MM/DD HH:mm:ss').format("YYYY/MM/DD HH:mm:ss");
var dateNow = new Date();
dateNow = moment(dateNow,'YYYY/MM/DD HH:mm:ss');
datebirthed = moment(datebirthed,'YYYY/MM/DD HH:mm:ss');
//var seconds = Math.floor((dateNow - (datebirthed))/1000);
var diff_ms = moment(dateNow).diff(datebirthed);
var dur_obj = moment.duration(diff_ms);
window.hour = parseInt(dur_obj.asHours());
$('#dob').empty().show();
$('#dobset').empty();
setInterval(update, 1000);
//$('#dob').append(hour +' Hours ' + minutes+' Minutes '+seconds+' Seconds');
}
function update() {
if(moment().minutes() == 59 && moment().seconds()==59){
if(window.hour==0)
{
window.hour = 1;
}
window.hour +=1;
}
$('#dob').html(window.hour+' '+moment().format(':mm:ss'));
}
$(document).ready(function(){
$('#btn').click(function(e) {
e.preventDefault();
quote();
});
});