mirror of
https://github.com/MailHops/mailhops-plugin.git
synced 2025-05-29 20:10:10 -07:00
Fixed distance display, now calculates distance from last hop on the client
This commit is contained in:
parent
4a4079eca8
commit
981a02bcfe
@ -8,7 +8,7 @@ var mailHops =
|
|||||||
{
|
{
|
||||||
msgURI: null
|
msgURI: null
|
||||||
, isLoaded: false
|
, isLoaded: false
|
||||||
, options: {'version':'MailHops Plugin 1.0.4','lan':'en','unit':'mi','api_url':'http://api.mailhops.com','debug':false}
|
, options: {'version':'MailHops Plugin 1.0.5','lan':'en','unit':'mi','api_url':'http://api.mailhops.com','debug':false}
|
||||||
, message: { secure:[] }
|
, message: { secure:[] }
|
||||||
, client_location: null
|
, client_location: null
|
||||||
};
|
};
|
||||||
@ -363,6 +363,9 @@ mailHops.lookupRoute = function(header_route){
|
|||||||
if(mailHops.options.fkey != '')
|
if(mailHops.options.fkey != '')
|
||||||
lookupURL += '&fkey='+mailHops.options.fkey;
|
lookupURL += '&fkey='+mailHops.options.fkey;
|
||||||
|
|
||||||
|
if(mailHops.options.client_location != '')
|
||||||
|
lookupURL+='&c=0';
|
||||||
|
|
||||||
mailHops.LOG(lookupURL);
|
mailHops.LOG(lookupURL);
|
||||||
|
|
||||||
//check for cache
|
//check for cache
|
||||||
|
@ -302,7 +302,14 @@ var mailHopsDisplay =
|
|||||||
|
|
||||||
if(this.options.client_location){
|
if(this.options.client_location){
|
||||||
var client_location = JSON.parse(this.options.client_location);
|
var client_location = JSON.parse(this.options.client_location);
|
||||||
if(response.route[response.route.length-1].ip != client_location.route[0].ip)
|
//get distance from last route to client_location and add to response.distance.miles or kilometers
|
||||||
|
if(!response.route[response.route.length-1]['private']){
|
||||||
|
if(this.options.unit=='km')
|
||||||
|
response.distance.kilometers += mailHopsUtils.getDistance(response.route[response.route.length-1],client_location.route[0],this.options.unit);
|
||||||
|
else
|
||||||
|
response.distance.miles += mailHopsUtils.getDistance(response.route[response.route.length-1],client_location.route[0],this.options.unit);
|
||||||
|
}
|
||||||
|
//push client location to the end of the route
|
||||||
response.route.push(client_location.route[0]);
|
response.route.push(client_location.route[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,11 +430,11 @@ var mailHopsDisplay =
|
|||||||
displayText = first.countryName;
|
displayText = first.countryName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(response.distance && response.distance.miles > 0){
|
if(response.distance){
|
||||||
if(this.options.unit=='mi')
|
if(this.options.unit=='km' && response.distance.kilometers > 0)
|
||||||
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )';
|
|
||||||
else
|
|
||||||
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )';
|
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )';
|
||||||
|
else if(response.distance.miles > 0)
|
||||||
|
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )';
|
||||||
}
|
}
|
||||||
else if(displayText=='')
|
else if(displayText=='')
|
||||||
displayText = ' Local message.';
|
displayText = ' Local message.';
|
||||||
|
@ -185,7 +185,14 @@ var mailHopsDisplay =
|
|||||||
|
|
||||||
if(this.options.client_location){
|
if(this.options.client_location){
|
||||||
var client_location = JSON.parse(this.options.client_location);
|
var client_location = JSON.parse(this.options.client_location);
|
||||||
if(response.route[response.route.length-1].ip != client_location.route[0].ip)
|
//get distance from last route to client_location and add to response.distance.miles or kilometers
|
||||||
|
if(!response.route[response.route.length-1]['private']){
|
||||||
|
if(this.options.unit=='km')
|
||||||
|
response.distance.kilometers += mailHopsUtils.getDistance(response.route[response.route.length-1],client_location.route[0],this.options.unit);
|
||||||
|
else
|
||||||
|
response.distance.miles += mailHopsUtils.getDistance(response.route[response.route.length-1],client_location.route[0],this.options.unit);
|
||||||
|
}
|
||||||
|
//push client location to the end of the route
|
||||||
response.route.push(client_location.route[0]);
|
response.route.push(client_location.route[0]);
|
||||||
}
|
}
|
||||||
for(var i=0; i<response.route.length;i++){
|
for(var i=0; i<response.route.length;i++){
|
||||||
@ -284,11 +291,11 @@ var mailHopsDisplay =
|
|||||||
displayText = first.countryName;
|
displayText = first.countryName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(response.distance && response.distance.miles > 0){
|
if(response.distance){
|
||||||
if(this.options.unit=='mi')
|
if(this.options.unit=='km' && response.distance.kilometers > 0)
|
||||||
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )';
|
|
||||||
else
|
|
||||||
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )';
|
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.kilometers))+' km traveled )';
|
||||||
|
else if(response.distance.miles > 0)
|
||||||
|
distanceText =' ( '+mailHopsUtils.addCommas(Math.round(response.distance.miles))+' mi traveled )';
|
||||||
} else if(displayText=='')
|
} else if(displayText=='')
|
||||||
displayText = ' Local message.';
|
displayText = ' Local message.';
|
||||||
}
|
}
|
||||||
|
@ -177,6 +177,30 @@ getWeatherIcon: function(icon){
|
|||||||
var hr = (new Date).getHours();
|
var hr = (new Date).getHours();
|
||||||
var time = (hr >= 4 && hr <= 18)?'day':'night';
|
var time = (hr >= 4 && hr <= 18)?'day':'night';
|
||||||
return 'chrome://mailhops/content/images/weather/'+forecast_icons[icon][time]+'.png';
|
return 'chrome://mailhops/content/images/weather/'+forecast_icons[icon][time]+'.png';
|
||||||
}
|
},
|
||||||
|
|
||||||
|
getDistance: function(from, to, unit) {
|
||||||
|
if(!from || !to || !from['lat'] || !to['lat'])
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
lat = parseFloat(from['lat']);
|
||||||
|
lon1 = parseFloat(from['lng']);
|
||||||
|
lat2 = parseFloat(to['lat']);
|
||||||
|
lon2 = parseFloat(to['lng']);
|
||||||
|
unit = unit || 'mi';//mi or km
|
||||||
|
|
||||||
|
lat *= (Math.PI/180);
|
||||||
|
lon1 *= (Math.PI/180);
|
||||||
|
lat2 *= (Math.PI/180);
|
||||||
|
lon2 *= (Math.PI/180);
|
||||||
|
|
||||||
|
dist = 2*Math.asin(Math.sqrt( Math.pow((Math.sin((lat-lat2)/2)),2) + Math.cos(lat)*Math.cos(lat2)*Math.pow((Math.sin((lon1-lon2)/2)),2))) * 6378.137;
|
||||||
|
|
||||||
|
if (unit == 'mi') {
|
||||||
|
dist = (dist / 1.609344);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dist;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
@ -5,7 +5,7 @@
|
|||||||
<Description about="urn:mozilla:install-manifest">
|
<Description about="urn:mozilla:install-manifest">
|
||||||
<em:type>2</em:type>
|
<em:type>2</em:type>
|
||||||
<em:id>thunderbird@mailhops.com</em:id>
|
<em:id>thunderbird@mailhops.com</em:id>
|
||||||
<em:version>1.0.4</em:version>
|
<em:version>1.0.5</em:version>
|
||||||
|
|
||||||
<em:name>MailHops</em:name>
|
<em:name>MailHops</em:name>
|
||||||
<em:description>MailHops maps the route an email traveled to get to you. Using GeoIP it also displays distance traveled along with the location (city, state and country) of the sender.</em:description>
|
<em:description>MailHops maps the route an email traveled to get to you. Using GeoIP it also displays distance traveled along with the location (city, state and country) of the sender.</em:description>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user