This repository has been archived by the owner on Mar 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
anim.js
65 lines (55 loc) · 3.48 KB
/
anim.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
var main = function($) {
var the_good_stuff = {};
$.ajax({
url : "http://api.wunderground.com/api/eff03e7c66c8636b/conditions/q/autoip.json",
dataType : "jsonp",
success : function(parsed_json) {
the_good_stuff = parsed_json['current_observation'];
var location = parsed_json['current_observation']['display_location']['full'];
var temp_f = parsed_json['current_observation']['temp_f'];
var temp_c = parsed_json['current_observation']['temp_c'];
var weather = parsed_json['current_observation']['weather'];
var icon = parsed_json['current_observation']['icon_url'];
var wind_spd = parsed_json['current_observation']['wind_mph'];
var wind_dir = parsed_json['current_observation']['wind_dir'];
var time = parsed_json['current_observation']['observation_time_rfc822'];
var Regexp = /\s(\d+):/g;
var hours = Regexp.exec(time)
$("#location").html(location);
$("#temperature").html(temp_f + "°F");
$("#weather").html(weather);
$("#weatherimg").attr("src",icon);
$("#wind_spd").html(wind_spd + "mph");
$("#wind_dir").html(wind_dir);
if(6 < hours[1] && hours[1] < 18){
switch(weather){
case "Clear":document.querySelector("body").style.backgroundImage = "url('http://orig03.deviantart.net/3263/f/2009/257/b/9/sunflower_field_by_mxmbulat.jpg')";break;
case "Rain":document.querySelector("body").style.backgroundImage = "url('http://images4.alphacoders.com/831/83196.jpg')";break;
case "Snow":document.querySelector("body").style.backgroundImage = "url('http://www.pageresource.com/wallpapers/wallpaper/comments-for-cousy-house-in-snowy-mountains.jpg')";break;
case "Thunderstorms":document.querySelector("body").style.backgroundImage = "url('http://www.mrwallpaper.com/wallpapers/thunderstorm.jpg')";break;
default: return false;
};
}
else {
switch(weather){
case "Clear":document.querySelector("body").style.backgroundImage = "url('https://snapshotsbykats.files.wordpress.com/2011/11/020.jpg')";break;
case "Rain":document.querySelector("body").style.backgroundImage = "url('http://newtopwallpapers.com/wp-content/uploads/2013/04/A-Rainy-Night-Background-For-Desktop.jpg')";break;
case "Snow":document.querySelector("body").style.backgroundImage = "url('http://www.free-desktop-backgrounds.net/free-desktop-wallpapers-backgrounds/free-hd-desktop-wallpapers-backgrounds/565804859.jpg')";break;
case "Thunderstorms":document.querySelector("body").style.backgroundImage = "url('http://www.pix123.com/freespins/NewsImages/587783_Thunder-Blue-Storm-at-Night.jpg')";break;
default: return false;
};
}
}
});
$('.swap').click(function(){
var current = $("#temperature").html();
if(current.includes("F") == true){
console.log("switch to C");
$("#temperature").html(the_good_stuff.temp_c + "°C");
}
else{
$("#temperature").html(the_good_stuff.temp_f + "°F");
}
}
)};
$(document).ready(main);