166 lines
3.9 KiB
JavaScript
166 lines
3.9 KiB
JavaScript
(function() {
|
|
let lastGBP = 0.0,
|
|
lastUSD = 0.0,
|
|
_fasttimer, _slowTimer, myBTC = 3.49524333;
|
|
let lows = {
|
|
gbp: 0,
|
|
usd: 0
|
|
},
|
|
highs = {
|
|
gbp: 0,
|
|
usd: 0
|
|
};
|
|
|
|
let list = [{
|
|
title: '101B ends',
|
|
y: 2013,
|
|
m: 9,
|
|
d: 24,
|
|
add: 1001
|
|
},
|
|
{
|
|
title: 'Ends',
|
|
y: 2016,
|
|
m: 4,
|
|
d: 4
|
|
}];
|
|
|
|
let self = this;
|
|
|
|
let addDays = function(myDate, days) {
|
|
return new Date(myDate.getTime() + days * 24 * 60 * 60 * 1000);
|
|
};
|
|
|
|
let getDays = function(startdate, enddate) {
|
|
let r, s, e;
|
|
s = startdate.getTime();
|
|
e = enddate.getTime();
|
|
r = (e - s) / (24 * 60 * 60 * 1000);
|
|
return r;
|
|
};
|
|
|
|
let tick = function() {
|
|
let today = new Date();
|
|
let start101 = new Date();
|
|
let end101;
|
|
let endContract = new Date();
|
|
let third = new Date();
|
|
start101.setFullYear(2013, 9, 24);
|
|
end101 = addDays(start101, 1001);
|
|
endContract.setFullYear(2017, 6, 5);
|
|
third.setFullYear(2013, 7, 25);
|
|
/*$('#one').text('101B ends: ' + Math.ceil(getDays(today,
|
|
end101)) + ' days / ' + Math.ceil(getDays(today,
|
|
end101) / 7) + ' weeks');*/
|
|
$('#one').hide();
|
|
$('#two').text('Ends: ' + Math.ceil(getDays(today,
|
|
endContract)) + ' days / ' + Math.ceil(getDays(today,
|
|
endContract) / 7) + ' weeks');
|
|
$('#three').hide();
|
|
};
|
|
|
|
let get_weather = function() {
|
|
navigator.geolocation.getCurrentPosition(show_weather);
|
|
};
|
|
|
|
this.bind('displayWeather', function(data) {
|
|
$('#weather').html(data.currently.summary + ' ' + data.currently.temperature + '°c <em>' + data.daily.summary + '</em>');
|
|
});
|
|
|
|
var show_weather = function(position) {
|
|
let latitude = position.coords.latitude;
|
|
let longitude = position.coords.longitude;
|
|
// let's show a map or do something interesting!
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: 'https://api.forecast.io/forecast/9ad2a41d420f3cf4960571bb886f710c/' + latitude.toString() + ',' + longitude.toString() + '?units=uk2',
|
|
data: '',
|
|
dataType: 'jsonp',
|
|
timeout: 10000,
|
|
context: $('body'),
|
|
contentType: ('application/json'),
|
|
headers: {
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
|
'Access-Control-Allow-Headers': 'Content-Type'
|
|
},
|
|
success: function(data) {
|
|
self.trigger('displayWeather', data);
|
|
},
|
|
error: function(xhr, type) {
|
|
console.log('ajax error');
|
|
console.log(xhr);
|
|
console.log(type);
|
|
}
|
|
});
|
|
};
|
|
|
|
|
|
let formatPassword = function(data) {
|
|
let dest$ = $('#passwordOut');
|
|
let html = new EJS({url: '/template/password.ejs'}).render(data);
|
|
dest$.empty();
|
|
dest$.append(html);
|
|
dest$.show();
|
|
};
|
|
|
|
let generatePassword = function(from, to) {
|
|
let url = '/generate';
|
|
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: url,
|
|
data: '',
|
|
dataType: 'json',
|
|
|
|
timeout: 10000,
|
|
|
|
headers: {
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
|
'Access-Control-Allow-Headers': 'Content-Type'
|
|
|
|
},
|
|
success: function(data) {
|
|
formatPassword(data);
|
|
},
|
|
error: function(xhr, type) {
|
|
console.log('ajax error');
|
|
console.log(xhr);
|
|
console.log(type);
|
|
}
|
|
});
|
|
};
|
|
|
|
tick();
|
|
get_weather();
|
|
|
|
_slowTimer = setInterval(function() {
|
|
|
|
get_weather();
|
|
}, (60000 * 15));
|
|
|
|
|
|
$('#newPassword').on('click', function() {
|
|
generatePassword();
|
|
});
|
|
|
|
document.title = 'Slack';
|
|
})();
|
|
|
|
let popitout = function(url) {
|
|
let newwindow = window.open(url, 'name', 'height=600,width=570');
|
|
if (window.focus) {
|
|
newwindow.focus();
|
|
}
|
|
return false;
|
|
};
|
|
|
|
let popitoutSmall = function(url) {
|
|
let newwindow = window.open(url, 'name', 'height=400,width=520');
|
|
if (window.focus) {
|
|
newwindow.focus();
|
|
}
|
|
return false;
|
|
};
|